Skip to content

fix: 🧩 修复 md 渲染时会把 `` 格式渲染成代码块问题#281

Merged
xun082 merged 2 commits intomainfrom
fix/md_code_block
Feb 2, 2026
Merged

fix: 🧩 修复 md 渲染时会把 `` 格式渲染成代码块问题#281
xun082 merged 2 commits intomainfrom
fix/md_code_block

Conversation

@xun082
Copy link
Copy Markdown
Owner

@xun082 xun082 commented Feb 2, 2026

PR 描述

PR 类型

  • 🐛 Bug 修复
  • ✨ 新功能
  • 💄 UI/UX 改进
  • ♻️ 重构
  • 🚀 性能优化
  • 📝 文档更新
  • 🔄 其他

Issue 关联

Closes #

其他信息

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 2, 2026

Deploy Preview for PR #281 - SUCCESS!

🚀 Preview URL: https://pr-281--ornate-blancmange-89db6b.netlify.app
📅 Updated: 2026-02-02T07:09:34.248Z

This preview will be updated automatically when you push new commits.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

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

此拉取请求旨在解决 Markdown 渲染器中一个将行内代码错误识别为代码块的缺陷。通过引入一个集中式的 ReactMarkdown 组件配置,确保了 Markdown 内容(特别是代码片段)的正确和一致渲染。此外,本次变更还对 AI 功能(如 AI 续写和 AI 润色)的流式响应逻辑进行了重大重构,将其抽象为可复用的自定义 Hook,从而显著提升了相关组件的清晰度、可维护性和代码复用性。

Highlights

  • Markdown 渲染修复: 修复了 Markdown 渲染时将行内代码(``)错误渲染为代码块( )的问题,确保了行内代码的正确显示和样式。
  • 统一 ReactMarkdown 组件配置: 引入了统一的 ReactMarkdown 组件配置 (markdownComponentscompactMarkdownComponents),集中管理 Markdown 元素的渲染样式,提高了代码的可维护性和一致性。
  • AI 流式响应逻辑重构: 将 AI 相关的流式响应逻辑重构为可复用的 React Hook (useAIStream, useAIContinue, useAIPolish),简化了 AI 功能组件的代码,并提升了模块化程度。
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
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 PR significantly refactors the Markdown rendering logic and AI streaming response handling, extracting them into markdown-components.tsx and use-ai-stream.ts respectively. This greatly enhances code readability, maintainability, and reusability, while also fixing Markdown inline code rendering issues. However, a critical security vulnerability has been identified in the custom link components, which render user-supplied URLs directly into the href attribute of <a> tags without proper sanitization, making the application susceptible to Cross-Site Scripting (XSS) attacks via javascript: URIs. Remediation requires implementing a strict allow-list for URI protocols. Furthermore, there are suggestions for improving type safety and performance optimization, particularly within the newly created markdown-components.tsx and use-ai-stream.ts files.

Comment on lines +100 to +111
const stream = useAIStream({
onUpdate: (response) => {
const pos = getPos();

if (pos !== undefined) {
editor.commands.updateContinueContent(pos, response);
}
},
onComplete: (response) => {
updateAttributes({ state: 'display', response });
},
});
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

为了优化性能并遵循 React Hooks 的最佳实践,建议使用 useCallback 来记忆化传递给 useAIStreamonUpdateonComplete 回调函数。这可以防止它们在每次父组件渲染时都重新创建,从而避免 useAIStream hook 内部不必要的重渲染。

这个建议同时适用于 useAIContinueuseAIPolish 两个 Hook。

  const onUpdate = useCallback(
    (response: string) => {
      const pos = getPos();

      if (pos !== undefined) {
        editor.commands.updateContinueContent(pos, response);
      }
    },
    [editor, getPos],
  );

  const onComplete = useCallback(
    (response: string) => {
      updateAttributes({ state: 'display', response });
    },
    [updateAttributes],
  );

  const stream = useAIStream({
    onUpdate,
    onComplete,
  });

@xun082 xun082 merged commit a38b2c1 into main Feb 2, 2026
6 checks passed
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.

1 participant