Skip to content

Conversation

@yanghuanrong
Copy link
Contributor

@yanghuanrong yanghuanrong commented Jan 28, 2026

…le unclosed tags

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

💡 Background and Solution

  1. 之前只考虑\n\n 的换行,现在对\n- \n 1. 等可能引起换行的解析做了兼容处理
  2. 优化了标签在未闭合的时候,流式输出也可以正常显示
  3. 修改了内部占位符在 think 组件下被意外展示的情况。

📝 Change Log

Language Changelog
🇺🇸 English Enhance custom in-tag line break protection and handle unclosed tags
🇨🇳 Chinese 增强自定义标签内换行符保护机制并处理未闭合标签

Summary by CodeRabbit

发布说明

  • Tests

    • 合并并扩展测试用例,覆盖自定义标签内单/双换行、空内容、未闭合/错配标签、HTML 转义和多种代码块渲染场景,提升边缘情况验证覆盖率。
  • Refactor

    • 优化自定义标签内换行保护和对未闭合标签的处理逻辑,改进占位符恢复流程,提升解析稳定性与代码块渲染一致性。

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 28, 2026

Prepare preview

@dosubot dosubot bot added the bug Something isn't working label Jan 28, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 x-markdown parser's ability to process custom HTML-like tags within Markdown content. The primary goal is to ensure that line breaks inside these custom tags are preserved as literal newlines rather than being converted into paragraph elements, and to provide a more resilient parsing experience when tags are left unclosed. These changes lead to more predictable and accurate rendering of complex Markdown documents that incorporate custom components.

Highlights

  • Enhanced Custom Tag Line Break Protection: The protectCustomTagNewlines feature has been significantly improved to protect all types of newlines (single \n and double \n\n) within custom tags, preventing them from being incorrectly parsed as paragraph breaks by Markdown.
  • Robust Unclosed Tag Handling: The parser now gracefully handles unclosed custom tags, ensuring that their content is correctly protected from Markdown parsing and displayed as intended, even when tags are not properly closed or are mismatched.
  • Optimized Placeholder Mechanism: Internal placeholders used for protecting content are now more robust, preventing them from being inadvertently displayed in the final output, particularly in specific component contexts.
  • Comprehensive Test Coverage: New test cases have been added to validate the enhanced line break protection, handling of empty and unclosed custom tags, mismatched tags, and improved escapeHtml utility, as well as code block rendering.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

该 PR 扩展并重构了 XMarkdown 的测试覆盖,新增代码块渲染测试,并在解析器中引入基于 Unicode (U+2063) 的换行保护以统一处理自定义标签内部换行,改进末尾未闭合标签处理与占位符恢复逻辑。

Changes

内聚体 / 文件 变更摘要
测试套件扩展
packages/x-markdown/src/XMarkdown/__tests__/Parser.test.ts
合并 openLinksInNewTab 测试;新增/重命名并扩展 protectCustomTagNewlines 测试以覆盖单双换行、空内容、未闭合、嵌套与无自定义标签场景;扩展 escapeHtml 边界测试;新增 configureCodeRenderer(围栏代码、缩进代码、语言指示等);删除若干旧测试。
核心解析逻辑改进
packages/x-markdown/src/XMarkdown/core/Parser.ts
引入基于 Unicode word joiner (U+2063) 的 newline 保护工具并替换旧 __X_MD_PLACEHOLDER__ 方案;对成对自定义标签内部统一应用保护;在内容末尾存在未闭合标签时保护并作为 open-tag 片段输出;更新占位符恢复逻辑以匹配新格式;添加中文注释说明未闭合标签处理。

Sequence Diagram(s)

(无)

Estimated code review effort

🎯 3 (中等) | ⏱️ ~30 分钟

Poem

我是兔子,轻跳在代码草丛间,
用 U+2063 把换行轻轻藏好,
标签若断我也能拼补成环,
测试更广,渲染更稳,我会欢笑,
嘿咻,解析通顺我就蹦跳! 🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 拉取请求标题准确概括了主要变更:改进自定义标签内换行符保护并处理未闭合标签,与代码更改内容完全相符。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
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

本次 PR 有效地增强了 Markdown 解析器,改进了对自定义标签内部换行符的保护,并增加了对未闭合标签的健壮处理,这对于流式渲染场景尤其有用。将保护策略从仅保护双换行符(\n\n)升级为保护自定义标签内的所有换行符(\n),是一个显著的改进,可以防止意外的 Markdown 渲染。处理未闭合标签的逻辑——即把直到流结束的内容都视为该标签的一部分——是合理的。此外,测试套件也得到了改进,增加了覆盖这些变更的新测试用例,并进行了一些重构以提高清晰度。代码质量很高,所做的修改与既定目标完全一致。

@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.34%. Comparing base (ef1b6c5) to head (c03c40b).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


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/);
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

请补充对应的测试用例以佐证此次变更的必要性。依据 CommonMark 规范,\n 不会引发块级结构的重新划分,因此通常无需特殊处理。如有例外情况,建议通过测试用例明确其上下文或兼容性需求。

Copy link
Contributor Author

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
expect(resultWithout).toContain('<li>');

const resultWith = parserWithProtect.parse(content);
expect(resultWith).toContain('<CustomComponent>Text\n- item1</CustomComponent>');
Copy link
Contributor

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)。

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants