fix: strip a tab that follows spaces in an indented code block - #4080
Merged
UziTech merged 2 commits intoSep 8, 2026
Conversation
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.
|
@Kjubikstronk is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
Uses renderExact so the fixture compares exactly, which htmlIsEqual does not, and keeps the assertions out of marked.test.js.
Contributor
Author
|
Moved the tests to Same six cases the unit tests covered, controls included: Reverting the alternation order fails the fixture, so it has teeth. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
4 tasks
styfle
approved these changes
Sep 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Marked version: 18.0.11 (53cb13f)
Markdown flavor: CommonMark
Description
CommonMark example 2. A line indented with spaces and then a tab keeps the tab as code content:
A tab advances to the next four column stop, so
··\tis four columns of indentation and all of it belongs to the block structure, not to the content.Cause
codeRemoveIndentis/^(?: {1,4}| {0,3}\t)/gm. Regex alternation takes the first branch that matches, so on··\tfoothe{1,4}branch matches the two spaces and stops, and the tab is left in the content. The tab branch only ever gets a chance when the line has no leading space at all, which is why example 1 (\tfoo…) has always passed and example 2 has not.Swapping the order fixes it, because the tab branch already carries its own
{0,3}prefix:Every space-only input is unaffected, since the tab branch cannot match without a tab:
··\tfoo\tfoofoo···\tfoo\tfoofoo\tfoofoofoo····foofoofoo·····foo·foo·foo······foo··foo··fooThe regex is used in one place,
Tokenizer.ts:108, inside the indented code tokenizer, so it cannot reach fenced content.Measurement
Whole spec through the CommonMark repository's own
test/normalize.py, 0.31.2,gfm: false:The one that moves is example 2, and nothing else moves in either direction. That measurement matters here because marked's own suite cannot see this bug:
htmlIsEqualleavesignoreWhitespacesattrue, and the difference is indentation insidepre. Example 2 reports as passing today with noshouldFailflag against it, the same blind spot as #4073.Contributor
Six tests in
test/unit/marked.test.js, asserting exact output for the reason above. Three fail without the change; the other three are controls that must pass either way, and do. Full spec suite (1789) and unit suite (200) pass.Committer
In most cases, this should be a different person than the contributor.
Context: this is the first half of the tab work discussed in #4050. Example 6 is the other half and I am not sending it, for reasons I have written up in that issue.