Building the plain list item context.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::none_of;
|
||||
use nom::character::complete::space0;
|
||||
use nom::combinator::eof;
|
||||
use nom::combinator::not;
|
||||
@@ -7,6 +8,8 @@ use nom::combinator::recognize;
|
||||
use nom::multi::many0;
|
||||
use nom::sequence::tuple;
|
||||
|
||||
use super::error::CustomError;
|
||||
use super::error::MyError;
|
||||
use super::error::Res;
|
||||
use super::parser_context::ContextElement;
|
||||
use super::Context;
|
||||
@@ -76,6 +79,33 @@ pub fn trailing_whitespace(input: &str) -> Res<&str, &str> {
|
||||
alt((eof, recognize(tuple((line_ending, many0(blank_line))))))(input)
|
||||
}
|
||||
|
||||
/// Check that we are at the start of a line
|
||||
pub fn start_of_line<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, ()> {
|
||||
let document_root = context.get_document_root().unwrap();
|
||||
let preceding_character = get_one_before(document_root, input)
|
||||
.map(|slice| slice.chars().next())
|
||||
.flatten();
|
||||
match preceding_character {
|
||||
Some('\n') => {}
|
||||
Some(_) => {
|
||||
// Not at start of line, cannot be a heading
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not at start of line",
|
||||
))));
|
||||
}
|
||||
// If None, we are at the start of the file which allows for headings
|
||||
None => {}
|
||||
};
|
||||
Ok((input, ()))
|
||||
}
|
||||
|
||||
/// Pull one non-whitespace character.
|
||||
///
|
||||
/// This function only operates on spaces, tabs, carriage returns, and line feeds. It does not handle fancy unicode whitespace.
|
||||
pub fn non_whitespace_character(input: &str) -> Res<&str, char> {
|
||||
none_of(" \t\r\n")(input)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user