Streamdown

作者 vercel8edc64857a17無授權條款5.6K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

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.

AI 產生的概覽

指導 Streamdown 這個專為串流輸出設計的 React Markdown 渲染器的安裝、設定與自訂。

功能
此技能提供實作 Streamdown 的說明與參考資料,Streamdown 是專為串流輸出打造的 React Markdown 渲染器。內容涵蓋安裝、必要的 Tailwind CSS 設定、程式碼、Mermaid、數學公式與中日韓文字等外掛的設定、樣式、安全選項,以及與 AI 串流輸出函式庫的整合。技能也附上範例設定檔,以及 API、外掛、樣式、安全與功能方面的參考文件。
適用情境
在 React 專案中導入 Streamdown、設定其外掛或 Tailwind 掃描路徑、調整渲染樣式,或將其接上 AI 聊天介面時使用。也適合用來排查樣式遺失、數學公式未渲染、游標未顯示或 Shiki 警告等常見問題。
執行需求
需要 Node.js 與 npm 來安裝 streamdown 套件及選用外掛套件,還需要 Tailwind CSS 與 React。部分功能依賴額外套件或 CSS 匯入,例如數學公式需要 katex 的 CSS,程式碼高亮需要 shiki。技能不含指令碼,僅為說明與參考文件。

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

bash
npm install streamdown

Optional plugins (install only what's needed):

bash
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:

css
@source "../node_modules/streamdown/dist/*.js";

Add plugin @source lines only for packages you have installed (omitting uninstalled plugins avoids Tailwind errors). See plugin pages for exact paths:

  • Code: @source "../node_modules/@streamdown/code/dist/*.js";
  • CJK: @source "../node_modules/@streamdown/cjk/dist/*.js";
  • Math: @source "../node_modules/@streamdown/math/dist/*.js";
  • Mermaid: @source "../node_modules/@streamdown/mermaid/dist/*.js";

Tailwind v3 — add to tailwind.config.js:

js
module.exports = {  content: [    "./app/**/*.{js,ts,jsx,tsx,mdx}",    "./node_modules/streamdown/dist/*.js",  ],};

3. Basic Usage

tsx
import { Streamdown } from 'streamdown';
<Streamdown>{markdown}</Streamdown>

4. With AI Streaming (Vercel AI SDK)

tsx
'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)

tsx
<Streamdown mode="static" plugins={{ code }}>  {content}</Streamdown>

Key Props

PropTypeDefaultPurpose
childrenstring—Markdown content
mode"streaming" | "static""streaming"Rendering mode
plugins{ code?, mermaid?, math?, cjk? }—Feature plugins
isAnimatingbooleanfalseStreaming indicator
caret"block" | "circle"—Cursor style
componentsComponents—Custom element overrides
controlsboolean | objecttrueInteractive buttons; download: { filename } sets custom download names
linkSafetyLinkSafetyConfig{ enabled: true }Link confirmation modal
shikiTheme[light, dark]['github-light', 'github-dark']Code themes
classNamestring—Container class
allowedElementsstring[]allTag names to allow
disallowedElementsstring[][]Tag names to disallow
allowElementAllowElement—Custom element filter
unwrapDisallowedbooleanfalseKeep children of disallowed elements
skipHtmlbooleanfalseIgnore raw HTML
urlTransformUrlTransformdefaultUrlTransformTransform/sanitize URLs

For full API reference, see references/api.md [blocked].

Plugin Quick Reference

PluginPackagePurpose
Code@streamdown/codeSyntax highlighting (Shiki, 200+ languages)
Mermaid@streamdown/mermaidDiagrams (flowcharts, sequence, etc.)
Math@streamdown/mathLaTeX via KaTeX (requires CSS import)
CJK@streamdown/cjkChinese/Japanese/Korean text support

Math requires CSS:

tsx
import 'katex/dist/katex.min.css';

For plugin configuration details, see references/plugins.md [blocked].

References

Use these for deeper implementation details:

  • references/api.md [blocked] — Complete props, types, and interfaces
  • references/plugins.md [blocked] — Plugin setup, configuration, and customization
  • references/styling.md [blocked] — CSS variables, data attributes, custom components, theme examples
  • references/security.md [blocked] — Hardening, link safety, custom HTML tags, production config
  • references/features.md [blocked] — Carets, remend, static mode, controls, GFM, memoization, troubleshooting

Example Configurations

Copy and adapt from assets/examples/:

  • basic-streaming.tsx [blocked] — Minimal AI chat with Vercel AI SDK
  • with-caret.tsx [blocked] — Streaming with block caret cursor
  • full-featured.tsx [blocked] — All plugins, carets, link safety, controls
  • static-mode.tsx [blocked] — Blog/docs rendering
  • custom-security.tsx [blocked] — Strict security for AI content

Common Gotchas

  1. Tailwind styles missing — Add @source directive or content entry for node_modules/streamdown/dist/*.js
  2. Math not rendering — Import katex/dist/katex.min.css
  3. Caret not showing — Both caret prop AND isAnimating={true} are required
  4. Copy buttons during streaming — Disabled automatically when isAnimating={true}
  5. Link safety modal appearing — Enabled by default; disable with linkSafety={{ enabled: false }}
  6. Shiki warning in Next.js — Install shiki explicitly, add to transpilePackages
  7. allowedTags not working — Only works with default rehype plugins
  8. Math uses $$ not $ — Single dollar is disabled by default to avoid currency conflicts

來源與署名

來源:vercel/streamdown位於skills/streamdown提交8edc648

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架