Markstream Migration
Overview
Replace an existing Markdown renderer without silently dropping transforms, custom components, URL policy, raw-HTML behavior, or streaming semantics. Read references/adoption-checklist.md first.
When to Use
Use when replacing react-markdown, markdown-it, marked, or another renderer; migrating node renderers; or choosing between Markstream content, smooth streaming, and nodes.
Workflow
Before changing dependencies or source files, inspect the existing package manager and project conventions, preview the intended edits, and obtain explicit user approval.
- Inventory renderer imports, call sites, plugins, HTML policy, URL transforms, allowlists, custom renderers, CSS, and tests.
- Classify the migration as direct, renderer-custom, plugin-heavy, or security-heavy.
- Install the framework package and explicit CSS. Preserve visible behavior before optional features.
- Map built-ins to scoped overrides; in React prefer renderer-local component maps.
- Use trusted custom tags only for trusted content and reserve parse transforms for irreducible token/AST requirements.
- Keep
content with smooth streaming for ordinary token streams. Use nodes only for worker parsing, shared AST ownership, or structural transforms.
- Preserve safe HTML and strict Mermaid defaults; scope and document any trusted legacy exception.
- Run relevant builds and behavior tests. Report mappings, intentional differences, and unresolved review.
Example
// Before:
// import ReactMarkdown from 'react-markdown'
// return <ReactMarkdown>{markdown}</ReactMarkdown>
import MarkdownRender from 'markstream-react'
import 'markstream-react/index.css'
export function AssistantAnswer({
markdown,
isDone,
}: {
markdown: string
isDone: boolean
}) {
return (
<MarkdownRender
content={markdown}
final={isDone}
fade={isDone}
typewriter={!isDone}
smoothStreaming={isDone ? false : 'auto'}
htmlPolicy="safe"
/>
)
}
Limitations
- Markstream cannot reproduce every remark, rehype, or markdown-it plugin automatically.
- Visual parity does not prove security or URL-policy parity.
- Large migrations may require staged conversion.
Security & Safety Notes
Do not weaken sanitization for screenshot parity. Review dependencies, raw HTML, URL transforms, and trust boundaries explicitly.
1---2name: markstream-migration3description: Audit and migrate an existing Markdown renderer to Markstream while preserving custom renderers, security policy, streaming behavior, and explicit parity gaps.4license: MIT5---67# Markstream Migration89## Overview1011Replace an existing Markdown renderer without silently dropping transforms, custom components, URL policy, raw-HTML behavior, or streaming semantics. Read [references/adoption-checklist.md](references/adoption-checklist.md) first.1213## When to Use1415Use when replacing `react-markdown`, `markdown-it`, `marked`, or another renderer; migrating node renderers; or choosing between Markstream `content`, smooth streaming, and `nodes`.1617## Workflow1819Before changing dependencies or source files, inspect the existing package manager and project conventions, preview the intended edits, and obtain explicit user approval.20211. Inventory renderer imports, call sites, plugins, HTML policy, URL transforms, allowlists, custom renderers, CSS, and tests.222. Classify the migration as direct, renderer-custom, plugin-heavy, or security-heavy.233. Install the framework package and explicit CSS. Preserve visible behavior before optional features.244. Map built-ins to scoped overrides; in React prefer renderer-local component maps.255. Use trusted custom tags only for trusted content and reserve parse transforms for irreducible token/AST requirements.266. Keep `content` with smooth streaming for ordinary token streams. Use `nodes` only for worker parsing, shared AST ownership, or structural transforms.277. Preserve safe HTML and strict Mermaid defaults; scope and document any trusted legacy exception.288. Run relevant builds and behavior tests. Report mappings, intentional differences, and unresolved review.2930## Example3132```tsx33// Before:34// import ReactMarkdown from 'react-markdown'35// return <ReactMarkdown>{markdown}</ReactMarkdown>3637import MarkdownRender from 'markstream-react'38import 'markstream-react/index.css'3940export function AssistantAnswer({41 markdown,42 isDone,43}: {44 markdown: string45 isDone: boolean46}) {47 return (48 <MarkdownRender49 content={markdown}50 final={isDone}51 fade={isDone}52 typewriter={!isDone}53 smoothStreaming={isDone ? false : 'auto'}54 htmlPolicy="safe"55 />56 )57}58```5960## Limitations6162- Markstream cannot reproduce every remark, rehype, or markdown-it plugin automatically.63- Visual parity does not prove security or URL-policy parity.64- Large migrations may require staged conversion.6566## Security & Safety Notes6768Do not weaken sanitization for screenshot parity. Review dependencies, raw HTML, URL transforms, and trust boundaries explicitly.