Docs menu

Guides


Primitives
Forms
Layout
Feedback
Overlays
Navigation
Data Display
AI

Streaming Markdown

Markdown from a model, rendered as real elements — <p>,<ol>, <table>,<blockquote>, and Kernel'sCode Block for fences — while it is still arriving. Finished blocks never re-render, and half-written syntax never flashes on screen as raw asterisks and pipes.

Playground

Type Markdown into content, and toggle streaming to see how unfinished syntax is read.

Try bold, code, a link (opens in new tab) or an unclosed fence of thought

Unstyled

Same component — Kernel look stripped. See Platforms.

streaming
animate
Usage
<StreamingMarkdown
  content={"Try **bold**, `code`, a [link](https://example.com) or an unclosed **fence of thought"}
  streaming
/>

Props

Props for StreamingMarkdown. Also accepts every native <div> attribute except children, content.
PropTypeDefaultNotes
contentstringRequiredThe Markdown so far. Append to it as chunks arrive.
streamingbooleanfalseText is still arriving: unfinished constructs (an open fence, an unclosed **, half a link or table row) render as their finished form would, instead of as raw syntax.
animatebooleantrueFade newly arrived words in while streaming. Off under reduced motion whatever this says. Default true.
componentsStreamingMarkdownComponents——
classNameClassNameValue<StreamingMarkdownState>—A class string, or a function of the component's state that returns one.
labelsPartial<StreamingMarkdownLabels>—Override built-in strings (e.g. for translation); unset keys keep their English default.

Web Components

Attributes and events of the Custom Elements in @kernelui-lib/elements.
TagAttributesEvents
<kernel-streaming-markdown>content, streaming, no-animate, label-opens-in-new-tab—

Stable streaming

The top level is split into blocks, and each block remembers the exact source slice it came from. Blocks are keyed by index and memoised on that slice, so a new chunk re-renders only the last block: earlier paragraphs, tables and code blocks keep their DOM nodes, their layout and the reader's text selection. Inside the live block, each word is its own span, also keyed by index, so words already on screen stay put and only the new ones mount — which is what the optional fade-in (animate) keys off. The fade is a short opacity and blur settle on the motion tokens, and it is off under reduced motion.

While streaming is true, unfinished constructs render as their finished form would:

  • an unterminated fence is an open code block, following its last line;
  • **bold with no closer yet is bold so far, and a marker with nothing after it yet is hidden;
  • [text](https://exa shows text and hides the half-written destination;
  • a table renders as soon as its header row arrives, and a half row is a row;
  • a last line that is only the start of a marker (-, #, >) is held back until it means something.

In the elements package, assign el.content as chunks arrive. Unchanged blocks are left alone and the last one is patched in place, element by element and text node by text node — React's index-keyed reconciliation in miniature.

What it parses

A compact, dependency-free subset of CommonMark plus GitHub's tables: paragraphs, ATX headings, emphasis, strong, strikethrough, inline code, fenced code, nested ordered and unordered lists, blockquotes, links, autolinks (<https://…> and bare URLs) and horizontal rules. Deliberately left out: raw HTML (always text), indented code blocks, setext headings, reference-style links, footnotes and task-list checkboxes. parseMarkdown is exported from both packages if you want the tree itself.

Safety

  • The parser produces data, never an HTML string, and the renderer builds elements from it — so model text can only ever become text. A<script> or <img onerror> in the content renders as those characters.
  • Links keep only http:, https:,mailto: and relative destinations, with control characters stripped before the scheme is read. An unsafe link renders as its text. External links open in a new tab withrel="noopener noreferrer".
  • Images render as a link to the image and are never loaded. An image URL written by a model is a known way to leak a conversation to a third-party server the moment it renders.

Overriding elements

components replaces any element by tag — each override gets the props the default would have had, so spread them to keep Kernel's styling. codeBlock replaces the fence renderer, which is where a highlighter plugs in. Pass a stable object: a new one every render re-renders every block.

const components = {
  a: (props) => <a {...props} onClick={trackClick} />,
  codeBlock: ({ code, language, streaming }) => (
    <CodeBlock lines={highlight(code, language)} language={language} streaming={streaming} />
  ),
};

<StreamingMarkdown content={text} streaming={!done} components={components} />

Accessibility

  • It is deliberately not a live region. A container that announces every appended token reads a stream back word by word, or re-reads the whole answer. Announcing belongs to the transcript:Message Scroller isrole="log" with polite announcements, and this component sets aria-busy while streaming so assistive tech can hold its updates and read the finished text once.
  • Headings, lists and tables are the real elements, so screen-reader rotors and table navigation work.
  • A table wider than the message scrolls inside a focusable wrapper, so it is reachable by keyboard.
  • Links that open a new tab say so, in a visually hidden suffix you can translate through labels.