Make sure text markup doesn't have interior spaces.

This commit is contained in:
Tom Alexander
2023-04-22 22:34:37 -04:00
parent da76d3714c
commit 9968aedd74
2 changed files with 28 additions and 0 deletions

View File

@@ -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.