Skip to content

Commit d0ad154

Browse files
📝 docs: rebuild site with docs-kit
Replace the Vite site/ package with a @lobehub/docs-kit (lobedocs) site: docs.config.ts, a building-landing-home landing page, guide pages and component pages for Streamdown and the profiler with live demos. The playground and profiler panels move into src/**/demos. build:site now writes dist/, and wrangler.jsonc and public/ move to the repo root.
1 parent d37fd9b commit d0ad154

64 files changed

Lines changed: 6337 additions & 2227 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ node_modules
44
# build output
55
es
66
dist
7-
site/dist
7+
8+
# docs
9+
.react-router
810

911
# ci
1012
coverage

‎docs.config.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// @lobehub/docs-kit has no stable export for `defineDocsConfig` (it is an identity function),
2+
// so this exports a plain object. Restart `lobedocs dev` after editing.
3+
export default {
4+
alias: {
5+
"@lobehub/streamdown": "src",
6+
},
7+
atomDirs: [{ dir: "src" }],
8+
description:
9+
"Headless streaming markdown engine for React with block caching, smooth per-character reveal and a LaTeX guard.",
10+
favicons: {
11+
appleTouchIcon: "/apple-touch-icon.png",
12+
icon: "/favicon.svg",
13+
icon16: "/favicon.svg",
14+
icon32: "/favicon.svg",
15+
},
16+
homePage: "./docs/home/home.tsx",
17+
publicDocs: [
18+
"docs/guide/getting-started.mdx",
19+
"docs/guide/streaming.mdx",
20+
"docs/guide/smooth-reveal.mdx",
21+
"docs/guide/animation.mdx",
22+
"docs/guide/code-fences.mdx",
23+
"docs/guide/latex.mdx",
24+
"docs/guide/remend.mdx",
25+
],
26+
siteUrl: "https://streamdown.lobehub.com",
27+
themeConfig: {
28+
apiHeader: {
29+
docUrl: "{github}/edit/main/{atomId}",
30+
github: "https://github.com/lobehub/streamdown",
31+
packageName: "@lobehub/streamdown",
32+
sourceUrl: "{github}/tree/main/{atomId}",
33+
},
34+
metadata: {
35+
openGraph: {
36+
image: "https://streamdown.lobehub.com/og.png",
37+
},
38+
},
39+
navItems: [
40+
{
41+
href: "/guide/getting-started",
42+
icon: "rocket",
43+
label: "Getting Started",
44+
},
45+
{ href: "/guide/streaming", icon: "blocks", label: "Streaming & Blocks" },
46+
{
47+
href: "/guide/smooth-reveal",
48+
icon: "activity",
49+
label: "Smooth Reveal",
50+
},
51+
{ href: "/guide/animation", icon: "sparkles", label: "Animation" },
52+
{ href: "/guide/code-fences", icon: "code", label: "Code Fences" },
53+
{ href: "/guide/latex", icon: "sigma", label: "LaTeX" },
54+
{ href: "/guide/remend", icon: "wand-sparkles", label: "remend" },
55+
],
56+
prefersColor: "auto",
57+
socialLinks: [
58+
{
59+
href: "https://github.com/lobehub/streamdown",
60+
icon: "github",
61+
label: "GitHub",
62+
},
63+
{
64+
href: "https://discord.gg/AYFPHvv2jT",
65+
icon: "discord",
66+
label: "Discord",
67+
},
68+
{
69+
href: "https://www.npmjs.com/package/@lobehub/streamdown",
70+
icon: "npm",
71+
label: "NPM",
72+
},
73+
],
74+
},
75+
title: "Streamdown",
76+
};

‎docs/changelog.mdx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Changelog
3+
description: New updates and improvements to @lobehub/streamdown
4+
---
5+
6+
import Changelog from "../CHANGELOG.md";
7+
8+
<Changelog />

