marked icon indicating copy to clipboard operation
marked copied to clipboard

Fix: skip inline parsing when block tokens already parsed

Open Hongweiwa opened this issue 7 months ago • 2 comments

Marked version: latest

Markdown flavor: GitHub Flavored Markdown

Description Improves the parsing behavior inside code blocks.

Prevents unnecessary inline parsing (such as emphasis, links, or special characters like @) inside fenced and indented code blocks.

No related GitHub issue — this is a proactive improvement based on observing markdown rendering inconsistencies.

Expectation Inside code blocks (fenced by ``` or indented by 4 spaces), content should be treated as plain text, without interpreting inline syntax such as @, _, *, etc.

Result Before fix:

In some situations, special characters inside code blocks were incorrectly parsed.

After fix:

Code blocks now properly preserve all content literally, matching markdown specs.

What was attempted Updated lexer and tokenizer logic to skip inline tokenization inside Tokens.Code nodes

This fix prevents Tokens.Code nodes from being parsed for inline formatting. Code blocks must render content literally without interpreting @, *, or _ as special syntax. This makes the parser behave according to markdown standards and avoids unexpected formatting issues.

Hongweiwa avatar Apr 26 '25 01:04 Hongweiwa

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marked-website ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2025 1:06am

vercel[bot] avatar Apr 26 '25 01:04 vercel[bot]

Would you be able to do the same thing by checking if token.type === 'code'?

Can you provide some markdown where marked renders something inside code blocks?

UziTech avatar Apr 26 '25 02:04 UziTech

closing as stale. If you would like to continue working on this feel free to reopen it.

UziTech avatar Jun 19 '25 03:06 UziTech