function
bun.markdown.render
input: string | ArrayBufferLike | TypedArray<ArrayBufferLike> | DataView<ArrayBufferLike>,
): string;
Render markdown with custom JavaScript callbacks for each element.
Each callback receives the accumulated children as a string and optional metadata, and returns a string. Return null or undefined to omit an element. If no callback is registered, children pass through unchanged.
Parser options are passed as a separate third argument.
@param input
The markdown string to render
@param callbacks
Callbacks for each element type
@param options
Parser options
@returns
The accumulated string output
// Custom HTML with classes
const html = Bun.markdown.render("# Title\n\nHello **world**", {
heading: (children, { level }) => `<h${level} class="title">${children}</h${level}>`,
paragraph: (children) => `<p>${children}</p>`,
strong: (children) => `<b>${children}</b>`,
});
// ANSI terminal output
const ansi = Bun.markdown.render("# Hello\n\n**bold**", {
heading: (children) => `\x1b[1;4m${children}\x1b[0m\n`,
paragraph: (children) => children + "\n",
strong: (children) => `\x1b[1m${children}\x1b[22m`,
});
// With parser options as third argument
const text = Bun.markdown.render("Visit www.example.com", {
link: (children, { href }) => `[${children}](${href})`,
paragraph: (children) => children,
}, { autolinks: true });