Skip to content

Commit 123ce04

Browse files
authored
fix: drop the leading whitespace after a hard line break (#4075)
* fix: drop the leading whitespace after a hard line break CommonMark ignores leading spaces at the start of the line following a hard line break. The br rule consumed the break but not that indentation, so it stayed on the following text token. Fixes CommonMark examples 636 and 637. Neither marked's differ nor an exact comparison can see this: the differ ignores whitespace, and exact still differs on <br> versus <br />. Under the spec's own normalize.py the count goes from 28 to 26. * fix: also drop a leading tab after a hard line break The rule only consumed spaces, so a continuation line indented with a tab kept it. Both the reference implementation and markdown-it drop tabs there as well. * test: move the hard line break tests to test/specs/new Uses renderExact so the fixture compares exactly, which htmlIsEqual does not, and the assertions keep their teeth outside marked.test.js.
1 parent dbb393d commit 123ce04

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎src/rules.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ const blockPedantic: Record<BlockKeys, RegExp> = {
283283

284284
const escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
285285
const inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
286-
const br = /^( {2,}|\\)\n(?!\s*$)/;
286+
const br = /^( {2,}|\\)\n(?!\s*$)[ \t]*/;
287287
const inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
288288

289289
// list of unicode punctuation marks, plus any missing characters from CommonMark spec
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<p>foo<br>bar</p>
2+
<p>foo<br>bar</p>
3+
<p>foo<br>bar</p>
4+
<p>foo<br>bar</p>
5+
<p>foo
6+
bar</p>
7+
<p>foo
8+
bar</p>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
renderExact: true
3+
---
4+
foo
5+
bar
6+
7+
foo\
8+
bar
9+
10+
foo
11+
bar
12+
13+
foo
14+
bar
15+
16+
foo
17+
bar
18+
19+
foo
20+
bar

0 commit comments

Comments
 (0)