‎docs/guide/animation.mdx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Animation
3+
description: How Streamdown fades in newly revealed text per character or per word with CSS, and how to style or disable the fade.
4+
---
5+
6+
import Animation from "../../src/Streamdown/demos/Animation.tsx?demo";
7+
8+
## Per-character fade
9+
10+
The `rehypeStreamAnimated` plugin wraps newly revealed text so it fades in. Each character gets a staggered `animation-delay`, chained after the previous one, so fades never race out of order and React does not need to re-render every frame. A cap on how far the fade queue can run ahead of "now" prevents a stream faster than the fade from piling up seconds of invisible backlog.
11+
12+
<Demo
13+
of={Animation}
14+
title="char vs. word granularity"
15+
layout="bare"
16+
editable={false}
17+
/>
18+
19+
## granularity
20+
21+
`granularity="char"` (default) fades each character; `granularity="word"` fades whole words together.
22+
23+
## Styles
24+
25+
Streamdown injects its fade keyframes with a React 19 `<style href precedence>` element, which React hoists and dedupes into `<head>`, so it is SSR-safe. The animated wrapper carries `STREAMDOWN_ANIMATED_CLASS` (`'streamdown-animated'`), and the fade lasts `STREAM_FADE_DURATION` (180ms). KaTeX display math is excluded from the fade.
26+
27+
Under `prefers-reduced-motion: reduce`, block-level fades are turned off.

‎docs/guide/code-fences.mdx‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: Code Fences
3+
description: Render open and closed code fences while streaming, plug in your own highlighter and diagrams, and detect an open fence with findOpenFenceLanguage.
4+
---
5+
6+
import CodeFence from "../../src/Streamdown/demos/CodeFence.tsx?demo";
7+
8+
## Open fences
9+
10+
An unterminated fence is completed on the open tail, so it renders as a code block from its first line. Code blocks skip the per-character fade and reveal as a block; prose resumes the fade after the fence.
11+
12+
<Demo
13+
of={CodeFence}
14+
title="Streaming a code fence and a diagram"
15+
layout="bare"
16+
editable={false}
17+
/>
18+
19+
## Highlighting with components
20+
21+
Streamdown renders a plain `<pre><code class="language-…">`. Replace `pre` through `components` to highlight it. Highlighting and diagram rendering cost far more than a reveal commit, so the demo above keeps a block as plain text until its source has held still for 180ms, then upgrades it to Lobe UI's `Highlighter` or `Mermaid`.
22+
23+
```tsx
24+
import { Streamdown } from "@lobehub/streamdown";
25+
import { Highlighter } from "@lobehub/ui";
26+
import {
27+
Children,
28+
type ComponentPropsWithoutRef,
29+
isValidElement,
30+
type ReactElement,
31+
} from "react";
32+
33+
const Pre = ({ children, ...rest }: ComponentPropsWithoutRef<"pre">) => {
34+
const code = Children.toArray(children).find(isValidElement) as
35+
ReactElement<{ children?: string; className?: string }> | undefined;
36+
const language = /language-([\w-]+)/.exec(code?.props.className ?? "")?.[1];
37+
if (!language) return <pre {...rest}>{children}</pre>;
38+
return (
39+
<Highlighter language={language}>
40+
{String(code?.props.children ?? "")}
41+
</Highlighter>
42+
);
43+
};
44+
45+
<Streamdown components={{ pre: Pre }} content={content} />;
46+
```
47+
48+
## findOpenFenceLanguage
49+
50+
`findOpenFenceLanguage(content)` returns the language of the last unclosed fence, `''` for a fence without a language, or `null` when every fence is closed. It looks for three backticks at the start of a line; tildes and indented fences are not detected.
51+
52+
The smoother uses it to bypass its buffer for some languages: while the input ends inside an open `html` fence, every chunk is shown immediately so a live HTML preview sees partial HTML at the real production rate. Smoothing resumes as soon as the fence closes.

