Fix handling line breaks after divider in description lists.

This commit is contained in:
Tom Alexander 2023-08-29 20:11:23 -04:00
parent 45be9e7bde
commit a6d742a536
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
3 changed files with 35 additions and 3 deletions

View File

@ -0,0 +1,2 @@
- foo ::

View File

@ -6,3 +6,6 @@
- -
lorem :: ipsum lorem :: ipsum
- dolar *bold* foo :: ipsum - dolar *bold* foo :: ipsum
- big gap ::
stuff

View File

@ -6,9 +6,12 @@ use nom::character::complete::one_of;
use nom::character::complete::space0; use nom::character::complete::space0;
use nom::character::complete::space1; use nom::character::complete::space1;
use nom::combinator::eof; use nom::combinator::eof;
use nom::combinator::not;
use nom::combinator::opt; use nom::combinator::opt;
use nom::combinator::peek;
use nom::combinator::recognize; use nom::combinator::recognize;
use nom::combinator::verify; use nom::combinator::verify;
use nom::multi::many0;
use nom::multi::many1; use nom::multi::many1;
use nom::multi::many_till; use nom::multi::many_till;
use nom::sequence::tuple; use nom::sequence::tuple;
@ -163,7 +166,7 @@ pub fn plain_list_item<'r, 's>(
parser_with_context!(item_tag)(context), parser_with_context!(item_tag)(context),
tag(" ::"), tag(" ::"),
)))(remaining)?; )))(remaining)?;
let (remaining, _ws) = alt((space1, line_ending))(remaining)?; let (remaining, _ws) = item_tag_post_gap(context, remaining)?;
let exit_matcher = plain_list_item_end(indent_level); let exit_matcher = plain_list_item_end(indent_level);
let parser_context = context let parser_context = context
.with_additional_node(ContextElement::ConsumeTrailingWhitespace(true)) .with_additional_node(ContextElement::ConsumeTrailingWhitespace(true))
@ -174,7 +177,10 @@ pub fn plain_list_item<'r, 's>(
let (remaining, (children, _exit_contents)) = many_till( let (remaining, (children, _exit_contents)) = many_till(
parser_with_context!(element(true))(&parser_context), parser_with_context!(element(true))(&parser_context),
parser_with_context!(exit_matcher_parser)(&parser_context), alt((
peek(recognize(tuple((start_of_line, many0(blank_line), eof)))),
parser_with_context!(exit_matcher_parser)(&parser_context),
)),
)(remaining)?; )(remaining)?;
let (remaining, _trailing_ws) = let (remaining, _trailing_ws) =
@ -189,7 +195,7 @@ pub fn plain_list_item<'r, 's>(
bullet: bull.into(), bullet: bull.into(),
tag: maybe_tag tag: maybe_tag
.map(|(_ws, item_tag, _divider)| item_tag) .map(|(_ws, item_tag, _divider)| item_tag)
.unwrap_or(Vec::new()), // TODO .unwrap_or(Vec::new()),
children, children,
}, },
)); ));
@ -305,6 +311,27 @@ fn item_tag_end<'r, 's>(
)))(input) )))(input)
} }
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn item_tag_post_gap<'r, 's>(
context: Context<'r, 's>,
input: OrgSource<'s>,
) -> Res<OrgSource<'s>, OrgSource<'s>> {
verify(
recognize(tuple((
alt((blank_line, space0)),
many_till(
blank_line,
alt((
peek(recognize(not(blank_line))),
peek(recognize(tuple((many0(blank_line), eof)))),
parser_with_context!(exit_matcher_parser)(context),
)),
),
))),
|gap| gap.len() > 0,
)(input)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;