Rendu markdown avec assistant-ui

VérifiéSûr

Rendre et personnaliser le texte des messages comme markdown dans assistant-ui, avec coloration syntaxique, mathématiques LaTeX et diagrammes Mermaid.

Spar Skills Guide Bot
DeveloppementIntermédiaire
0029/08/2026
Claude CodeCursorWindsurfCopilotCodex
#markdown#assistant-ui#react#streaming#syntax-highlighting

Recommandé pour

Notre avis

Compétence pour rendre les messages de l'assistant en markdown dans assistant-ui via MarkdownTextPrimitive, avec support de la coloration syntaxique, des mathématiques KaTeX, des diagrammes Mermaid et du streaming, en configurant plugins et composants mémoïsés.

Points forts

  • Fournit une configuration complète pour le rendu markdown dans assistant-ui, y compris le code, LaTeX et Mermaid.
  • Couvre à la fois MarkdownTextPrimitive et StreamdownTextPrimitive, offrant une alternative clé en main avec streaming par blocs.
  • Inclut des pièges courants pratiques pour résoudre les problèmes de rendu, de styles et de streaming partiel.

Limites

  • Nécessite des dépendances et configurations supplémentaires pour la coloration syntaxique et les maths ; rien n'est inclus par défaut.
  • Certaines API sont marquées comme instables (ex. unstable_memoizeMarkdownComponents) et peuvent évoluer.
  • La compétence est spécifique à assistant-ui et React, non applicable à d'autres frameworks.
Quand l'utiliser

Utilisez-la lorsque vous construisez une interface de chat assistant en React et que vous devez afficher la sortie du modèle comme markdown formaté avec code, formules ou diagrammes.

Quand l'éviter

Ne l'utilisez pas si vous avez besoin d'un rendu markdown agnostique au framework ou si votre projet n'est pas basé sur assistant-ui.

Analyse de sécurité

Sûr
Score qualité92/100

The skill provides documentation and code examples for rendering markdown in assistant-ui. It does not instruct destructive, exfiltrating, or obfuscated actions. No tools are declared, and the content is purely educational/instructional for UI configuration.

Aucun point d'attention détecté

Exemples

Set up markdown rendering
Wire up MarkdownTextPrimitive in my assistant-ui app so that model responses render as markdown with GitHub-flavored markdown (remark-gfm) and syntax highlighting using react-shiki.
Add LaTeX and Mermaid support
Configure my assistant-ui markdown component to render LaTeX math with KaTeX and Mermaid diagrams, but gate the Mermaid rendering on stream completion to avoid partial diagram errors.
Fix plain text showing instead of markdown
In my assistant-ui chat, the text parts show as raw plain text instead of formatted markdown. Why? Show me the correct MessagePrimitive.Parts wiring and how to use MarkdownTextPrimitive.

name: markdown description: "Render and customize assistant message text as markdown in assistant-ui. Use when displaying model output as formatted markdown with MarkdownTextPrimitive from @assistant-ui/react-markdown wired into the MessagePrimitive.Parts text branch, configuring remarkPlugins (remark-gfm, remark-math) and rehypePlugins (rehype-katex), or memoizing components with unstable_memoizeMarkdownComponents. Covers code-block syntax highlighting via react-shiki or react-syntax-highlighter registered as SyntaxHighlighter in components/componentsByLanguage, LaTeX math rendering with KaTeX, Mermaid diagrams gated on stream completion, custom math delimiters via preprocess, and the StreamdownTextPrimitive alternative from @assistant-ui/react-streamdown with built-in Shiki/KaTeX/Mermaid and block streaming. For general chat UI composition route to primitives." license: MIT

assistant-ui Markdown

Always consult assistant-ui.com/llms.txt for the latest API.

Render and customize assistant message text as markdown with MarkdownTextPrimitive from @assistant-ui/react-markdown, wired into the MessagePrimitive.Parts text branch.

References

Orientation

MarkdownTextPrimitive renders one text part as markdown. The registry component (npx assistant-ui@latest add markdown-text) generates components/assistant-ui/markdown-text.tsx, which exports a memoized MarkdownText built on the primitive plus a defaultComponents map from unstable_memoizeMarkdownComponents. Render MarkdownText from the text branch of MessagePrimitive.Parts.

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: rehypePlugins for KaTeX, componentsByLanguage for a per-language SyntaxHighlighter (Mermaid, diff), and preprocess 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 StreamdownTextPrimitive from @assistant-ui/react-streamdown.

Common Gotchas

  • Nothing renders / plain text shows. The text branch must return MarkdownText; returning <p>{part.text}</p> bypasses markdown entirely.
  • No syntax highlighting. Highlighting is not bundled. Register a SyntaxHighlighter in defaultComponents (react-shiki recommended) per the syntax-highlighting reference.
  • KaTeX has no styling. Import katex/dist/katex.min.css once at the app root; rehypeKatex only emits markup.
  • Mermaid parses partial diagrams while streaming. Gate rendering on stream completion (the reference uses useAuiState to detect the closing fence) instead of rendering every delta.
  • Memoization export name. The package exports unstable_memoizeMarkdownComponents; the generated file aliases it to memoizeMarkdownComponents.
  • Unstyled by default. The aui-md class and styles/dot.css provide base styling; add your own Tailwind/CSS otherwise.

Related Skills

  • primitives -- general UI composition (ThreadPrimitive, ComposerPrimitive, MessagePrimitive.Parts) for assembling the message and the rest of the chat surface around the markdown text branch.
Skills similaires