diff --git a/src/parser/footnote_definition.rs b/src/parser/footnote_definition.rs index 3567cc8..f4c6b7f 100644 --- a/src/parser/footnote_definition.rs +++ b/src/parser/footnote_definition.rs @@ -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) } diff --git a/toy_language.txt b/toy_language.txt index a6af557..8fbf6b4 100644 --- a/toy_language.txt +++ b/toy_language.txt @@ -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-