diff --git a/src/parser/bold.rs b/src/parser/bold.rs index 5c64cf7..a8dc00a 100644 --- a/src/parser/bold.rs +++ b/src/parser/bold.rs @@ -95,6 +95,7 @@ fn _preceded_by_whitespace<'r, 's>(context: Context<'r, 's>) -> bool { return true; } ContextElement::Context(_) => {} + ContextElement::ListItem(_) => {} } } else { break; diff --git a/src/parser/combinator.rs b/src/parser/combinator.rs index fc0ec87..4b99f84 100644 --- a/src/parser/combinator.rs +++ b/src/parser/combinator.rs @@ -46,6 +46,7 @@ where ContextElement::ExitMatcherNode(_) => None, ContextElement::Context(_) => None, ContextElement::StartOfParagraph => None, + ContextElement::ListItem(_) => None, }) .collect(); if elements.is_empty() { @@ -93,6 +94,7 @@ where }) => { ret.push(token); } + ContextElement::ListItem(_) => {} }; } ret.reverse(); diff --git a/src/parser/parser_context.rs b/src/parser/parser_context.rs index 32bc039..07cd186 100644 --- a/src/parser/parser_context.rs +++ b/src/parser/parser_context.rs @@ -87,6 +87,7 @@ impl<'r, 's> ContextTree<'r, 's> { ContextElement::PreviousElementNode(_) => {} ContextElement::StartOfParagraph => {} ContextElement::Context(_) => {} + ContextElement::ListItem(_) => {} }; } // TODO: Make this a specific error instead of just a generic MyError @@ -99,6 +100,7 @@ pub enum ContextElement<'r, 's> { ExitMatcherNode(ExitMatcherNode<'r>), PreviousElementNode(PreviousElementNode<'s>), Context(&'r str), + ListItem(usize), StartOfParagraph, } diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index 59370a8..c226c87 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -16,6 +16,7 @@ use nom::sequence::tuple; use super::combinator::context_many_till; use super::error::Res; use super::paragraph::paragraph_end; +use super::parser_context::ContextElement; use super::text::space; use super::text::text_element; use super::token::ListItem; @@ -31,6 +32,7 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, pub fn item<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, ListItem<'s>> { let (remaining, leading_whitespace) = space0(i)?; let indent_level = leading_whitespace.len(); + let list_item_context = context.with_additional_node(ContextElement::ListItem(indent_level)); let (remaining, (bul, countset, check, tg, sp, (contents, end))) = tuple(( bullet, opt(tuple((space, counter_set))), @@ -38,7 +40,7 @@ pub fn item<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, ListIt opt(tuple((space, item_tag))), space, // TODO: This context should probably be something involving the item - context_many_till(context, text_element, item_end), + context_many_till(&list_item_context, text_element, item_end), ))(remaining)?; let elements = contents diff --git a/src/parser/util.rs b/src/parser/util.rs index 44886ce..3600c13 100644 --- a/src/parser/util.rs +++ b/src/parser/util.rs @@ -9,6 +9,7 @@ pub fn in_section<'r, 's, 'x>(context: Context<'r, 's>, section_name: &'x str) - ContextElement::Context(name) if *name == section_name => return true, ContextElement::Context(_) => {} ContextElement::StartOfParagraph => {} // TODO: If we specialize this to bold then this would be a good spot to stop scanning + ContextElement::ListItem(_) => {} } } false