Add parsers for lines that are indented less than or equal to the current line item's indent.
This commit is contained in:
parent
29904f2bb5
commit
6d19eeb0f4
@ -10,11 +10,14 @@ use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::peek;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::verify;
|
||||
use nom::multi::many0_count;
|
||||
use nom::multi::many1;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::combinator::context_many_till;
|
||||
use super::error::CustomError;
|
||||
use super::error::MyError;
|
||||
use super::error::Res;
|
||||
use super::paragraph::paragraph_end;
|
||||
use super::parser_context::ContextElement;
|
||||
@ -115,3 +118,26 @@ pub fn item_end<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, &'
|
||||
recognize(tuple((line_ending, peek(item_matcher)))),
|
||||
))(i)
|
||||
}
|
||||
|
||||
fn line_indented_lte<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, &'s str> {
|
||||
let current_item_indent_level: &usize = get_context_item_indent(context).ok_or(
|
||||
nom::Err::Error(CustomError::MyError(MyError("NotInPlainListItem"))),
|
||||
)?;
|
||||
|
||||
let matched = recognize(verify(
|
||||
tuple((line_ending::<&str, _>, space0, anychar)),
|
||||
|(_newline, _space0, _anychar)| _space0.len() <= *current_item_indent_level,
|
||||
))(i)?;
|
||||
|
||||
Ok(matched)
|
||||
}
|
||||
|
||||
fn get_context_item_indent<'r, 's>(context: Context<'r, 's>) -> Option<&'r usize> {
|
||||
for thing in context.iter() {
|
||||
match thing.get_data() {
|
||||
ContextElement::ListItem(depth) => return Some(depth),
|
||||
_ => {}
|
||||
};
|
||||
}
|
||||
None
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user