From dbb393deebc5b6982cb29d7415e8a8ba5555b83a Mon Sep 17 00:00:00 2001 From: Miodrag Obradovic <99922455+Kjubikstronk@users.noreply.github.com> Date: Tue, 8 Sep 2026 17:28:16 +0200 Subject: [PATCH] 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. --- src/rules.ts | 2 +- test/specs/new/tabs_indented_code.html | 14 ++++++++++++++ test/specs/new/tabs_indented_code.md | 20 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/specs/new/tabs_indented_code.html create mode 100644 test/specs/new/tabs_indented_code.md diff --git a/src/rules.ts b/src/rules.ts index 33643c5f..8da5ffea 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -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+/, diff --git a/test/specs/new/tabs_indented_code.html b/test/specs/new/tabs_indented_code.html new file mode 100644 index 00000000..d036d907 --- /dev/null +++ b/test/specs/new/tabs_indented_code.html @@ -0,0 +1,14 @@ +
foo baz bim
+
+sep
+three spaces and a tab
+
+sep
+lone tab
+
+sep
+four spaces
+
+sep
+ five spaces
+
diff --git a/test/specs/new/tabs_indented_code.md b/test/specs/new/tabs_indented_code.md
new file mode 100644
index 00000000..86081e61
--- /dev/null
+++ b/test/specs/new/tabs_indented_code.md
@@ -0,0 +1,20 @@
+---
+renderExact: true
+---
+ foo baz bim
+
+sep
+
+ three spaces and a tab
+
+sep
+
+ lone tab
+
+sep
+
+ four spaces
+
+sep
+
+ five spaces