Unstable API — This API is under active development and may change in future versions of Bun.
Bun.markdown.html()— render Markdown to an HTML stringBun.markdown.render()— render Markdown with custom callbacks for each elementBun.markdown.react()— render Markdown to React JSX elements
Bun.markdown.html()
Convert a Markdown string to HTML.
Options
Pass an options object as the second argument to configure the parser:Autolinks
Passtrue to enable all autolink types, or an object for granular control:
Heading IDs
Passtrue to enable both heading IDs and autolink headings, or an object for granular control:
Bun.markdown.render()
Parse Markdown and render it using custom JavaScript callbacks. This gives you full control over the output format — you can generate HTML with custom classes, React elements, ANSI terminal output, or any other string format.
Callback signature
Each callback receives:children— the accumulated content of the element as a stringmeta(optional) — an object with element-specific metadata
null or undefined to omit the element from the output entirely. If no callback is registered for an element, its children pass through unchanged.
Block callbacks
List item meta
ThelistItem callback receives everything needed to render markers directly:
index— 0-based position within the parent listdepth— the parent list’s nesting level (0 = top-level)ordered— whether the parent list is orderedstart— the parent list’s start number (only whenorderedis true)checked— task list state (only for- [x]/- [ ]items)
Inline callbacks
Examples
Custom HTML with classes
Stripping all formatting
Omitting elements
Returnnull or undefined to remove an element from the output:
ANSI terminal output
Nested list numbering
ThelistItem callback receives everything needed to render markers directly — no post-processing:
Code block syntax highlighting
Parser options
Pass parser options as a separate third argument:Bun.markdown.react()
Render Markdown directly to React elements. Returns a <Fragment> that you can use as a component return value.
Server-side rendering
Works withrenderToString() and React Server Components:
Component overrides
Replace any HTML element with a custom React component by passing it in the second argument, keyed by tag name:Available overrides
Every HTML tag produced by the parser can be overridden:React 18 and older
By default, elements useSymbol.for('react.transitional.element') as the $$typeof symbol. For React 18 and older, pass reactVersion: 18 in the options (third argument):