fix: strip a tab that follows spaces in an indented code block (#4080)

* fix: strip a tab that follows spaces in an indented code block

codeRemoveIndent tried its space alternative first, so a line indented
with spaces then a tab lost only the spaces and kept the tab as content.
Trying the tab alternative first matches CommonMark example 2, where a
tab advances to the next four column stop and the whole run is indent.

* test: move the tab tests to test/specs/new

Uses renderExact so the fixture compares exactly, which htmlIsEqual
does not, and keeps the assertions out of marked.test.js.
This commit is contained in:
Miodrag Obradovic
2026-09-08 09:28:16 -06:00
committed by GitHub
parent 24bf47c732
commit dbb393deeb
3 changed files with 35 additions and 1 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ try {
})();
export const other = {
codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm,
codeRemoveIndent: /^(?: {0,3}\t| {1,4})/gm,
outputLinkReplace: /\\([\[\]])/g,
indentCodeCompensation: /^(\s+)(?:```)/,
beginningSpace: /^\s+/,
+14
View File
@@ -0,0 +1,14 @@
<pre><code>foo baz bim
</code></pre>
<p>sep</p>
<pre><code>three spaces and a tab
</code></pre>
<p>sep</p>
<pre><code>lone tab
</code></pre>
<p>sep</p>
<pre><code>four spaces
</code></pre>
<p>sep</p>
<pre><code> five spaces
</code></pre>
+20
View File
@@ -0,0 +1,20 @@
---
renderExact: true
---
foo baz bim
sep
three spaces and a tab
sep
lone tab
sep
four spaces
sep
five spaces