Skip to content

.414989552471815:4877ac3507274f33d51f97ffbb852acc_69eb2aaf286388925d723dad.69eb2b80286388925d723de5.69eb2b80cf35f4552b2be12a:Trae CN.T(2026/4/24 16:36:16)#3957

Open
zilvya wants to merge 1 commit intomarkedjs:masterfrom
zilvya:a1

Conversation

@zilvya
Copy link
Copy Markdown

@zilvya zilvya commented Apr 25, 2026

添加对空块引用的处理,当块引用内容仅为空白字符时跳过解析
新增测试用例验证空块引用场景

Marked version:

Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a

Description

  • Fixes #### (if fixing a known issue; otherwise, describe issue using the following format)

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

添加对空块引用的处理,当块引用内容仅为空白字符时跳过解析
新增测试用例验证空块引用场景
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 25, 2026

@zilvya is attempting to deploy a commit to the MarkedJS Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request attempts to skip empty blockquotes in the tokenizer and adds a manual test script to verify the behavior. However, the review feedback highlights that this change violates Markdown specifications (CommonMark and GFM) which explicitly allow empty blockquotes. Additionally, the implementation causes the Lexer to fallback to the text tokenizer, leading to incorrect HTML output where the blockquote marker is escaped as plain text. The review also notes that the new test file does not follow the project's established directory structure for tests.

Comment thread src/Tokenizer.ts
Comment on lines +224 to +227
// Skip empty blockquotes (only whitespace content)
if (!text.trim()) {
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

此更改违反了 Markdown 规范(如 CommonMark 和 GFM),这些规范明确允许空块引用(例如,仅包含 > 的行)。

此外,此处返回 undefined 并没有真正“跳过”内容。相反,它会导致 Lexer 回退并尝试其他 Tokenizer。由于 text Tokenizer 是兜底的,这些空块引用标记最终会被解析为普通文本(例如 > 会变成 <p>&gt;</p>),这通常不是“跳过”所期望的结果。

从性能角度看,在完成整个块引用的复杂解析逻辑后再决定丢弃结果也是低效的。建议移除此逻辑以保持对 Markdown 标准的兼容性。

Comment thread test-empty-blockquote.js
Comment on lines +1 to +19
import { marked } from './lib/marked.esm.js';

// 测试用例
const testCases = [
'>', // 纯 >
'> ', // > 加空格
'>\t', // > 加制表符
'>\n>', // 两行空引用
'> \n> ', // 两行带空格的空引用
'> hello', // 正常引用(应该保留)
];

console.log('=== 测试空引用块解析 ===\n');

for (const test of testCases) {
console.log(`输入: ${JSON.stringify(test)}`);
console.log(`输出: ${JSON.stringify(marked(test))}`);
console.log();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

该测试文件不符合项目的测试规范。marked 项目通常将测试用例放在 test/specs/ 目录下。

此外,该测试脚本输出的结果(如将 ">" 渲染为 "

>

")证实了此 PR 破坏了 Markdown 的标准行为。建议移除此文件,并优先修复 src/Tokenizer.ts 中的逻辑问题。

@UziTech
Copy link
Copy Markdown
Member

UziTech commented Apr 25, 2026

CommonMark allows empty block quotes. demo

If you want to do this for your usage, you can create a custom extension that checks for empty block quotes and renders them as text.

Something like:

const emptyblockquote = {
  name: "emptyblockquote",
  level: "block",
  tokenizer(src) {
    const match = src.match(/(>[ \t]*($|\n))+/);
    if(match) {
      return {
        name: "text",
        raw: match[0],
        text: match[0],
        tokens: this.lexer.inline(match[0]),
      }
    }
  },
};

marked.use({extensions: [emptyblockquote]});

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants