Skip to content

Commit

Permalink
SimpleBlock::parse consumes blank lines that follow the block
Browse files Browse the repository at this point in the history
  • Loading branch information
scouten committed Dec 27, 2023
1 parent f197912 commit d06e84a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/blocks/simple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use nom::{multi::many1, IResult};

use crate::{primitives::non_empty_line, Span};
use crate::{
primitives::{consume_empty_lines, non_empty_line},
Span,
};

/// A block that's treated as contiguous lines of paragraph text (and subject to
/// normal substitutions) (e.g., a paragraph block).
Expand All @@ -14,6 +17,6 @@ impl<'a> SimpleBlock<'a> {
#[allow(dead_code)] // TEMPORARY
pub(crate) fn parse(i: Span<'a>) -> IResult<Span, Self> {
let (i, inlines) = many1(non_empty_line)(i)?;
Ok((i, Self { inlines }))
Ok((consume_empty_lines(i), Self { inlines }))
}
}
15 changes: 15 additions & 0 deletions src/tests/blocks/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,18 @@ fn multiple_lines() {
assert_eq!(block.inlines[1].col(), 1);
assert_eq!(*block.inlines[1].data(), "def");
}

#[test]
fn consumes_blank_lines_after() {
let expected = SimpleBlock {
inlines: vec![Span::new("abc", true)],
};

let (rem, block) = SimpleBlock::parse(Span::new("abc\n\ndef", true)).unwrap();

assert_eq!(rem.line(), 3);
assert_eq!(rem.col(), 1);
assert_eq!(*rem.data(), "def");

assert_eq!(block, expected);
}

0 comments on commit d06e84a

Please sign in to comment.