You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a760c79
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,7 @@ Read https://streamdown.lobehub.com/skills.md, then use @lobehub/streamdown to r
158
158
## 📖 Documentation
159
159
160
160
-**Docs and playground**: [streamdown.lobehub.com][website-link]
Copy file name to clipboardExpand all lines: docs/content/code-fences.mdx
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,13 @@
1
1
---
2
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.
3
+
description: Render open and closed code fences while streaming, plug in your own highlighter and diagrams, and detect an open fence.
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
+
8
11
## Open fences
9
12
10
13
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.
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.
| 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.
Copy file name to clipboardExpand all lines: docs/content/latex.mdx
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,13 @@
1
1
---
2
2
title: LaTeX
3
3
description: Render math while it streams with remark-math and rehype-katex, hold incomplete formulas with latexGuard, and clean model output with preprocessLaTeX.
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
+
8
11
## Setup
9
12
10
13
Math rendering comes from your plugins. Add `remark-math` and `rehype-katex`, load KaTeX's CSS, and enable `latexGuard`.
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
9
12
10
13
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.
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
+
8
11
## Block splitting
9
12
10
13
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.
11
14
12
15
## Frozen prefix
13
16
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.
15
18
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.
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:
0 commit comments