Add support for parsing description lists.

This commit is contained in:
Tom Alexander 2023-08-29 18:07:29 -04:00
parent ea6faf728c
commit 2682779534
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,7 @@
- foo :: bar
- cat ::
- cat ::
dog
- lorem
:: ipsum
-
lorem :: ipsum

View File

@ -1,12 +1,15 @@
use nom::branch::alt;
use nom::bytes::complete::tag;
use nom::character::complete::anychar;
use nom::character::complete::digit1;
use nom::character::complete::line_ending;
use nom::character::complete::multispace1;
use nom::character::complete::one_of;
use nom::character::complete::space0;
use nom::character::complete::space1;
use nom::combinator::eof;
use nom::combinator::opt;
use nom::combinator::peek;
use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many1;
@ -138,7 +141,6 @@ pub fn plain_list_item<'r, 's>(
Into::<&str>::into(bull) != "*" || indent_level > 0
})(remaining)?;
// TODO: This isn't taking into account items that immediately line break and then have contents
let maybe_contentless_item: Res<OrgSource<'_>, OrgSource<'_>> = eof(remaining);
match maybe_contentless_item {
Ok((rem, _ws)) => {
@ -156,6 +158,7 @@ pub fn plain_list_item<'r, 's>(
Err(_) => {}
};
let (remaining, _maybe_tag) = opt(tuple((space1, item_tag, tag(" ::"))))(remaining)?;
let (remaining, _ws) = alt((space1, line_ending))(remaining)?;
let exit_matcher = plain_list_item_end(indent_level);
let parser_context = context
@ -262,6 +265,18 @@ fn _line_indented_lte<'r, 's>(
Ok(matched)
}
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn item_tag<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
recognize(many_till(
anychar,
peek(alt((
line_ending,
tag(" :: "),
recognize(tuple((tag(" ::"), alt((line_ending, eof))))),
))),
))(input)
}
#[cfg(test)]
mod tests {
use super::*;