markdown
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseassistant-ui Markdown
assistant-ui Markdown
Always consult assistant-ui.com/llms.txt for the latest API.
Render and customize assistant message text as markdown with from , wired into the text branch.
MarkdownTextPrimitive@assistant-ui/react-markdownMessagePrimitive.Parts请始终查阅assistant-ui.com/llms.txt获取最新API。
使用@assistant-ui/react-markdown中的,将助手消息文本渲染并自定义为Markdown格式,需将其接入的文本分支。
MarkdownTextPrimitiveMessagePrimitive.PartsReferences
参考资料
- ./references/markdown-text.md -- MarkdownTextPrimitive setup
- ./references/syntax-highlighting.md -- code highlighting (react-shiki / react-syntax-highlighter)
- ./references/latex-mermaid.md -- LaTeX and Mermaid
- ./references/streamdown.md -- StreamdownTextPrimitive alternative
- ./references/markdown-text.md -- MarkdownTextPrimitive 配置指南
- ./references/syntax-highlighting.md -- 代码高亮(react-shiki / react-syntax-highlighter)
- ./references/latex-mermaid.md -- LaTeX与Mermaid图表
- ./references/streamdown.md -- StreamdownTextPrimitive 替代方案
Orientation
入门指南
MarkdownTextPrimitivenpx assistant-ui@latest add markdown-textcomponents/assistant-ui/markdown-text.tsxMarkdownTextdefaultComponentsunstable_memoizeMarkdownComponentsMarkdownTexttextMessagePrimitive.Partstsx
import "@assistant-ui/react-markdown/styles/dot.css";
import { MarkdownTextPrimitive } from "@assistant-ui/react-markdown";
import { MessagePrimitive } from "@assistant-ui/react";
import remarkGfm from "remark-gfm";
import { memo } from "react";
const MarkdownTextImpl = () => (
<MarkdownTextPrimitive
remarkPlugins={[remarkGfm]}
className="aui-md"
components={defaultComponents}
/>
);
export const MarkdownText = memo(MarkdownTextImpl);
<MessagePrimitive.Parts>
{({ part }) => (part.type === "text" ? <MarkdownText /> : null)}
</MessagePrimitive.Parts>;Add highlighting, math, or diagrams by extending the same primitive: for KaTeX, for a per-language (Mermaid, diff), and to normalize raw text before parsing. See the references for each. For a batteries-included alternative with built-in Shiki, KaTeX, Mermaid, and block streaming, swap in from .
rehypePluginscomponentsByLanguageSyntaxHighlighterpreprocessStreamdownTextPrimitive@assistant-ui/react-streamdownMarkdownTextPrimitivenpx assistant-ui@latest add markdown-textcomponents/assistant-ui/markdown-text.tsxMarkdownTextunstable_memoizeMarkdownComponentsdefaultComponentsMessagePrimitive.PartstextMarkdownTexttsx
import "@assistant-ui/react-markdown/styles/dot.css";
import { MarkdownTextPrimitive } from "@assistant-ui/react-markdown";
import { MessagePrimitive } from "@assistant-ui/react";
import remarkGfm from "remark-gfm";
import { memo } from "react";
const MarkdownTextImpl = () => (
<MarkdownTextPrimitive
remarkPlugins={[remarkGfm]}
className="aui-md"
components={defaultComponents}
/>
);
export const MarkdownText = memo(MarkdownTextImpl);
<MessagePrimitive.Parts>
{({ part }) => (part.type === "text" ? <MarkdownText /> : null)}
</MessagePrimitive.Parts>;通过扩展同一个primitive添加高亮、数学公式或图表功能:使用实现KaTeX渲染,通过为每种语言注册(Mermaid、diff),以及使用在解析前规范化原始文本。具体请查看各参考资料。如需开箱即用的替代方案(内置Shiki、KaTeX、Mermaid和块流式处理),可替换为@assistant-ui/react-streamdown中的。
rehypePluginscomponentsByLanguageSyntaxHighlighterpreprocessStreamdownTextPrimitiveCommon Gotchas
常见问题
- Nothing renders / plain text shows. The branch must return
text; returningMarkdownTextbypasses markdown entirely.<p>{part.text}</p> - No syntax highlighting. Highlighting is not bundled. Register a in
SyntaxHighlighter(react-shiki recommended) per the syntax-highlighting reference.defaultComponents - KaTeX has no styling. Import once at the app root;
katex/dist/katex.min.cssonly emits markup.rehypeKatex - Mermaid parses partial diagrams while streaming. Gate rendering on stream completion (the reference uses to detect the closing fence) instead of rendering every delta.
useAuiState - Memoization export name. The package exports ; the generated file aliases it to
unstable_memoizeMarkdownComponents.memoizeMarkdownComponents - Unstyled by default. The class and
aui-mdprovide base styling; add your own Tailwind/CSS otherwise.styles/dot.css
- 无内容渲染 / 仅显示纯文本:分支必须返回
text;若返回MarkdownText则会完全跳过Markdown解析。<p>{part.text}</p> - 无语法高亮:高亮功能未捆绑在内。需按照语法高亮参考资料,在中注册
defaultComponents(推荐使用react-shiki)。SyntaxHighlighter - KaTeX无样式:需在应用根目录导入一次;
katex/dist/katex.min.css仅生成标记内容。rehypeKatex - 流式传输时Mermaid解析不完整的图表:需在流完成后再渲染(参考资料中使用检测闭合标记),而非渲染每个增量内容。
useAuiState - 缓存函数导出名称:该包导出的是;生成的文件将其别名为
unstable_memoizeMarkdownComponents。memoizeMarkdownComponents - 默认无样式:类和
aui-md提供基础样式;否则需自行添加Tailwind/CSS样式。styles/dot.css
Related Skills
相关技能
- primitives -- general UI composition (,
ThreadPrimitive,ComposerPrimitive) for assembling the message and the rest of the chat surface around the markdown text branch.MessagePrimitive.Parts
- primitives -- 通用UI组合(、
ThreadPrimitive、ComposerPrimitive),用于在Markdown文本分支周围组装消息及聊天界面的其他部分。MessagePrimitive.Parts