fixup! 37b213fdafacf85b84282d24112b30b80c78c42f

This commit is contained in:
Noah Hellman 2022-12-01 20:34:23 +01:00
parent 6717ed38f5
commit d4214ce431
2 changed files with 16 additions and 1 deletions

View file

@ -91,11 +91,22 @@ impl<'s> Parser<'s> {
match &kind {
Block::Leaf(l) => {
self.tree.enter(kind, span);
lines[0] = lines[0].with_start(span.end());
let first = &mut lines[0];
*first = first.with_start(span.end());
// trim starting whitespace of block
*first = Span::new(
first.end() - first.of(self.src).trim_start().len(),
first.end(),
);
let len = match l {
CodeBlock { .. } => len - 2,
_ => len,
};
if !matches!(l, Leaf::CodeBlock { .. }) {
// trim ending whitespace of block
let last = &mut lines[len - 1];
*last = last.with_len(last.of(self.src).trim_end().len());
}
for line in &lines[0..len] {
self.tree.elem(Atom::Inline, *line);
}

View file

@ -24,6 +24,10 @@ impl Span {
Self::new(start, self.end())
}
pub fn with_len(self, len: usize) -> Self {
Self::by_len(self.start(), len)
}
pub fn trim_start(self, n: usize) -> Self {
Self::new(self.start().checked_add(n).unwrap(), self.end())
}