streamdown
Implement, configure, and customize Streamdown ā a streaming-optimized React Markdown renderer with syntax highlighting, Mermaid diagrams, math rendering, and CJK support. Use when working with Streamdown setup, configuration, plugins, styling, security, or integration with AI streaming (e.g., Vercel AI SDK). Triggers on: (1) Installing or setting up Streamdown, (2) Configuring plugins (code, mermaid, math, cjk), (3) Styling or theming Streamdown output, (4) Integrating with AI chat/streaming, (5) Configuring security, link safety, or custom HTML tags, (6) Using carets, static mode, or custom components, (7) Troubleshooting Tailwind, Shiki, or Vite issues.
SKILL.md
| Name | streamdown |
| Description | Implement, configure, and customize Streamdown ā a streaming-optimized React Markdown renderer with syntax highlighting, Mermaid diagrams, math rendering, and CJK support. Use when working with Streamdown setup, configuration, plugins, styling, security, or integration with AI streaming (e.g., Vercel AI SDK). Triggers on: (1) Installing or setting up Streamdown, (2) Configuring plugins (code, mermaid, math, cjk), (3) Styling or theming Streamdown output, (4) Integrating with AI chat/streaming, (5) Configuring security, link safety, or custom HTML tags, (6) Using carets, static mode, or custom components, (7) Troubleshooting Tailwind, Shiki, or Vite issues. |
Streamdown
A drop-in replacement for react-markdown, designed for AI-powered streaming.
Overview
Formatting Markdown is easy, but when you tokenize and stream it, new challenges arise. Streamdown is built specifically to handle the unique requirements of streaming Markdown content from AI models, providing seamless formatting even with incomplete or unterminated Markdown blocks.
Streamdown powers the AI Elements Message component but can be installed as a standalone package for your own streaming needs.
Features
- š Drop-in replacement for
react-markdown - š Streaming-optimized - Handles incomplete Markdown gracefully
- šØ Unterminated block parsing - Build with
remendfor better streaming quality - š GitHub Flavored Markdown - Tables, task lists, and strikethrough support
- š¢ Math rendering - LaTeX equations via KaTeX
- š Mermaid diagrams - Render Mermaid diagrams as code blocks with a button to render them
- šÆ Code syntax highlighting - Beautiful code blocks with Shiki
- š”ļø Security-first - Built with
rehype-hardenfor safe rendering - ā” Performance optimized - Memoized rendering for efficient updates
Installation
npm i streamdown
Then, update your Tailwind globals.css to include the following so that Tailwind can detect the utility classes used by Streamdown.
@source "../node_modules/streamdown/dist/*.js";
The path must be relative from your CSS file to the node_modules folder containing streamdown. In a standard Next.js project where globals.css lives in app/, the default path above should work.
If you install optional Streamdown plugins, add their matching @source lines from the relevant plugin docs (/docs/plugins/code, /docs/plugins/cjk, /docs/plugins/math, /docs/plugins/mermaid). Only include plugin @source entries for packages that are actually installed.
Example:
@source "../node_modules/@streamdown/code/dist/*.js";
Monorepo setup
In a monorepo (npm workspaces, Turbo, pnpm, etc.), dependencies are typically hoisted to the root node_modules. You need to adjust the relative path to point there:
monorepo/
āāā node_modules/streamdown/ ā hoisted here
āāā apps/
ā āāā web/
ā āāā app/
ā āāā globals.css ā your CSS file
/* apps/web/app/globals.css ā 3 levels up to reach root node_modules */
@source "../../../node_modules/streamdown/dist/*.js";
Adjust the number of ../ segments based on where your CSS file lives relative to the root node_modules. If you install Streamdown plugins, add their respective @source entries only when those packages are installed.
Usage
Here's how you can use Streamdown in your React application with the AI SDK:
import { useChat } from "@ai-sdk/react";
import { Streamdown } from "streamdown";
import { code } from "@streamdown/code";
import { mermaid } from "@streamdown/mermaid";
import { math } from "@streamdown/math";
import { cjk } from "@streamdown/cjk";
import "katex/dist/katex.min.css";
import "streamdown/styles.css";
export default function Chat() {
const { messages, status } = useChat();
return (
<div>
{messages.map(message => (
<div key={message.id}>
{message.role === 'user' ? 'User: ' : 'AI: '}
{message.parts.map((part, index) =>
part.type === 'text' ? (
<Streamdown
key={index}
animated
plugins={{ code, mermaid, math, cjk }}
isAnimating={status === 'streaming'}
>
{part.text}
</Streamdown>
) : null,
)}
</div>
))}
</div>
);
}
For more info, see the documentation.