Skip to content

Conversation

Div627
Copy link

@Div627 Div627 commented Sep 29, 2025

中文版模板 / 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?)

💡 Background and Solution

Background: 在流式渲染时,遇到未完成的图片/链接 ![img](,缓存等待时间久,用户体验差。
Solution:匹配未完成的 Markdown 语法,支持传入 components 传入加载状态。

📝 Change Log

  1. 支持通过组件匹配未完成的Markdown语法。
  2. 默认缓存 Setext headings,避免格式突变。
Language Changelog
🇺🇸 English
🇨🇳 Chinese

Copy link
Contributor

coderabbitai bot commented Sep 29, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature_markdown_format

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

github-actions bot commented Sep 29, 2025

Preview is ready

Copy link

codecov bot commented Sep 29, 2025

Bundle Report

Changes will decrease total bundle size by 1.87MB (-45.04%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
x-markdown-array-push 2.06MB -1.87MB (-47.64%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: x-markdown-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
code-high-light.js (New) 2.06MB 2.06MB 100.0% 🚀
mermaid.min.js (Deleted) -3.93MB 0 bytes -100.0% 🗑️

@dosubot dosubot bot added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 29, 2025
Copy link

Summary of Changes

Hello @Div627, 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!

此拉取请求显著增强了 XMarkdown 组件的流式渲染能力,使其能够智能地处理不完整的Markdown语法。通过引入可自定义的占位符组件,它解决了在实时内容传输过程中因语法片段导致的视觉中断和用户体验不佳的问题。此外,还对核心流式处理逻辑进行了重构,并提供了全面的新文档和示例,以支持这些改进。

Highlights

  • 支持通过组件匹配未完成的Markdown语法: 在流式渲染过程中,当遇到未完成的Markdown语法(如链接或图片)时,XMarkdown现在能够识别并允许通过自定义组件进行匹配和渲染,从而提供更好的用户体验,避免显示破碎的语法。
  • 新增 incompleteMarkdownComponentMap 配置项: 为 streaming 属性新增了 incompleteMarkdownComponentMap 配置项,用户可以指定自定义组件来替代流式渲染中未闭合的链接和图片,例如显示加载骨架屏。
  • 优化 useStreaming Hook 逻辑: 重构了 useStreaming Hook,引入了 StreamBuffer 接口和 handleTokenProcessing 函数,以更精细地管理流式状态和处理不完整的Markdown语法。同时,增加了当输入内容完全改变时重置流式状态的逻辑。
  • 默认缓存 Setext headings: 为避免在流式渲染过程中Setext标题(如Title ---)出现格式突变,现在默认会缓存此类标题,以确保渲染的稳定性。
  • 更新和新增文档: 新增了关于流式语法处理和动画效果的详细文档页面(streaming-syntaxstreaming-animation),并更新了相关示例,以清晰地展示新功能的使用方法和最佳实践。
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.

Copy link

cloudflare-workers-and-pages bot commented Sep 29, 2025

Deploying ant-design-x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2b9a27e
Status: ✅  Deploy successful!
Preview URL: https://964732a0.ant-design-x.pages.dev
Branch Preview URL: https://feature-markdown-format.ant-design-x.pages.dev

View logs

Copy link

@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 语法,以改善流式渲染的用户体验。整体实现思路清晰,通过状态机和 token 缓冲来处理流式数据,并增加了替换不完整语法的能力。代码重构和测试用例的补充都非常出色,特别是新增了大量针对边缘场景的测试,大大提高了代码的健壮性。

我发现了一些可以改进的地方,主要集中在 useStreaming.ts hook 中,包括一个正则表达式的潜在 bug 和一处为了可读性可以优化的逻辑。此外,文档的更新和重构做得很好,使得新功能更容易理解和使用。

Comment on lines +88 to +89
.replace(/!\[([^\]]*?)\](?!\([^)]*\)$)(?![^[]*\]\([^)]*\))$/, finalComponentMap.image)
.replace(/\[([^\]]*?)\](?!\([^)]*\)$)(?![^[]*\]\([^)]*\))$/, finalComponentMap.link)

Choose a reason for hiding this comment

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

high

