fix(markdown): disable indented code blocks in comment rendering#958
Conversation
Lines prefixed with four spaces were parsed as indented code blocks, breaking paragraph layout when users tried to indent text with spaces. Keep fenced ``` code blocks; only disable the legacy 4-space rule. Fixes #855 Co-authored-by: Cursor <cursoragent@cursor.com>
审阅者指南(在小型 PR 上折叠显示)审阅者指南通过重写 marked 的 tokenizer 中的 code 处理函数,禁用 Markdown 旧版的 4 空格缩进代码块渲染,同时保持围栏代码块(fenced code block)的行为不变。 取消缩进代码块后的评论 Markdown 渲染时序图sequenceDiagram
title Sequence diagram for comment markdown rendering without indented code blocks
actor User
participant CommentUI
participant marked
participant tokenizer_code
User->>CommentUI: submitComment(textWithLeadingSpaces)
CommentUI->>marked: parse(textWithLeadingSpaces)
marked->>tokenizer_code: code(src, tokens)
tokenizer_code-->>marked: undefined
marked-->>CommentUI: htmlWithParagraphs
CommentUI-->>User: renderComment(htmlWithParagraphs)
文件级变更
与关联 issue 的对照评估
可能相关的 issues
技巧与命令与 Sourcery 互动
自定义使用体验访问你的 控制面板 以:
获取帮助Original review guide in EnglishReviewer's guide (collapsed on small PRs)Reviewer's GuideDisables Markdown’s legacy 4-space indented code blocks in comment rendering by overriding the marked tokenizer’s code handler while keeping fenced code blocks intact. Sequence diagram for comment markdown rendering without indented code blockssequenceDiagram
title Sequence diagram for comment markdown rendering without indented code blocks
actor User
participant CommentUI
participant marked
participant tokenizer_code
User->>CommentUI: submitComment(textWithLeadingSpaces)
CommentUI->>marked: parse(textWithLeadingSpaces)
marked->>tokenizer_code: code(src, tokens)
tokenizer_code-->>marked: undefined
marked-->>CommentUI: htmlWithParagraphs
CommentUI-->>User: renderComment(htmlWithParagraphs)
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - 我发现了 1 个问题,并留下了一些总体反馈:
- 将
tokenizer.code覆写为始终返回undefined也会禁用围栏代码块,这与 PR 描述相矛盾;建议检查源码,只跳过缩进(4 空格)代码块,同时保留围栏代码块。 - 如果这个
marked实例在评论渲染之外也会被重用,那么在这里全局禁用代码块可能会带来意料之外的副作用;建议把这个 tokenizer 覆写限定在用于评论的专用 Markdown 处理流程中,而不是放在共享工具里。
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Overriding `tokenizer.code` to always return `undefined` will also disable fenced code blocks, which contradicts the PR description; consider inspecting the source to skip only indented (4-space) code blocks while preserving fenced blocks.
- If this `marked` instance is reused outside of comment rendering, globally disabling code blocks here may have unintended side effects; consider scoping this tokenizer override to the comment-specific Markdown pipeline instead of the shared utility.
## Individual Comments
### Comment 1
<location path="src/client/utils/marked.js" line_range="21-22" />
<code_context>
+// otherwise render as a code block (#855).
+marked.use({
+ tokenizer: {
+ code () {
+ return undefined
+ }
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** 用 `return undefined` 覆写 `tokenizer.code` 很可能并不能按预期禁用 4 空格代码块。
在 marked 的扩展 API 中,从 tokenizer 方法返回 `undefined` 通常意味着回退到默认 tokenizer,所以这可能实际上并不会禁用缩进代码块。要可靠地关闭 4 空格缩进代码,你很可能需要要么将这些行转换成其他 token 类型(例如 paragraph/text),要么调整块级规则,使得缩进行永远不会到达 `code()`。请确认你所使用的 marked 版本中 `code()` tokenizer 的约定,以避免悄悄地保持原有行为不变。
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进评审质量。
Original comment in English
Hey - I've found 1 issue, and left some high level feedback:
- Overriding
tokenizer.codeto always returnundefinedwill also disable fenced code blocks, which contradicts the PR description; consider inspecting the source to skip only indented (4-space) code blocks while preserving fenced blocks. - If this
markedinstance is reused outside of comment rendering, globally disabling code blocks here may have unintended side effects; consider scoping this tokenizer override to the comment-specific Markdown pipeline instead of the shared utility.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Overriding `tokenizer.code` to always return `undefined` will also disable fenced code blocks, which contradicts the PR description; consider inspecting the source to skip only indented (4-space) code blocks while preserving fenced blocks.
- If this `marked` instance is reused outside of comment rendering, globally disabling code blocks here may have unintended side effects; consider scoping this tokenizer override to the comment-specific Markdown pipeline instead of the shared utility.
## Individual Comments
### Comment 1
<location path="src/client/utils/marked.js" line_range="21-22" />
<code_context>
+// otherwise render as a code block (#855).
+marked.use({
+ tokenizer: {
+ code () {
+ return undefined
+ }
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** Overriding `tokenizer.code` with `return undefined` likely does not disable 4‑space code blocks as intended.
In marked’s extension API, returning `undefined` from a tokenizer method usually defers to the default tokenizer, so this may not actually disable indented code blocks. To reliably turn off 4-space-indented code, you’ll likely need to either transform those lines into a different token type (e.g., paragraph/text) or adjust the block rules so indented lines never reach `code()`. Please confirm the `code()` tokenizer contract for your marked version so this doesn’t silently leave the original behavior unchanged.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| code () { | ||
| return undefined |
There was a problem hiding this comment.
issue (bug_risk): 用 return undefined 覆写 tokenizer.code 很可能并不能按预期禁用 4 空格代码块。
在 marked 的扩展 API 中,从 tokenizer 方法返回 undefined 通常意味着回退到默认 tokenizer,所以这可能实际上并不会禁用缩进代码块。要可靠地关闭 4 空格缩进代码,你很可能需要要么将这些行转换成其他 token 类型(例如 paragraph/text),要么调整块级规则,使得缩进行永远不会到达 code()。请确认你所使用的 marked 版本中 code() tokenizer 的约定,以避免悄悄地保持原有行为不变。
Original comment in English
issue (bug_risk): Overriding tokenizer.code with return undefined likely does not disable 4‑space code blocks as intended.
In marked’s extension API, returning undefined from a tokenizer method usually defers to the default tokenizer, so this may not actually disable indented code blocks. To reliably turn off 4-space-indented code, you’ll likely need to either transform those lines into a different token type (e.g., paragraph/text) or adjust the block rules so indented lines never reach code(). Please confirm the code() tokenizer contract for your marked version so this doesn’t silently leave the original behavior unchanged.
Summary
Disable Markdown's legacy 4-space indented code blocks in Twikoo comment rendering. Fenced ``` code blocks remain supported.
Problem
Fixes #855. Users who prefix lines with four spaces for visual indentation were getting code-block layout instead of normal paragraph text.
Test plan
Summary by Sourcery
Bug Fixes:
Original summary in English
Summary by Sourcery
Bug Fixes: