streamdown package.
Code block components
CodeBlock
The primary code block component. Renders a container with a language header, an optional actions slot, and the highlighted code body. Syntax highlighting is loaded lazily via React Suspense; the unhighlighted tokens are shown as a fallback while the highlighter loads.HTMLAttributes<HTMLDivElement> plus:)
The raw source code to display and highlight.
The language identifier used for syntax highlighting and file extension mapping.
When
true, marks the block as still streaming. The container receives a data-incomplete attribute and highlighting may be deferred. Defaults to false.Custom starting line number for line numbering. Defaults to
1.Whether to show line numbers. Inherits from
StreamdownContext (default true) when not provided directly.Action buttons rendered in a sticky overlay in the top-right corner of the code block. Typically
CodeBlockCopyButton and/or CodeBlockDownloadButton.CodeBlockContainer
The outer wrapper<div> for a code block. Applies Tailwind classes for border, background, padding, and rounded corners, plus content-visibility: auto for off-screen rendering performance.
ComponentProps<"div"> plus:)
Set as the
data-language attribute on the container element.When
true, sets data-incomplete on the container. Useful for conditional styling during streaming.CodeBlockHeader
A small header bar that displays the language name in lowercase monospace text.The language label to display. Rendered in lowercase.
CodeBlockCopyButton
A button that copies the code to the clipboard. Must be rendered inside aCodeBlock (which provides the code via context) or receive the code prop directly. Disabled during animation (isAnimating from StreamdownContext).
ComponentProps<"button"> plus:)
The text to copy. When omitted, the code is read from the nearest
CodeBlock via context.Called after the code has been successfully written to the clipboard.
Called when copying fails (e.g. clipboard API unavailable).
Duration in milliseconds for which the “copied” state is shown. Defaults to
2000.CodeBlockDownloadButton
A button that triggers a file download of the code. The file extension is inferred from the language identifier. Disabled during animation.ComponentProps<"button"> plus:)
The text to download. When omitted, the code is read from the nearest
CodeBlock via context.Used to determine the file extension (e.g.
"typescript" → .ts, "python" → .py). Falls back to .txt for unknown languages.Called after the file download is triggered.
Called when the download fails.
CodeBlockSkeleton
A loading placeholder that matches the shape of a code block. Shows a spinner icon. Use this as a loading state while a code block is being prepared.IconProvider.
Table components
TableCopyDropdown
A dropdown button that copies the nearest ancestor table to the clipboard in Markdown, CSV, or TSV format. The HTML representation of the table is also placed on the clipboard alongside the plain-text format.Called with the chosen format after the table has been written to the clipboard.
Called when copying fails.
Duration in milliseconds for the “copied” confirmation state. Defaults to
2000.Additional CSS class names for the trigger button.
Custom trigger content. Defaults to a copy icon.
TableDownloadButton
A button that downloads the nearest ancestor table as a file in the specified format.The download format. Defaults to
"csv".The base filename without extension. Defaults to
"table".Called after the file download is triggered.
Called when the download fails.
Additional CSS class names for the button.
Custom button content. Defaults to a download icon.
TableDownloadDropdown
A dropdown button that lets the user choose between CSV and Markdown download formats.Called with the chosen format after the file download is triggered.
Called when the download fails.
Additional CSS class names for the trigger button.
Custom trigger content. Defaults to a download icon.
Table utility functions
The following functions are exported fromstreamdown and operate on the TableData structure. They are used internally by the table components but are available for standalone use.
TableData
The column header values extracted from the
<thead> row.The data rows extracted from
<tbody>. Each inner array corresponds to one table row; values are the text content of each <td> cell.extractTableDataFromElement()
<table> DOM element by querying thead th for headers and tbody tr td for rows.
The
<table> element to extract data from.tableDataToCSV()
TableData to a CSV string. Values containing commas, double quotes, or newlines are quoted and internal double quotes are escaped by doubling them (" → ""). The header row is included first when headers is non-empty.
tableDataToTSV()
TableData to a TSV (tab-separated values) string. Tabs, newlines, and carriage returns within cell values are escaped as \t, \n, and \r.
tableDataToMarkdown()
TableData to a GFM Markdown table string. Returns an empty string when headers is empty. Rows shorter than the header row are padded with empty cells. Pipe characters and backslashes in cell values are escaped.
escapeMarkdownTableCell()
\ → \\), then pipe characters (| → \|). Returns the original string unchanged when no escaping is needed (fast path).
The raw cell string to escape.
