.414989552471815:4877ac3507274f33d51f97ffbb852acc_69eb2aaf286388925d723dad.69eb2b80286388925d723de5.69eb2b80cf35f4552b2be12a:Trae CN.T(2026/4/24 16:36:16)#3957
Conversation
添加对空块引用的处理,当块引用内容仅为空白字符时跳过解析 新增测试用例验证空块引用场景
|
@zilvya is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
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.
| // Skip empty blockquotes (only whitespace content) | ||
| if (!text.trim()) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
| 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(); | ||
| } |
|
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]}); |
添加对空块引用的处理,当块引用内容仅为空白字符时跳过解析
新增测试用例验证空块引用场景
Marked version:
Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a
Description
Contributor
Committer
In most cases, this should be a different person than the contributor.