Markdown
Streaming markdown for AI answers, block by block
Usage
Markdown is imported from its own subpath and needs four optional peers.
npm install marked react-markdown remark-gfm shikiimport {Markdown} from "@peakui-pro/react/markdown";Examples
Streaming
Pass the whole string on every update; only the block that grew re-renders.
Custom Components
components replaces the element for a tag; keep the object stable.
GFM
Images And Links
No image loads unless isImageAllowed allows it; live links show their destination.
In A Message
Customization
Tailwind CSS
<Markdown className="[--markdown-block-gap:1rem] [--markdown-font-size:1rem]">{answer}</Markdown>Global CSS
@layer components {
.markdown {
--markdown-link-color: var(--color-accent);
--markdown-line-height: 1.75;
}
}Styling Reference
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
CSS Classes
The Markdown component uses these CSS classes (view source styles):
Base Classes
.markdown- Root, a column of blocks
Element Classes
.markdown__block- One top-level block: a heading, paragraph, list, table, quote or fence.markdown__inline-code- Inline code.markdown__image- A loaded image, or an inert one's alt text and host.markdown__image-host- The host an inert image names.markdown__link-destination- The destination a live link shows.markdown__link-text- A refused link, as text
A fence renders a CodeBlock, with its .code-block classes. Elements inside a block are styled by tag through :where(), so any class you add wins.
Slots
[data-slot="markdown"][data-slot="markdown-block"][data-slot="markdown-inline-code"][data-slot="markdown-image"][data-slot="markdown-link-destination"][data-slot="markdown-link-text"]
CSS Variables
| Variable | Purpose |
|---|---|
--markdown-block-gap | Space between blocks; defaults to 0.75rem |
--markdown-font-size | Body text size; defaults to var(--text-sm) |
--markdown-line-height | Body line height; defaults to 1.65 |
--markdown-heading-color | Heading and table header colour; defaults to var(--color-foreground) |
--markdown-link-color | Link colour; defaults to var(--color-link) |
--markdown-inline-code-bg | Inline code background; defaults to var(--color-default) |
--markdown-quote-border | Quote rule colour; defaults to var(--color-border) |
--markdown-table-border | Table and rule line colour; defaults to var(--color-separator) |
Interactive States
- Focus:
:focus-visibleon a link draws the core focus ring - Inert image:
[data-inert="true"]on.markdown__imagewhen no image was fetched - Forced colors:
@media (forced-colors: active)paints links inLinkTextand outlines inline code
API Reference
Markdown
| Prop | Type | Default | Description |
|---|---|---|---|
children | string | '' | The markdown source. Raw HTML in it is shown as text, never parsed; javascript: URLs are removed |
isImageAllowed | (src: string) => boolean | - | Whether an image may be fetched. Without it no image loads: each renders as its alt text and host. Only an http(s) image with alt text can load |
isLinkAllowed | (href: string) => boolean | absolute http, https, mailto | Whether a link is live. A refused link renders as text; a live one shows its host (or address) and has its URL as title |
components | MarkdownComponents | - | Element overrides by tag name, merged over the defaults (pre renders a CodeBlock, code inline code, li names task checkboxes, img and a apply the two policies above). An override of img or a replaces its policy. A new object on every render re-renders every block |
id | string | generated | Seed of the blocks' keys, and the root's id |
className | string | - | Additional classes |
render | DOMRenderFunction<'div', undefined> | - | Replaces the rendered <div> with your own element |
...rest | Omit<ComponentProps<'div'>, 'children' | 'id'> | - | Native <div> attributes |