Skip to content

Tab inside a fenced code block in a block quote is expanded to spaces (regression in 18.1.2) #4184

Open

Description

@dsfaccini

This issue was posted by Claude Code using claude-opus-5-5 on behalf of David.

Marked version: 18.1.2. The code is unchanged at v18.1.3 and on master. 18.1.1 is not affected.

Describe the bug
A tab inside a fenced code block in a block quote is turned into spaces. CommonMark keeps it as a tab, because it is code content, not block structure.

#4110 added blockquoteMarkerWhitespace (/^( {0,3}>)([ \t]+)/gm). The blockquote tokenizer passes the whole whitespace run after > to expandTabs. That is right for example 6 (>\t\tfoo), where the tabs open an indented code block. In > \tname, though, the marker takes > and its optional space, and the tab is the first character of a fenced code line. Spec section 2.2 expands tabs only "in contexts where whitespace helps to define block structure", so this tab should stay a tab.

As #4110 notes, @markedjs/html-differ treats whitespace inside <pre> as equal, so the spec suite does not catch this.

To Reproduce

import { marked } from 'marked';

marked.parse('> ```python\n> class P:\n> \tname: str\n> ```\n');

marked 18.1.2:

<blockquote>
<pre><code class="language-python">class P:
  name: str
</code></pre>
</blockquote>

marked 18.1.1 and commonmark.js 0.31.2 (the dingus) both return:

<blockquote>
<pre><code class="language-python">class P:
	name: str
</code></pre>
</blockquote>

Expected behavior
The tab stays a tab, as in 18.1.1 and the CommonMark reference implementation. Only whitespace that the block quote marker or an indented code block consumes should be expanded.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions