Skip to content

Commit

Permalink
remove leading spaces after a hard line break
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeando authored and kivikakk committed May 20, 2022
1 parent cbae4da commit abbe664
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/parser/inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ impl<'a, 'r, 'o, 'd, 'i, 'c, 'subj> Subject<'a, 'r, 'o, 'd, 'i, 'c, 'subj> {
strings::rtrim(&mut contents);
}

// if we've just produced a LineBreak, then we should consume any leading
// space on this line
if node.last_child().map_or(false, |n| {
matches!(n.data.borrow().value, NodeValue::LineBreak)
}) {
strings::ltrim(&mut contents);
}

Some(make_inline(self.arena, NodeValue::Text(contents)))
}
};
Expand Down
13 changes: 13 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,19 @@ fn backticks_empty_with_newline_should_be_space() {
html("`\n`", "<p><code> </code></p>\n");
}

#[test]
fn blockquote_hard_linebreak_space() {
html(">\\\n A", "<blockquote>\n<p><br />\nA</p>\n</blockquote>\n");
}

#[test]
fn blockquote_hard_linebreak_nonlazy_space() {
html(
"> A\\\n> B",
"<blockquote>\n<p>A<br />\nB</p>\n</blockquote>\n",
);
}

#[test]
fn backticks_num() {
let input = "Some `code1`. More ``` code2 ```.\n";
Expand Down

0 comments on commit abbe664

Please sign in to comment.