Consume the trailing whitespace after a headline.

This commit is contained in:
Tom Alexander
2023-03-25 11:59:19 -04:00
parent b65c2f86b5
commit 3a0a4c8953
4 changed files with 31 additions and 11 deletions

View File

@@ -1,3 +1,13 @@
use nom::branch::alt;
use nom::character::complete::line_ending;
use nom::character::complete::space0;
use nom::combinator::eof;
use nom::combinator::not;
use nom::combinator::recognize;
use nom::multi::many0;
use nom::sequence::tuple;
use super::error::Res;
use super::parser_context::ContextElement;
use super::Context;
@@ -54,6 +64,18 @@ pub fn get_consumed<'s>(input: &'s str, remaining: &'s str) -> &'s str {
source
}
/// A line containing only whitespace and then a line break
///
/// It is up to the caller to ensure this is called at the start of a line.
pub fn blank_line(input: &str) -> Res<&str, &str> {
not(eof)(input)?;
recognize(tuple((space0, alt((line_ending, eof)))))(input)
}
pub fn trailing_whitespace(input: &str) -> Res<&str, &str> {
alt((eof, recognize(tuple((line_ending, many0(blank_line))))))(input)
}
#[cfg(test)]
mod tests {
use super::*;