HextaUI

Markdown rendering for AI answers. Handles streaming without half-typed syntax, tables you can copy and inline citations.

Category
AI
Components used
4
Files
4
Usage examples
2
Access
HextaUI Pro (55 blocks)
Source updated
Open in new tab

Part of HextaUI Pro, all 55 blocks, $79 one-time, Compare plans

Models answer in Markdown, and they write it a token at a time. A plain renderer flashes raw asterisks, half-built tables and unclosed code fences while it streams. Markdown completes unfinished syntax as it goes and paces the text like the Streaming block, so formatting appears in place.

Each element is built from the rest of HextaUI. Code fences become Code Blocks, GitHub callouts like [!NOTE] use Alert, task lists use read-only Checkboxes, and tables scroll sideways with a menu to copy them as Markdown or CSV. Pass sources and [1] becomes a citation chip, while marks inside code are left alone.

Headings get ids from their text, with an optional link icon to share them. Images load lazily with a placeholder and caption, footnotes link back to their mark, external links open in a new tab and say so, and text direction is detected per block. It works as well for READMEs and changelogs as for streamed answers.

  1. Get HextaUI Pro

    One payment unlocks every block, including future ones. See pricing.

  2. Add the Pro registry to components.json

    components.json
    {
      "registries": {
        "@hextaui-pro": {
          "url": "https://hextaui.com/r/pro/{name}.json",
          "headers": {
            "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
          }
        }
      }
    }
  3. Add your token

    Create a token on your account page and put it in .env.local as HEXTAUI_PRO_TOKEN.

  4. Add the block

    pnpm dlx shadcn@latest add @hextaui-pro/markdown

With the AI SDK

Render each text part of a useChat message, with source-url parts as its sources. The part’s state tells Markdown when the model is still writing.

"use client"

import type { UIMessage } from "ai"

import { Markdown } from "@/components/blocks/markdown/markdown"

export function AssistantMessage({ message }: { message: UIMessage }) {
  const sources = message.parts.flatMap((part) =>
    part.type === "source-url"
      ? [{ id: part.sourceId, url: part.url, title: part.title ?? part.url }]
      : []
  )

  return message.parts.map((part, index) =>
    part.type === "text" ? (
      <Markdown
        key={index}
        text={part.text}
        streaming={part.state === "streaming"}
        sources={sources}
      />
    ) : null
  )
}

Static content

Pass a string as children for READMEs, changelogs or saved answers. Set anchors to give headings a link people can share.

import { Markdown } from "@/components/blocks/markdown/markdown"

const changelog = `## 2.4.0

> [!NOTE]
> Requires React 19.

- [x] Faster cold starts
- [x] Copy tables as CSV
- [ ] Offline mode`

export function Changelog() {
  return <Markdown anchors size="base">{changelog}</Markdown>
}

Anatomy

The parts you compose, from the outside in.

PartDescription
MarkdownThe renderer. Takes a string and handles pacing, parsing and every element.
MarkdownTableA scrollable table with the copy menu.
MarkdownAlertA callout for [!NOTE] and the other GitHub alert types.
MarkdownHeadingA heading with an id and optional anchor link.
MarkdownImageAn image with loading, error and caption states.
PropTypeDefault
textThe Markdown so far. You can pass it as children instead.
string–
streamingPaces the text, shows the caret and completes unfinished syntax.
booleanfalse
smoothTurn pacing off to render text exactly as received.
booleantrue
sourcesTurns [1] into a chip for sources[0], and so on. Without sources, [1] stays plain text.
Source[][]
sizeText size. Use sm in chat and base for articles.
"sm" | "base""sm"
anchorsShow a link icon on headings.
booleanfalse
componentsOverride any element, such as a or img. Keep the object stable, for example outside the component, so blocks don’t remount.
Components–
classNameClasses for the wrapper.
string–
KeyAction
TabMoves through links, citations, heading anchors, table copy menus and code block actions in reading order.
EnterOpens a link, or the copy menu on a table.
↑↓Moves between Copy as Markdown and Copy as CSV.
  • The wrapper is marked aria-busy while it streams, so screen readers wait for the text to settle.
  • Callouts use role=note with their type as the label, instead of announcing like live alerts.
  • Task list checkboxes are read-only and skipped by Tab, so they read as state rather than controls.
  • External links say “opens in a new tab”, citation chips are named after their source, and heading anchors are named “Link to …”.
  • Images keep their alt text, and tables keep their header cells for screen reader navigation.
  • With reduced motion, the caret stops pulsing and images appear without fading.

Built with

The free HextaUI components Markdown is made from. Each one installs on its own.

Code

4 files, added to components/blocks/markdown.