Identified the problem as being the handling of the trailing whitespace.

This commit is contained in:
Tom Alexander 2023-04-10 09:49:24 -04:00
parent 9b3fbe6d26
commit 6813c7c991
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 11 additions and 38 deletions

View File

@ -17,6 +17,7 @@ use nom::bytes::complete::tag;
use nom::bytes::complete::tag_no_case;
use nom::bytes::complete::take_while;
use nom::character::complete::digit1;
use nom::character::complete::multispace0;
use nom::character::complete::space0;
use nom::combinator::recognize;
use nom::combinator::verify;
@ -37,12 +38,11 @@ pub fn footnote_definition<'r, 's>(
context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode {
exit_matcher: ChainBehavior::IgnoreParent(Some(&footnote_definition_end)),
}));
// TODO: The problem is we are not accounting for trailing whitespace like we do in section. Maybe it would be easier if we passed down whether or not to parse trailing whitespace into the element matcher similar to how tag takes in parameters.
let element_matcher = parser_with_context!(element)(&parser_context);
let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context);
let (remaining, (children, _exit_contents)) =
many_till(element_matcher, exit_matcher)(remaining)?;
let footnote_definition_end_matcher = parser_with_context!(footnote_definition_end)(context);
let (remaining, _end) = alt((footnote_definition_end_matcher, whitespace_eof))(remaining)?;
let source = get_consumed(input, remaining);
Ok((
remaining,
@ -67,9 +67,13 @@ fn footnote_definition_end<'r, 's>(
context: Context<'r, 's>,
input: &'s str,
) -> Res<&'s str, &'s str> {
let start_of_line_matcher = parser_with_context!(start_of_line)(&context);
recognize(tuple((
start_of_line_matcher,
verify(many1(blank_line), |lines: &Vec<&str>| lines.len() >= 2),
)))(input)
let start_of_line_matcher = parser_with_context!(start_of_line)(context);
let footnote_definition_matcher = parser_with_context!(footnote_definition)(context);
alt((
recognize(tuple((multispace0, footnote_definition_matcher))),
recognize(tuple((
start_of_line_matcher,
verify(many1(blank_line), |lines: &Vec<&str>| lines.len() >= 2),
))),
))(input)
}

View File

@ -1,34 +1,3 @@
prologue *goes here* I guess *bold
text*
bold*wont* start *or stop*when there is text outside it
I guess *regular
text*
[foo *bar] baz* car
*nesting *bold entrances* and* exits
* Heading
body of heading
** Child heading
** Immediate second child heading
* Second top-level heading
foo bar
1. This is a list immediately after a paragraph
2. This is a second item in the list
1. This is a child of the second item
#+begin_center
1. foo
2. bar
#+end_center
[fn:1] A footnote.
[fn:2] A multi-