这里的正则表达式 (?![^[]*]\\[([^)]*\\]))$/ 存在一些问题,可能会导致对某些 Markdown 语法的错误处理。

  1. 逻辑混乱: [^[]* 限制了 [ 字符的出现,这对于处理嵌套括号的链接文本来说过于严格。
  2. 潜在 Bug: 这个正则表达式无法正确处理引用式链接(reference-style links)。例如,对于 ![alt][ref] 这样的语法,它会被错误地识别为不完整的图片并被替换,因为 [ref] 不会匹配 [^[]*]\\[([^)]*\\]),导致负向先行断言成功。

建议简化和修正这个正则表达式,以更准确地处理链接和图片的边界情况。例如,可以分别检查是否跟着 (...)[...]

Suggested change
.replace(/!\[([^\]]*?)\](?!\([^)]*\)$)(?![^[]*\]\([^)]*\))$/, finalComponentMap.image)
.replace(/\[([^\]]*?)\](?!\([^)]*\)$)(?![^[]*\]\([^)]*\))$/, finalComponentMap.link)
.replace(/!\[([^\]]*?)\](?!\([^\]]*?\)$)(?!\[[^\]]*?\]$)$/, finalComponentMap.image)
.replace(/\[([^\]]*?)\](?!\([^\]]*?\)$)(?!\[[^\]]*?\]$)$/, finalComponentMap.link)

Comment on lines 171 to 199
popToken();
if (emphasisCount === 1) {
/**
* _token_ / *token*
* ^ ^
*/
pushToken(TokenType.Emphasis);
} else if (emphasisCount === 2) {
/**
* __token__ / **token**
* ^ ^
*/
pushToken(TokenType.Strong);
} else if (emphasisCount === 3) {
/**
* ___token___ / ***token***
* ^ ^
*/
pushToken(TokenType.Emphasis);
pushToken(TokenType.Strong);
} else {
// no more than 3
buffer.emphasisCount = 0;

switch (emphasisCount) {
case 1:
/**
* _token_ / *token*
* ^ ^
*/
pushToken(TokenType.Emphasis);
break;
case 2:
/**
* __token__ / **token**
* ^ ^
*/
pushToken(TokenType.Strong);
break;
case 3:
/**
* ___token___ / ***token***
* ^ ^
*/
pushToken(TokenType.Emphasis);
pushToken(TokenType.Strong);
break;
default:
buffer.emphasisCount = 0;
}
}

Choose a reason for hiding this comment

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

medium

MaybeEmphasis token 的处理逻辑中,switch (emphasisCount) 使用的是在 handleTokenProcessing 函数开头解构的 emphasisCount 值。虽然在当前逻辑下它能正确工作,但这种写法有些微妙且难以理解:emphasisCount 的值在 case 内部通过 buffer.emphasisCount++ 被修改,但 switch 语句却使用了修改前的值。

为了提高代码的可读性和可维护性,建议在 else 块内创建一个新变量来保存当前的 emphasisCount,这样意图会更清晰。

            const currentEmphasisCount = buffer.emphasisCount;
            popToken();

            switch (currentEmphasisCount) {
              case 1:
                /**
                 * _token_ / *token*
                 * ^         ^
                 */
                pushToken(TokenType.Emphasis);
                break;
              case 2:
                /**
                 * __token__ / **token**
                 *  ^           ^
                 */
                pushToken(TokenType.Strong);
                break;
              case 3:
                /**
                 * ___token___ / ***token***
                 *   ^             ^
                 */
                pushToken(TokenType.Emphasis);
                pushToken(TokenType.Strong);
                break;
              default:
                buffer.emphasisCount = 0;
            }
          }

Copy link

codecov bot commented Sep 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.57%. Comparing base (4e35f49) to head (2b9a27e).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #1223      +/-   ##
==========================================
- Coverage   94.61%   94.57%   -0.04%     
==========================================
  Files         131      131              
  Lines        3455     3431      -24     
  Branches      954      948       -6     
==========================================
- Hits         3269     3245      -24     
  Misses        184      184              
  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.

Copy link
Contributor

github-actions bot commented Sep 29, 2025

size-limit report 📦

Path Size
packages/x/dist/antdx.min.js 66 KB
packages/x-sdk/dist/x-sdk.min.js 7.2 KB
packages/x-markdown/dist/x-markdown.min.js 43.46 KB (+19 B 🔺)
packages/x-markdown/dist/plugins/code-high-light.min.js 277.65 KB
packages/x-markdown/dist/plugins/latex.min.js 62.01 KB
packages/x-markdown/dist/plugins/mermaid.min.js 849.55 KB

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request lgtm This PR has been approved by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants