-
-
Notifications
You must be signed in to change notification settings - Fork 996
fix(x-markdown): enhance custom in-tag line break protection and hand… #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @yanghuanrong, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthrough该 PR 扩展并重构了 XMarkdown 的测试覆盖,新增代码块渲染测试,并在解析器中引入基于 Unicode (U+2063) 的换行保护以统一处理自定义标签内部换行,改进末尾未闭合标签处理与占位符恢复逻辑。 Changes
Sequence Diagram(s)(无) Estimated code review effort🎯 3 (中等) | ⏱️ ~30 分钟 Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
本次 PR 有效地增强了 Markdown 解析器,改进了对自定义标签内部换行符的保护,并增加了对未闭合标签的健壮处理,这对于流式渲染场景尤其有用。将保护策略从仅保护双换行符(\n\n)升级为保护自定义标签内的所有换行符(\n),是一个显著的改进,可以防止意外的 Markdown 渲染。处理未闭合标签的逻辑——即把直到流结束的内容都视为该标签的一部分——是合理的。此外,测试套件也得到了改进,增加了覆盖这些变更的新测试用例,并进行了一些重构以提高清晰度。代码质量很高,所做的修改与既定目标完全一致。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1711 +/- ##
=======================================
Coverage 97.33% 97.34%
=======================================
Files 144 144
Lines 4577 4587 +10
Branches 1286 1271 -15
=======================================
+ Hits 4455 4465 +10
Misses 120 120
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| const result2 = parser.parse('<CustomComponent>Line1\nLine2</CustomComponent>'); | ||
| expect(result2).toContain('<CustomComponent>Line1\nLine2</CustomComponent>'); | ||
| expect(result2).not.toMatch(/<CustomComponent>Line1<\/p>\s*<p>Line2/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有开启protectCustomTagNewlines,该测试用例也会渲染为 <p><CustomComponent>First line\nSecond line</CustomComponent></p>,commonMark 规范内单个 \n 不会分块。
| const result: string[] = []; | ||
| let lastIndex = 0; | ||
|
|
||
| const NEWLINE_REGEX = /\n/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请补充对应的测试用例以佐证此次变更的必要性。依据 CommonMark 规范,\n 不会引发块级结构的重新划分,因此通常无需特殊处理。如有例外情况,建议通过测试用例明确其上下文或兼容性需求。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢指正,重新修改了测试用例。
…n custom tags - Add test case to verify single \n alone does not cause block separation per CommonMark spec - Add test cases to explain why protect all \n (using /\n/g) instead of just \n\n: - \n followed by list marker (-) causes block change - \n followed by ordered list marker (1.) causes block change - \n followed by heading marker (#) causes block change - \n followed by code fence (```) causes block change - Add test case for blockquote marker (>) being escaped by marked
b0231dd to
c03c40b
Compare
| expect(resultWithout).toContain('<li>'); | ||
|
|
||
| const resultWith = parserWithProtect.parse(content); | ||
| expect(resultWith).toContain('<CustomComponent>Text\n- item1</CustomComponent>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yanghuanrong 感谢提交 PR!当前的修改会破坏 CommonMark 规范,会导致子元素内所有新的块格式无法被解析。在规范中,行内 HTML 的子元素应当被解析为 Markdown;如果该组件不需要解析内部结构,建议将其实现为块级组件(Block Component)。

…le unclosed tags
中文版模板 / Chinese template
🤔 This is a ...
🔗 Related Issues
💡 Background and Solution
📝 Change Log
Summary by CodeRabbit
发布说明
Tests
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.