Make sure text markup doesn't have interior spaces.
This commit is contained in:
@@ -151,6 +151,28 @@ pub fn start_of_line<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'
|
||||
Ok((input, ()))
|
||||
}
|
||||
|
||||
/// Check that we are at the start of a line
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn preceded_by_whitespace<'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('\r') | Some(' ') | Some('\t') => {}
|
||||
// If None, we are at the start of the file which is not allowed
|
||||
None | Some(_) => {
|
||||
return Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"Not preceded by whitespace.",
|
||||
))));
|
||||
}
|
||||
};
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user