Switch to a contextual bold start function.

This commit is contained in:
Tom Alexander 2022-12-11 00:36:59 -05:00
parent 88bf1b3d8b
commit 9dfca22b86
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 11 additions and 4 deletions

View File

@ -118,6 +118,13 @@ pub fn context_paragraph_end<'s, 'r>(
paragraph_end(input)
}
pub fn context_bold_start<'s, 'r>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, &'s str> {
recognize(bold_start)(input)
}
pub fn context_bold_end<'s, 'r>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, &'s str> {
recognize(bold_end)(input)
}
@ -170,14 +177,14 @@ fn recognize_bold_end(input: &str) -> Res<&str, &str> {
}
fn flat_bold<'s, 'r>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, Bold<'s>> {
let bold_start = parser_with_context!(context_bold_start)(context.clone());
let nom_context =
context.with_additional_node(ContextElement::FailMatcherNode(FailMatcherNode {
fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)),
}));
let (remaining, captured) = recognize(tuple((
bold_start,
|i| context_many_till(&nom_context, flat_text_element, context_bold_end)(i),
)))(i)?;
let (remaining, captured) = recognize(tuple((bold_start, |i| {
context_many_till(&nom_context, flat_text_element, context_bold_end)(i)
})))(i)?;
let ret = Bold { contents: captured };
Ok((remaining, ret))
}