‎docs/guide/getting-started.mdx‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Getting Started
3+
description: Install @lobehub/streamdown, render a streaming message, add math and code highlighting, and style the output yourself.
4+
---
5+
6+
import Basic from "../../src/Streamdown/demos/index.tsx?demo";
7+
8+
## Installation
9+
10+
```bash
11+
pnpm add @lobehub/streamdown
12+
```
13+
14+
The package is ESM only. `react` and `react-dom` `^19` are peer dependencies. It ships a `'use client'` boundary, so it renders from React Server Component frameworks without extra wiring.
15+
16+
## Render a stream
17+
18+
Pass the markdown received so far as `content` and re-render as chunks arrive. There is nothing to reset between chunks: Streamdown keeps finished blocks cached and only re-lexes the open tail.
19+
20+
```tsx
21+
import { Streamdown } from "@lobehub/streamdown";
22+
23+
export const Message = ({ content }: { content: string }) => (
24+
<Streamdown content={content} />
25+
);
26+
```
27+
28+
<Demo of={Basic} title="A simulated stream" />
29+
30+
## Add math and GFM
31+
32+
Plugins are passed through to react-markdown. When you render math, enable `latexGuard` so a half-arrived formula keeps the previous frame instead of flashing raw source.
33+
34+
```tsx
35+
import { Streamdown } from "@lobehub/streamdown";
36+
import rehypeKatex from "rehype-katex";
37+
import remarkGfm from "remark-gfm";
38+
import remarkMath from "remark-math";
39+
import "katex/dist/katex.min.css";
40+
41+
export const Message = ({ content }: { content: string }) => (
42+
<Streamdown
43+
content={content}
44+
latexGuard
45+
rehypePlugins={[rehypeKatex]}
46+
remarkPlugins={[remarkGfm, remarkMath]}
47+
/>
48+
);
49+
```
50+
51+
## Style the output
52+
53+
Streamdown is headless: no stylesheet, no component dependencies. The rendered tree is plain markdown HTML plus fade animation classes (`STREAMDOWN_ANIMATED_CLASS`, `STREAM_FADE_DURATION`); the fade keyframes are injected for you. Wrap it in your own typography, and swap elements through `components`, for example a code highlighter for `pre` (see [Code Fences](/guide/code-fences)).
54+
55+
## Next steps
56+
57+
- [Streaming & Blocks](/guide/streaming): how content is split and cached
58+
- [Smooth Reveal](/guide/smooth-reveal): the `smoothing` presets
59+
- [Animation](/guide/animation): per-character or per-word fades
60+
- [LaTeX](/guide/latex): `latexGuard` and the preprocessing helpers
61+
- [remend](/guide/remend): completing unclosed markdown on the open tail
62+
- [Streamdown API](/components/streamdown#api) and the [Playground](/components/streamdown#playground)
63+
- [Streamdown Profiler](/components/profiler): measuring commit cost

‎docs/guide/latex.mdx‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: LaTeX
3+
description: Render math while it streams with remark-math and rehype-katex, hold incomplete formulas with latexGuard, and clean model output with preprocessLaTeX.
4+
---
5+
6+
import Latex from "../../src/Streamdown/demos/Latex.tsx?demo";
7+
8+
## Setup
9+
10+
Math rendering comes from your plugins. Add `remark-math` and `rehype-katex`, load KaTeX's CSS, and enable `latexGuard`.
11+
12+
```tsx
13+
import { preprocessLaTeX, Streamdown } from "@lobehub/streamdown";
14+
import rehypeKatex from "rehype-katex";
15+
import remarkMath from "remark-math";
16+
import "katex/dist/katex.min.css";
17+
18+
<Streamdown
19+
content={content}
20+
latexGuard
21+
preprocess={preprocessLaTeX}
22+
rehypePlugins={[rehypeKatex]}
23+
remarkPlugins={[remarkMath]}
24+
/>;
25+
```
26+
27+
<Demo
28+
of={Latex}
29+
title="Toggle the guard and the preprocessor"
30+
layout="bare"
31+
editable={false}
32+
/>
33+
34+
## latexGuard
35+
36+
With `latexGuard`, Streamdown holds the previous frame while the trailing formula is still incomplete, so a half-streamed `$$…` block never flashes raw source or a KaTeX parse error. It uses `isLastFormulaRenderable(text)`, which finds the trailing formula still waiting for its closing delimiter (skipping code spans and fences) and checks whether KaTeX can already render it.
37+
38+
## preprocessLaTeX
39+
40+
Models emit math in shapes remark-math does not parse. Pass `preprocessLaTeX` as `preprocess` to normalize the text before rendering. By default it:
41+
42+
- escapes currency dollars such as `$20` or `$1,000`
43+
- converts `\[…\]` to `$$…$$` and `\(…\)` to `$…$`
44+
- escapes mhchem commands, pipes inside formulas (so tables do not split), and underscores inside `\text{}`
45+
46+
Code blocks are protected throughout. Optional steps are enabled through the second argument:
47+
48+
| Option | Default | Effect |
49+
| ------------------------ | ------- | ----------------------------------------------------------- |
50+
| `escapeCurrency` | `true` | Escape currency dollar signs |
51+
| `convertBrackets` | `true` | Convert bracket delimiters to dollar delimiters |
52+
| `escapeMhchem` | `true` | Escape mhchem commands |
53+
| `escapePipes` | `true` | Escape `\|` inside formulas |
54+
| `escapeUnderscores` | `true` | Escape underscores in `\text{}` |
55+
| `fixErrors` | `false` | Balance unmatched braces and `\left` / `\right` |
56+
| `normalizeSpacing` | `false` | Normalize whitespace in formulas |
57+
| `handleCJK` | `false` | Handle CJK characters next to formulas |
58+
| `addCJKSpaces` | `false` | Add spaces between CJK text and formulas (with `handleCJK`) |
59+
| `validate` | `false` | Validate every formula |
60+
| `throwOnValidationError` | `false` | Throw when validation fails (with `validate`) |
61+
62+
`preprocessLaTeXMinimal` and `preprocessLaTeXStrict` are exported as well, together with the individual steps: `escapeCurrencyDollars`, `convertLatexDelimiters`, `escapeMhchemCommands`, `escapeLatexPipes`, `escapeTextUnderscores`, `fixCommonLaTeXErrors`, `normalizeLatexSpacing`, `handleCJKWithLatex` and `validateLatexExpressions`.

‎docs/guide/remend.mdx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: remend
3+
description: How Streamdown completes unclosed markdown on the open tail block with remend, so partial emphasis, links and code never show as raw syntax.
4+
---
5+
6+
import Remend from "../../src/Streamdown/demos/Remend.tsx?demo";
7+
8+
## Completing the tail
9+
10+
Mid-stream, markdown is almost always unbalanced. Before the open tail block is lexed, Streamdown runs it through [remend](https://github.com/vercel/streamdown), which completes unclosed markers such as emphasis, inline code, links and strikethrough. Only the tail is processed; frozen blocks are already complete.
11+
12+
<Demo
13+
of={Remend}
14+
title="Raw stream vs. rendered output"
15+
layout="bare"
16+
editable={false}
17+
/>
18+
19+
## Options
20+
21+
Pass remend options through the `remend` prop. For example, use `{ htmlTags: false }` when `<` in your content is prose or math rather than HTML:
22+
23+
```tsx
24+
<Streamdown content={content} remend={{ htmlTags: false }} />
25+
```
26+
27+
The same options are applied by the smoother (`useSmoothStreamContent`) and the block lexer, so both see the same completed tail.

‎docs/guide/smooth-reveal.mdx‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Smooth Reveal
3+
description: The smoothing presets that turn bursty LLM chunks into a steady per-character reveal, and the useSmoothStreamContent hook behind them.
4+
---
5+
6+
import Smoothing from "../../src/Streamdown/demos/Smoothing.tsx?demo";
7+
8+
## Why smooth
9+
10+
Upstream chunks arrive in bursts. Rendering each chunk as it lands makes text jump forward a sentence at a time. Streamdown buffers the incoming text and reveals it at an adaptive characters-per-second rate: faster when the buffer grows, draining the remainder once input goes quiet.
11+
12+
## Presets
13+
14+
`smoothing` picks one of three presets; the default is `balanced`.
15+
16+
| Preset | Target buffer | Min commit interval |
17+
| ---------- | ------------- | ------------------- |
18+
| `realtime` | 40ms | 32ms |
19+
| `balanced` | 120ms | 48ms |
20+
| `silky` | 170ms | 56ms |
21+
22+
`realtime` keeps the smallest buffer for the lowest latency; `silky` holds the longest buffer for the steadiest flow. The same bursty stream feeds all three panes below.
23+
24+
<Demo
25+
of={Smoothing}
26+
title="One stream, three presets"
27+
layout="bare"
28+
editable={false}
29+
/>
30+
31+
## useSmoothStreamContent
32+
33+
The pacing is available as a hook for custom renderers:
34+
35+
```tsx
36+
import { useSmoothStreamContent } from "@lobehub/streamdown";
37+
38+
const visible = useSmoothStreamContent(content, { preset: "balanced" });
39+
```
40+
41+
Options are `enabled` (default `true`), `preset` (default `'balanced'`), `remend` (options for the remend pass on the open tail) and `tailUnitsRef`, through which the component reports the real length of the tail block.

0 commit comments

Comments
 (0)