streamdown
127
总安装量
128
周安装量
#1881
全站排名
安装命令
npx skills add https://github.com/vercel/streamdown --skill streamdown
Agent 安装分布
codex
123
opencode
122
gemini-cli
119
github-copilot
118
amp
102
kimi-cli
100
Skill 文档
Streamdown
Streaming-optimized React Markdown renderer. Drop-in replacement for react-markdown with built-in streaming support, security, and interactive controls.
Quick Setup
1. Install
npm install streamdown
Optional plugins (install only what’s needed):
npm install @streamdown/code @streamdown/mermaid @streamdown/math @streamdown/cjk
2. Configure Tailwind CSS (Required)
This is the most commonly missed step. Streamdown uses Tailwind for styling and the dist files must be scanned.
Tailwind v4 â add to globals.css:
@source "../node_modules/streamdown/dist/*.js";
Tailwind v3 â add to tailwind.config.js:
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/streamdown/dist/*.js",
],
};
3. Basic Usage
import { Streamdown } from 'streamdown';
<Streamdown>{markdown}</Streamdown>
4. With AI Streaming (Vercel AI SDK)
'use client';
import { useChat } from '@ai-sdk/react';
import { Streamdown } from 'streamdown';
import { code } from '@streamdown/code';
export default function Chat() {
const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat();
return (
<>
{messages.map((msg, i) => (
<Streamdown
key={msg.id}
plugins={{ code }}
caret="block"
isAnimating={isLoading && i === messages.length - 1 && msg.role === 'assistant'}
>
{msg.content}
</Streamdown>
))}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} disabled={isLoading} />
</form>
</>
);
}
5. Static Mode (Blogs, Docs)
<Streamdown mode="static" plugins={{ code }}>
{content}
</Streamdown>
Key Props
| Prop | Type | Default | Purpose |
|---|---|---|---|
children |
string |
â | Markdown content |
mode |
"streaming" | "static" |
"streaming" |
Rendering mode |
plugins |
{ code?, mermaid?, math?, cjk? } |
â | Feature plugins |
isAnimating |
boolean |
false |
Streaming indicator |
caret |
"block" | "circle" |
â | Cursor style |
components |
Components |
â | Custom element overrides |
controls |
boolean | object |
true |
Interactive buttons |
linkSafety |
LinkSafetyConfig |
{ enabled: true } |
Link confirmation modal |
shikiTheme |
[light, dark] |
['github-light', 'github-dark'] |
Code themes |
className |
string |
â | Container class |
allowedElements |
string[] |
all | Tag names to allow |
disallowedElements |
string[] |
[] |
Tag names to disallow |
allowElement |
AllowElement |
â | Custom element filter |
unwrapDisallowed |
boolean |
false |
Keep children of disallowed elements |
skipHtml |
boolean |
false |
Ignore raw HTML |
urlTransform |
UrlTransform |
defaultUrlTransform |
Transform/sanitize URLs |
For full API reference, see references/api.md.
Plugin Quick Reference
| Plugin | Package | Purpose |
|---|---|---|
| Code | @streamdown/code |
Syntax highlighting (Shiki, 200+ languages) |
| Mermaid | @streamdown/mermaid |
Diagrams (flowcharts, sequence, etc.) |
| Math | @streamdown/math |
LaTeX via KaTeX (requires CSS import) |
| CJK | @streamdown/cjk |
Chinese/Japanese/Korean text support |
Math requires CSS:
import 'katex/dist/katex.min.css';
For plugin configuration details, see references/plugins.md.
References
Use these for deeper implementation details:
- references/api.md â Complete props, types, and interfaces
- references/plugins.md â Plugin setup, configuration, and customization
- references/styling.md â CSS variables, data attributes, custom components, theme examples
- references/security.md â Hardening, link safety, custom HTML tags, production config
- references/features.md â Carets, remend, static mode, controls, GFM, memoization, troubleshooting
Example Configurations
Copy and adapt from assets/examples/:
- basic-streaming.tsx â Minimal AI chat with Vercel AI SDK
- with-caret.tsx â Streaming with block caret cursor
- full-featured.tsx â All plugins, carets, link safety, controls
- static-mode.tsx â Blog/docs rendering
- custom-security.tsx â Strict security for AI content
Common Gotchas
- Tailwind styles missing â Add
@sourcedirective orcontententry fornode_modules/streamdown/dist/*.js - Math not rendering â Import
katex/dist/katex.min.css - Caret not showing â Both
caretprop ANDisAnimating={true}are required - Copy buttons during streaming â Disabled automatically when
isAnimating={true} - Link safety modal appearing â Enabled by default; disable with
linkSafety={{ enabled: false }} - Shiki warning in Next.js â Install
shikiexplicitly, add totranspilePackages allowedTagsnot working â Only works with default rehype plugins- Math uses
$$not$â Single dollar is disabled by default to avoid currency conflicts