Fragments

Markdown

Formance-styled markdown renderer (GFM, code blocks, tables, math, mermaid) with an overridable component map.

Formance
Docs

A Formance-styled markdown renderer built on react-markdown. Pass a markdown string as children and it renders headings, prose, lists, links, tables, and code blocks with the design system's tokens and typography. Typography comes from typeset: the wrapper carries typeset typeset-docs, so the rendered elements need no classes of their own. Fenced code blocks render as a Code Block (Shiki), with the language in the header and a copy button, and inline code stays lightweight. While a fence is not closed (an odd number of ``` markers, as when a reply streams), the copy button is disabled.

Out of the box it supports GitHub Flavored Markdown (remark-gfm), math (remark-math + rehype-katex), and ```mermaid diagrams (loaded lazily). Every element renderer is overridable through the components prop, which is merged over the defaults — override one tag without losing the rest. The same map is exported as markdownComponents so you can reuse the renderers in your own react-markdown (or streamdown) instance — wrap that output in typeset typeset-docs to get the same typography. To keep an embedded component out of typeset, give it the not-typeset class.

import { Markdown } from '@/components/ui-fragments/markdown';
<Markdown>{`# Hello\n\nSome **markdown** with a [link](https://formance.com).`}</Markdown>;

GitHub Flavored Markdown#

Tables, task lists, strikethrough, and autolinks via remark-gfm.

Code blocks#

Fenced blocks render as a CodeBlock (Shiki); unknown languages fall back to plain text.

Extending the component map#

Pass a components map to override or inject custom renderers. It is merged over the defaults, so the rest of the elements keep their styling.

Math (KaTeX)#

Inline ($…$) and block ($$…$$) math via remark-math and rehype-katex.

Mermaid diagrams#

A ```mermaid fence renders as a diagram. The mermaid bundle is code-split and only loaded when a diagram is present.

Mermaid diagrams

A ```mermaid fence renders as a diagram. The mermaid bundle is loaded lazily, so pages without diagrams never pay for it.

Compound Components

Compose the pieces you need:

<Markdown />Renders a markdown string with Formance styling. Accepts a `components` prop merged over the defaults.
<markdownComponents />The reusable element→component map (links, task-list inputs, code blocks). Spread it into react-markdown or streamdown and wrap the output in `typeset typeset-docs` for the same typography.