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.
This commit is contained in:
Miodrag Obradovic
2026-09-08 09:29:33 -06:00
committed by GitHub
parent dbb393deeb
commit 123ce04b81
3 changed files with 29 additions and 1 deletions
+1 -1
View File
@@ -283,7 +283,7 @@ const blockPedantic: Record<BlockKeys, RegExp> = {
const escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
const inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
const br = /^( {2,}|\\)\n(?!\s*$)/;
const br = /^( {2,}|\\)\n(?!\s*$)[ \t]*/;
const inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
// list of unicode punctuation marks, plus any missing characters from CommonMark spec
@@ -0,0 +1,8 @@
<p>foo<br>bar</p>
<p>foo<br>bar</p>
<p>foo<br>bar</p>
<p>foo<br>bar</p>
<p>foo
bar</p>
<p>foo
bar</p>
@@ -0,0 +1,20 @@
---
renderExact: true
---
foo
bar
foo\
bar
foo
bar
foo
bar
foo
bar
foo
bar