Record the list item indent depth in the context tree.
This commit is contained in:
parent
32897270a5
commit
88c974f8e4
@ -95,6 +95,7 @@ fn _preceded_by_whitespace<'r, 's>(context: Context<'r, 's>) -> bool {
|
||||
return true;
|
||||
}
|
||||
ContextElement::Context(_) => {}
|
||||
ContextElement::ListItem(_) => {}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user