mirror of
https://github.com/markedjs/marked.git
synced 2026-11-30 16:48:05 +01:00
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:
+1
-1
@@ -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
|
||||
Reference in New Issue
Block a user