@gridui/markdown
v2.0.1
Published
GridUI React Markdown content with streaming updates
Readme
@gridui/markdown
Render Markdown content using the existing GridUI theme. Import Markdown from
@gridui/markdown; load @gridui/theme/styles.css before
@gridui/markdown/styles.css. Consumers do not need a styling compiler.
import "@gridui/theme/styles.css";
import "@gridui/markdown/styles.css";
import { Markdown, type MarkdownStatus } from "@gridui/markdown";
const status: MarkdownStatus = "streaming";
<Markdown status={status}>{responseText}</Markdown>;Styles
Load Theme once. Use @gridui/markdown/styled for automatic component CSS in
CSS-aware bundlers, or keep the CSS-free root import and load @gridui/markdown/styles.css.
Both entries expose the same root API. The standalone stylesheet includes component
dependency styles; Theme/reset remain separate. See the
integration guide
for static HTML loading, SSR limits, and avoiding duplicate CSS.
Streaming snapshots
Pass the complete current text snapshot as children, not the latest token delta.
The host decodes transport bytes, accumulates chunks, and supplies valid Unicode
text. Replacements, shorter snapshots, and resets are accepted; the renderer does
not append to hidden internal history.
| status | Presentation |
| --- | --- |
| pending | Waiting for content; busy without inventing placeholder text |
| streaming | Busy, with presentation-only completion of unfinished syntax |
| complete | Ordinary Markdown rendering of the exact supplied source |
| interrupted | Retain partial formatting; no longer busy |
| error | Retain partial formatting; no longer busy |
status defaults to complete. aria-busy reflects
pending/streaming, and data-state exposes the resolved state. There is no
per-token live region, animation queue, timer, or automatic scrolling. Render
localized completion/error messages and retry controls outside the content.
While streaming, interrupted, or failed, remend completes partial emphasis and inline code for display. Unfinished links render as noninteractive text; unfinished images show alternative text without loading a partial URL. Existing CommonMark parsing handles open fenced code. GFM tables appear once the received source contains a valid header and separator; the renderer does not invent table columns or missing cell values. Other GFM features include task lists, strikethrough, and autolinks. Math rendering is not enabled.
Completion is a display heuristic, not a reconstruction of missing source.
Stopping a response should use interrupted, not complete: literal unmatched
syntax may reappear when a snapshot is finalized as ordinary Markdown. The
caller retains the original source for persistence and Markdown copying. Native
selection copies the rendered text. Custom renderers receive the presentation
AST, whose positions may differ from the original partial source.
Identical content inputs reuse the rendered document across parent/status updates.
Changed snapshots still parse as a whole, preserving cross-block references;
this is not an incremental Markdown parser. Keep components and citations
references stable when unchanged, and batch high-frequency updates in the host.
There is no artificial typing delay. Long-running transport and completion
announcements remain application responsibilities.
Content and Grid ownership
The root adds no outer padding, border, background, heading, or controls. Grid
owns region spacing and structural seams. Markdown owns document typography,
list indentation, quotes, code surfaces and table cell borders. Native div props,
className, inline styles and a div ref are forwarded. Content inherits the
nearest Theme palette. Compose FollowScroll around a bounded reading region;
readers who scroll away should be able to inspect earlier content.
Content boundary and citations
Raw HTML is skipped. URLs pass through react-markdown's safe default transform;
there is no raw-HTML or unsafe URL-transform escape hatch. components can
replace semantic renderers, including code, links and images. Those trusted
renderers own their output and accessibility; never inject untrusted HTML.
Images use the supplied URLs, so the application owns remote-media policy.
Use [1](#citation:guide) with
citations={[{ id: "guide", title: "Guide", href: "https://example.com" }]}
to resolve application-supplied citations. IDs must be nonempty and unique.
Unknown citations, incomplete destinations and rejected URLs render without an
active link. A custom link renderer can compose the application's existing
citation presentation. Changed citation metadata and custom renderers are applied
even when the text snapshot is unchanged.
Compose messages with native article/heading elements and @gridui/follow-scroll.
Keep author identity, timestamps, message actions, retries and persistence in the
application. The Streaming story steps through deterministic snapshots; the
Grid reader
adds burst delivery, interruption, failure and long-response playback.
See release history.
Component reference contains focused API pages for each public component.
