Record the list item indent depth in the context tree.

This commit is contained in:
Tom Alexander 2023-03-17 16:49:09 -04:00
parent 32897270a5
commit 88c974f8e4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 9 additions and 1 deletions

View File

@ -95,6 +95,7 @@ fn _preceded_by_whitespace<'r, 's>(context: Context<'r, 's>) -> bool {
return true; return true;
} }
ContextElement::Context(_) => {} ContextElement::Context(_) => {}
ContextElement::ListItem(_) => {}
} }
} else { } else {
break; break;

View File

@ -46,6 +46,7 @@ where
ContextElement::ExitMatcherNode(_) => None, ContextElement::ExitMatcherNode(_) => None,
ContextElement::Context(_) => None, ContextElement::Context(_) => None,
ContextElement::StartOfParagraph => None, ContextElement::StartOfParagraph => None,
ContextElement::ListItem(_) => None,
}) })
.collect(); .collect();
if elements.is_empty() { if elements.is_empty() {
@ -93,6 +94,7 @@ where
}) => { }) => {
ret.push(token); ret.push(token);
} }
ContextElement::ListItem(_) => {}
}; };
} }
ret.reverse(); ret.reverse();

View File

@ -87,6 +87,7 @@ impl<'r, 's> ContextTree<'r, 's> {
ContextElement::PreviousElementNode(_) => {} ContextElement::PreviousElementNode(_) => {}
ContextElement::StartOfParagraph => {} ContextElement::StartOfParagraph => {}
ContextElement::Context(_) => {} ContextElement::Context(_) => {}
ContextElement::ListItem(_) => {}
}; };
} }
// TODO: Make this a specific error instead of just a generic MyError // TODO: Make this a specific error instead of just a generic MyError
@ -99,6 +100,7 @@ pub enum ContextElement<'r, 's> {
ExitMatcherNode(ExitMatcherNode<'r>), ExitMatcherNode(ExitMatcherNode<'r>),
PreviousElementNode(PreviousElementNode<'s>), PreviousElementNode(PreviousElementNode<'s>),
Context(&'r str), Context(&'r str),
ListItem(usize),
StartOfParagraph, StartOfParagraph,
} }

View File

@ -16,6 +16,7 @@ use nom::sequence::tuple;
use super::combinator::context_many_till; use super::combinator::context_many_till;
use super::error::Res; use super::error::Res;
use super::paragraph::paragraph_end; use super::paragraph::paragraph_end;
use super::parser_context::ContextElement;
use super::text::space; use super::text::space;
use super::text::text_element; use super::text::text_element;
use super::token::ListItem; 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>> { pub fn item<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, ListItem<'s>> {
let (remaining, leading_whitespace) = space0(i)?; let (remaining, leading_whitespace) = space0(i)?;
let indent_level = leading_whitespace.len(); 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(( let (remaining, (bul, countset, check, tg, sp, (contents, end))) = tuple((
bullet, bullet,
opt(tuple((space, counter_set))), 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))), opt(tuple((space, item_tag))),
space, space,
// TODO: This context should probably be something involving the item // 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)?; ))(remaining)?;
let elements = contents let elements = contents

View File

@ -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(name) if *name == section_name => return true,
ContextElement::Context(_) => {} ContextElement::Context(_) => {}
ContextElement::StartOfParagraph => {} // TODO: If we specialize this to bold then this would be a good spot to stop scanning ContextElement::StartOfParagraph => {} // TODO: If we specialize this to bold then this would be a good spot to stop scanning
ContextElement::ListItem(_) => {}
} }
} }
false false