PeakUIPro

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 shiki
import {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

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

VariablePurpose
--markdown-block-gapSpace between blocks; defaults to 0.75rem
--markdown-font-sizeBody text size; defaults to var(--text-sm)
--markdown-line-heightBody line height; defaults to 1.65
--markdown-heading-colorHeading and table header colour; defaults to var(--color-foreground)
--markdown-link-colorLink colour; defaults to var(--color-link)
--markdown-inline-code-bgInline code background; defaults to var(--color-default)
--markdown-quote-borderQuote rule colour; defaults to var(--color-border)
--markdown-table-borderTable and rule line colour; defaults to var(--color-separator)

Interactive States

  • Focus: :focus-visible on a link draws the core focus ring
  • Inert image: [data-inert="true"] on .markdown__image when no image was fetched
  • Forced colors: @media (forced-colors: active) paints links in LinkText and outlines inline code

API Reference

Markdown

PropTypeDefaultDescription
childrenstring''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) => booleanabsolute http, https, mailtoWhether a link is live. A refused link renders as text; a live one shows its host (or address) and has its URL as title
componentsMarkdownComponents-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
idstringgeneratedSeed of the blocks' keys, and the root's id
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div> with your own element
...restOmit<ComponentProps<'div'>, 'children' | 'id'>-Native <div> attributes

On this page