# Markdown A streaming-safe markdown renderer. Every node is a semantic element inside a shadcn/typeset container, so the typography comes from typeset, and the append-only cache re-parses only the open block while the source grows. ## Installation ```bash npx shadcn@latest add litingyes/blocove/markdown ``` > Typography requires [shadcn/typeset](https://ui.shadcn.com/docs/typeset). Copy `typeset.css` next to your main stylesheet, import it after Tailwind and add the `.typeset-docs` preset. This example also uses: `markdown-code-block`, `markdown-math`. ```bash npx shadcn@latest add litingyes/blocove/markdown-code-block litingyes/blocove/markdown-math ``` Every node is a plain semantic element inside a `.typeset typeset-docs` container, so a document looks exactly like the rich text editor and no second stylesheet has to be kept in sync. Streaming is the default behaviour, not a second mode: while `source` grows, the parse cache keeps every block that already ended and re-parses only the open one, so finished elements keep their DOM, a completed fence is not tokenized again, and a half-written marker stays literal until its closing token arrives. Raw HTML is escaped, and only `http`, `https`, `mailto`, `tel`, fragment and relative targets become anchors. Fence renderers register through `components.fences` keyed by lowercase language and fall back to `code`; they receive `complete` when the closing fence has arrived or the source is final, so a diagram renders on the closing line even when the answer ends without a trailing newline. A fence with no registered renderer keeps its source. ## Usage ### Install typeset ```bash curl -o src/typeset.css https://ui.shadcn.com/typeset.css ``` ### Typeset setup ```css /* src/styles.css */ @import "tailwindcss"; @import "./typeset.css"; @import "@fontsource-variable/inter"; @import "@fontsource-variable/jetbrains-mono"; .typeset-docs { --typeset-font-body: var(--font-inter); --typeset-font-heading: var(--font-inter); --typeset-font-mono: var(--font-jetbrains-mono); --typeset-size: 16px; --typeset-leading: 1.75; --typeset-flow: 1.25em; } ``` ## API Reference ### Markdown The streaming-safe renderer. `source` is the whole document; growing the string token by token is the case the shell is built for. The layout element carries `data-slot="markdown"`; the typeset element deliberately does not, because typeset skips the descendants of a `data-slot` element. | Prop | Type | Default | | --- | --- | --- | | `source` | `string` | `Required` | | `streaming` | `boolean` | `false` | | `typeset` | `boolean` | `true` | | `components` | `MarkdownComponents` | - | | `className` | `string` | - | | `contentClassName` | `string` | - | ### MarkdownComponents Capability map of the shell. A node with no registered renderer keeps its literal source — a fence falls back to `
` and math stays `$…$` — so the optional items compose without the shell knowing them. Fence renderers are keyed by lowercase language and fall back to `code`; a fence renderer receives `complete` when the closing fence has arrived or the source is final.

| Prop | Type | Default |
| --- | --- | --- |
| `code` | `ComponentType` | - |
| `math` | `ComponentType` | - |
| `fences` | `Record>` | - |

## Registry dependencies

- `litingyes/blocove/markdown-parse`

Namespace: `npx shadcn@latest add @blocove/markdown`