Skip to content

Commit a760c79

Browse files
📝 docs: restructure site storytelling
1 parent 9bb3a75 commit a760c79

21 files changed

Lines changed: 324 additions & 387 deletions

‎AGENTS.md‎

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ on `react-markdown`, `marked` and `remend`. It has two entries, `@lobehub/stream
1212
`@lobehub/docs-kit` (the `lobedocs` CLI) from `docs/` and the `index.mdx` files under `src/`.
1313
Single pnpm package, Node >= 22.22 for the docs site.
1414

15-
| Path | What lives there |
16-
| ----------------------------------------------------------- | ------------------------------------------------------------------------------------- |
17-
| `src/index.ts` | Main entry; every public export is listed here |
18-
| `src/Streamdown.tsx` | The component and `StreamdownProps`; wires lexer, queue, smoother and rehype plugins |
19-
| `src/types.ts` | Shared public unions (`StreamSmoothingPreset`, `StreamAnimationGranularity`) |
20-
| `src/blockLexer.ts` | Block splitting with `marked`, frozen prefix, `remend` on the open tail |
21-
| `src/useStreamQueue.ts` | Block states (`revealed` / `animating` / `streaming` / `queued`) and char delay |
22-
| `src/useSmoothStreamContent.ts` | Reveal pacing; `PRESET_CONFIG` holds the `realtime` / `balanced` / `silky` presets |
23-
| `src/rehypeStreamAnimated.ts`, `src/streamAnimationMeta.ts` | Rehype plugin that wraps newly revealed text, and per-block animation timing |
24-
| `src/styles.tsx` | Fade keyframes, `STREAM_FADE_DURATION`, `STREAMDOWN_ANIMATED_CLASS` |
25-
| `src/CachedMarkdown.tsx`, `src/StreamTail.tsx` | Memoized per-block renderer; streaming tail element |
26-
| `src/latex.ts`, `src/fenceState.ts` | LaTeX preprocessing / `isLastFormulaRenderable`; `findOpenFenceLanguage` |
27-
| `src/internal.ts` | Shared internal helpers; never exported from an entry |
28-
| `src/profiler/` | The `./profiler` entry (`index.ts`, `profiler.ts`, `StreamdownProfilerProvider.tsx`) |
29-
| `src/Streamdown/`, `src/profiler/index.mdx` | Docs only: component pages and `demos/` (not part of the published build) |
30-
| `docs/`, `docs.config.ts` | Guide pages (`docs/guide/*.mdx`), landing page (`docs/home/`), changelog, site config |
31-
| `public/`, `wrangler.jsonc` | Static assets for the site; Cloudflare Pages config (`dist/`) |
15+
| Path | What lives there |
16+
| ----------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
17+
| `src/index.ts` | Main entry; every public export is listed here |
18+
| `src/Streamdown.tsx` | The component and `StreamdownProps`; wires lexer, queue, smoother and rehype plugins |
19+
| `src/types.ts` | Shared public unions (`StreamSmoothingPreset`, `StreamAnimationGranularity`) |
20+
| `src/blockLexer.ts` | Block splitting with `marked`, frozen prefix, `remend` on the open tail |
21+
| `src/useStreamQueue.ts` | Block states (`revealed` / `animating` / `streaming` / `queued`) and char delay |
22+
| `src/useSmoothStreamContent.ts` | Reveal pacing; `PRESET_CONFIG` holds the `realtime` / `balanced` / `silky` presets |
23+
| `src/rehypeStreamAnimated.ts`, `src/streamAnimationMeta.ts` | Rehype plugin that wraps newly revealed text, and per-block animation timing |
24+
| `src/styles.tsx` | Fade keyframes, `STREAM_FADE_DURATION`, `STREAMDOWN_ANIMATED_CLASS` |
25+
| `src/CachedMarkdown.tsx`, `src/StreamTail.tsx` | Memoized per-block renderer; streaming tail element |
26+
| `src/latex.ts`, `src/fenceState.ts` | LaTeX preprocessing / `isLastFormulaRenderable`; `findOpenFenceLanguage` |
27+
| `src/internal.ts` | Shared internal helpers; never exported from an entry |
28+
| `src/profiler/` | The `./profiler` entry (`index.ts`, `profiler.ts`, `StreamdownProfilerProvider.tsx`) |
29+
| `src/Streamdown/`, `src/profiler/index.mdx` | Docs only: component pages and `demos/` (not part of the published build) |
30+
| `docs/`, `docs.config.ts` | Guide pages (`docs/{guide,features,content}/*.mdx`), landing page (`docs/home/`), site config |
31+
| `public/`, `wrangler.jsonc` | Static assets for the site; Cloudflare Pages config (`dist/`) |
3232

3333
## Using Skills
3434

@@ -52,8 +52,13 @@ by hand.
5252
- **Component pages**: only files named `index.mdx` under `src` (`atomDirs`) become pages; the URL
5353
comes from the folder: `src/Streamdown/index.mdx` → `/components/streamdown`,
5454
`src/profiler/index.mdx` → `/components/profiler`.
55-
- **Guide pages**: `docs/guide/<name>.mdx` with `title` + `description`, listed in `publicDocs` and
56-
`themeConfig.navItems` in `docs.config.ts`. They are served at `/guide/<name>`.
55+
- **Guide pages**: `docs/<group>/<name>.mdx` with `title`, `description` and `order`, listed in
56+
`publicDocs` in `docs.config.ts` and served at `/<group>/<name>`. The folder picks the sidebar
57+
group through `themeConfig.sidebarGroups`: `docs/guide` (Get Started: introduction, getting
58+
started, usage), `docs/features` (Streaming: what happens to each chunk) and `docs/content`
59+
(Rich Content: code, math, components and plugins); the `src` group puts component pages under
60+
API Reference, after the guides. Open each page with a short paragraph that
61+
states the problem before the first heading, then show the API.
5762
- **Frontmatter**: `title`, `description` (one or two plain sentences; feeds search and llms.txt),
5863
`category` on component pages (`General`), optional `order`. A PascalCase `title` makes the page
5964
header show `import { Title } from '@lobehub/streamdown'`, which is why the profiler page is
@@ -68,7 +73,7 @@ by hand.
6873
- **API tables**: `<Api name="Streamdown" />` and `<Api name="StreamdownProfilerProvider" />` read
6974
props from TypeScript. JSDoc on props becomes the description, and a JSDoc `@default` must equal
7075
the runtime default in the destructuring or the build fails.
71-
- **Links**: use site pathnames (`/guide/latex`, `/components/streamdown#api`); the build audits
76+
- **Links**: use site pathnames (`/content/latex`, `/components/streamdown#api`); the build audits
7277
every internal link and `#hash`.
7378
- **Preview and check**: `pnpm dev`, then `pnpm build:site`, which runs every docs audit. Restart
7479
the dev server after editing `docs.config.ts`.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Read https://streamdown.lobehub.com/skills.md, then use @lobehub/streamdown to r
158158
## 📖 Documentation
159159

160160
- **Docs and playground**: [streamdown.lobehub.com][website-link]
161+
- **Introduction**: [streamdown.lobehub.com/guide/introduction](https://streamdown.lobehub.com/guide/introduction)
161162
- **Getting started**: [streamdown.lobehub.com/guide/getting-started](https://streamdown.lobehub.com/guide/getting-started)
162163
- **API**: [streamdown.lobehub.com/components/streamdown](https://streamdown.lobehub.com/components/streamdown)
163164
- **Changelog**: [CHANGELOG.md](./CHANGELOG.md)

‎docs.config.ts‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
},
77
atomDirs: [{ dir: "src" }],
88
description:
9-
"Headless streaming markdown engine for React with block caching, smooth per-character reveal and a LaTeX guard.",
9+
"A headless React renderer for LLM markdown: caches finished blocks, reveals text smoothly, completes half-typed syntax.",
1010
favicons: {
1111
appleTouchIcon: "/apple-touch-icon.png",
1212
icon: "/favicon.svg",
@@ -15,13 +15,16 @@ export default {
1515
},
1616
homePage: "./docs/home/home.tsx",
1717
publicDocs: [
18+
"docs/guide/introduction.mdx",
1819
"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",
20+
"docs/guide/usage.mdx",
21+
"docs/features/incomplete-markdown.mdx",
22+
"docs/features/blocks.mdx",
23+
"docs/features/smooth-reveal.mdx",
24+
"docs/features/animation.mdx",
25+
"docs/content/code-fences.mdx",
26+
"docs/content/latex.mdx",
27+
"docs/content/components.mdx",
2528
],
2629
siteUrl: "https://streamdown.lobehub.com",
2730
themeConfig: {
@@ -36,24 +39,17 @@ export default {
3639
image: "https://streamdown.lobehub.com/og.png",
3740
},
3841
},
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-
],
5642
prefersColor: "auto",
43+
// Sidebar order tells the story: why → how to start → streaming features → rich content,
44+
// then the API pages.
45+
sidebarGroups: [
46+
{ dir: "docs/guide", icon: "rocket", order: -3, title: "Get Started" },
47+
{ dir: "docs/features", icon: "activity", order: -2, title: "Streaming" },
48+
{ dir: "docs/content", icon: "shapes", order: -1, title: "Rich Content" },
49+
// Without a group, src/ pages land in the built-in "Components" section, which docs-kit
50+
// always pins to the top of the sidebar.
51+
{ dir: "src", icon: "code", order: 0, title: "API Reference" },
52+
],
5753
socialLinks: [
5854
{
5955
href: "https://github.com/lobehub/streamdown",
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
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.
3+
description: Render open and closed code fences while streaming, plug in your own highlighter and diagrams, and detect an open fence.
4+
order: 0
45
---
56

67
import CodeFence from "../../src/Streamdown/demos/CodeFence.tsx?demo";
78

9+
Code is where streaming hurts most: an unclosed fence can turn the rest of an answer into raw backticks. Streamdown renders an open fence as a code block from its first line, and leaves highlighting and diagrams to the components you plug in.
10+
811
## Open fences
912

1013
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.

‎docs/content/components.mdx‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Components & Plugins
3+
description: Style Streamdown's headless output, swap elements through react-markdown components, and add GFM, math, highlighting or diagrams with plugins.
4+
order: 2
5+
---
6+
7+
Streamdown renders plain markdown HTML and stops there. Styling, syntax highlighting, diagrams and math all come from what you pass in, the same way you would extend react-markdown.
8+
9+
## Override elements
10+
11+
`components` is react-markdown's: map a tag name to your own React component, which receives the same props react-markdown would pass.
12+
13+
```tsx
14+
import { Streamdown } from "@lobehub/streamdown";
15+
import type { Components } from "react-markdown";
16+
17+
const components: Components = {
18+
a: ({ node, ...props }) => <a {...props} rel="noreferrer" target="_blank" />,
19+
};
20+
21+
<Streamdown components={components} content={content} />;
22+
```
23+
24+
## Add capabilities
25+
26+
Nothing below is bundled. Each row is something you add yourself, and how this site does it:
27+
28+
| Capability | How to add it | On this site |
29+
| ------------------------------------------------ | ---------------------------------------------------------------- | -------------------------------------------------------------- |
30+
| GFM tables, task lists, strikethrough, autolinks | `remark-gfm` in `remarkPlugins` | `remark-gfm` |
31+
| Math | `remark-math` + `rehype-katex`, KaTeX CSS and `latexGuard` | See [LaTeX](/content/latex) |
32+
| Syntax highlighting | A highlighter rendered from `components.pre` | Lobe UI `Highlighter`, see [Code Fences](/content/code-fences) |
33+
| Mermaid diagrams | Render `language-mermaid` code with a diagram component in `pre` | Lobe UI `Mermaid`, see [Code Fences](/content/code-fences) |
34+
| Typography | Wrap the output in your own prose styles | Lobe UI `Typography` |
35+
36+
## Plugins see one block at a time
37+
38+
Each top-level block is parsed by its own processor, so remark and rehype plugins receive one block, not the whole document. Plugins that work inside a block (GFM, math, highlighting) behave as usual. Plugins that link across blocks leave the reference literal: GFM footnotes, reference-style links and reference-style images. While a block is still animating, Streamdown appends its own `rehypeStreamAnimated` to your rehype plugins for that block.
39+
40+
## Styling
41+
42+
Streamdown ships no stylesheet. The only CSS it adds is the fade keyframes, injected through a React 19 `<style>` element. Animated text is wrapped in an element with `STREAMDOWN_ANIMATED_CLASS` (`'streamdown-animated'`) and fades over `STREAM_FADE_DURATION` (180ms); target that class to adjust it. See [Animation](/features/animation) for details.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
22
title: LaTeX
33
description: Render math while it streams with remark-math and rehype-katex, hold incomplete formulas with latexGuard, and clean model output with preprocessLaTeX.
4+
order: 1
45
---
56

67
import Latex from "../../src/Streamdown/demos/Latex.tsx?demo";
78

9+
Until its closing `$$` arrives, a streaming formula is either raw TeX or a KaTeX error. Streamdown renders math through the plugins you add, holds incomplete formulas with `latexGuard`, and normalizes the delimiters models actually emit with `preprocessLaTeX`.
10+
811
## Setup
912

1013
Math rendering comes from your plugins. Add `remark-math` and `rehype-katex`, load KaTeX's CSS, and enable `latexGuard`.
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
---
22
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.
3+
description: How Streamdown fades newly revealed text in per character or per word with CSS, and how to style or disable it.
4+
order: 3
45
---
56

67
import Animation from "../../src/Streamdown/demos/Animation.tsx?demo";
78

8-
## Per-character fade
9+
Even at a steady pace, text that pops into existence reads as flicker. Streamdown fades newly revealed characters or words in with CSS, chained so fades never run out of order, without re-rendering React every frame.
10+
11+
## How it works
912

1013
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.
1114

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
---
2-
title: Streaming & Blocks
3-
description: How Streamdown splits streaming markdown into top-level blocks, freezes the finished ones and re-renders only the open tail.
2+
title: Block Memoization
3+
description: How Streamdown splits streaming markdown into top-level blocks, freezes finished ones and re-renders only the open tail.
4+
order: 1
45
---
56

67
import Streaming from "../../src/Streamdown/demos/Streaming.tsx?demo";
78

9+
Re-rendering a whole message for every token gets slower as the answer grows. Streamdown splits the content into top-level blocks and re-parses only the one still being written, so the cost of a commit tracks the open tail, not the length of the message.
10+
811
## Block splitting
912

1013
Every commit, Streamdown lexes the content into top-level blocks with `marked`: paragraphs, headings, lists, tables, code fences, block quotes. Each block is rendered by its own memoized `CachedMarkdown`, so a block whose text did not change is not re-rendered.
1114

1215
## Frozen prefix
1316

14-
Paragraphs, headings, code fences, tables, block quotes and thematic breaks can never grow again once a blank line follows them. Tokens up to such a boundary are frozen and reused; only the text after it is completed by [remend](/guide/remend) and lexed again. Lists and indented code are not frozen, because `- a` + blank line + `- b` merges back into one list.
17+
Paragraphs, headings, code fences, tables, block quotes and thematic breaks can never grow again once a blank line follows them. Tokens up to such a boundary are frozen and reused; only the text after it is completed by [remend](/features/incomplete-markdown) and lexed again. Lists and indented code are not frozen, because `- a` + blank line + `- b` merges back into one list.
1518

16-
The result: the cost of a commit tracks the open tail, not the whole message. Change the upstream chunk size below and compare root and block commit cost.
19+
Change the upstream chunk size below and compare root and block commit cost.
1720

1821
<Demo
1922
of={Streaming}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Incomplete Markdown
3+
description: How Streamdown completes unclosed markdown on the open tail with remend, so partial emphasis, links and code render formatted.
4+
order: 0
5+
---
6+
7+
import Remend from "../../src/Streamdown/demos/Remend.tsx?demo";
8+
9+
Mid-stream, markdown is almost never balanced: a bold run is opened but not closed, a link has its text but not yet its URL. Streamdown completes the open tail block before rendering it, so readers see formatting from the first character instead of raw markers that snap into place later.
10+
11+
## How it works
12+
13+
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: blocks before it are already complete and [frozen](/features/blocks). Open code fences render as code blocks from their first line, see [Code Fences](/content/code-fences).
14+
15+
<Demo
16+
of={Remend}
17+
title="Raw stream vs. rendered output"
18+
layout="bare"
19+
editable={false}
20+
/>
21+
22+
## Options
23+
24+
Pass remend options through the `remend` prop. For example, use `{ htmlTags: false }` when `<` in your content is prose or math rather than HTML:
25+
26+
```tsx
27+
<Streamdown content={content} remend={{ htmlTags: false }} />
28+
```
29+
30+
The same options are applied by the smoother (`useSmoothStreamContent`) and the block lexer, so both see the same completed tail.

0 commit comments

Comments
 (0)