UnflowUI
Components

Markdown

Renders markdown (GitHub Flavored Markdown) on the app type scale, including content that is still streaming in.

Overview

Markdown renders GitHub Flavored Markdown: headings, tables, task lists, strikethrough, autolinks, block quotes, inline code and fenced code blocks. Headings use the 16 px step and body text 14/22, so answers sit naturally inside app UI. Fenced code renders as a CodeBlock and inline code as InlineCode.

It is built for content that arrives in pieces, such as AI responses. With streaming, unfinished syntax renders cleanly and only the last block re-renders as text arrives.

Links open in a new tab without access to the opener, and javascript: URLs are dropped. Raw HTML shows as text unless allowHtml is set, and is sanitized when it is.

Import

import { Markdown } from '@unflowio/ui/components/Markdown';

Props

PropTypeDefaultDescription
contentstring—Required. The markdown source
streamingbooleanfalseThe content is still arriving. Unclosed code fences, half-typed tables and links, and open inline markers render cleanly, and a caret follows the last word
componentsComponents—Element overrides merged over the defaults (e.g. a for citation links). Keep the object stable
allowHtmlbooleanfalseRenders raw HTML in the content, sanitized. Off by default: HTML shows as text
remarkPluginsOptions['remarkPlugins']—Extra remark plugins after GFM, e.g. remark-math. Keep the array stable
rehypePluginsOptions['rehypePlugins']—Extra rehype plugins, e.g. rehype-katex. Keep the array stable
codeBlockPropsPick<ICodeBlock, 'showLineNumbers' | 'wrap' | 'maxHeight'>—Passed to every code block. Keep the object stable
codeActions(code: string, language: string | undefined) => ReactNode—App actions for each code block's header, e.g. an "Insert" button

Components and Options are the react-markdown types. Other <div> props go to the wrapper.

Basic usage

Quarterly summary

Spend grew 12% while seats stayed flat, so the increase comes from heavier use.

TeamSeatsMonthly spend
Brand24€612.40
Legal9€188.10
Support31€904.75
  1. Invite the workspace admins
  2. Set a budget per team
  • Guidelines uploaded
  • Legal review
json
{ "event": "post_click", "utm_campaign": "launch" }

See pricing for details.

<Markdown content={answer} />

Streaming

Pass the text received so far as content and keep streaming on until the last chunk arrives. While it is on:

  • an unclosed code fence renders as a code block, not as stray backticks
  • a table is held back until its delimiter row arrives, and a half-typed last row is left out, so broken table markup never shows
  • half-typed links and images wait until they are complete instead of flashing as raw syntax
  • open inline code, bold and strikethrough markers are closed
  • a caret follows the last word, and goes away when streaming turns off

Content is split into blocks at blank lines, and only the last block re-renders as text arrives, so long answers stay cheap to update.

<Markdown content={received} streaming={!done} />

Raw HTML

By default, HTML in the content shows as text. Set allowHtml to render it. It is sanitized first, so scripts, event handlers and javascript: URLs are removed.

The answer used <b>bold</b> and <script>alert(1)</script>: both show as text.

<Markdown content={trustedHtmlAndMarkdown} allowHtml />

Overrides and plugins

components replaces how individual elements render, e.g. turning links into citation chips. codeBlockProps and codeActions configure every code block. Define these at module scope or memoize them: a new object or function on each render re-renders every block.

import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import type { Components } from 'react-markdown';

const components: Components = {
  a: ({ href, children }) => <CitationLink href={href}>{children}</CitationLink>,
};
const remarkPlugins = [remarkMath];
const rehypePlugins = [rehypeKatex];
const codeBlockProps = { maxHeight: 320 };

export function Answer({ text, done }: { text: string; done: boolean }) {
  const codeActions = useCallback(
    (code: string) => <InsertButton onClick={() => insert(code)} />,
    [],
  );

  return (
    <Markdown
      content={text}
      streaming={!done}
      components={components}
      remarkPlugins={remarkPlugins}
      rehypePlugins={rehypePlugins}
      codeBlockProps={codeBlockProps}
      codeActions={codeActions}
    />
  );
}

Accessibility

  • Output is semantic HTML: real headings, lists, tables with header cells, and block quotes.
  • Links open in a new tab with rel="noopener noreferrer".
  • Code blocks keep their CodeBlock behaviour: an announced Copy button and line numbers hidden from screen readers.