




















A fully featured Markdown renderer for React. From README files to streaming LLM output, one component renders it all:
npm install llmrender
# Release 1.0 is available
Now **faster** and ~~heavier~~ lighter. Even $E = mc^2$ renders inline.
$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$
You also have **30+ languages** supported in the default Syntax Highlighting:
```jsx
import Markdown from "llmrender";
const App = ({ text }) => <Markdown>{text}</Markdown>;
```
your markdown what your users see
Edit the Markdown on the left, or press ▶ stream to watch it render token by token, exactly the way your LLM output arrives.
Syntax highlighting
Fenced code blocks come out colored without adding highlight.js or Prism to your bundle. JavaScript, TypeScript, Python, Rust, Go, SQL, CSS, HTML, shell, diff and many more are recognized out of the box.
highlight prop and
plug in Prism.js in three lines
// Built in, just write Markdown
<Markdown>{text}</Markdown>
// …or bring your own highlighter
<Markdown
highlight={(code, lang) => (
<SyntaxHighlighter language={lang}>
{code}
</SyntaxHighlighter>
)}
>
LaTeX math
LLMs love emitting LaTeX. LLMRender parses it and renders browser-native MathML: fractions, roots, matrices, Greek letters, sums, integrals and accents.
$…$ and display $$…$$ syntaxmath prop and keep
everything else
Inline $e^{i\pi} + 1 = 0$ math.
$$
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
$$
Inline eiπ+1=0 math.
∑ n=1 ∞ 1 n2 = π2 6
GitHub Flavored Markdown
From READMEs to chat replies, real-world Markdown is GitHub flavored, and
LLMRender renders all of it: tables with column alignment, task lists with
checkboxes, strikethrough, autolinks, and the
[!NOTE]/[!TIP]/[!WARNING]
callouts that make documents scannable.
> [!WARNING]
> Callouts render with icons and colors.
| Model | Score |
|:------|------:|
| A | 98.2 |
- [x] Tables, aligned
- [x] Task lists
- [x] ~~Missing features~~
Streaming
Streaming output means the renderer sees half-finished Markdown hundreds of times per response. LLMRender is designed for that: just re-render with the text you have so far, with no buffering, no flicker, no crashes.
$$ math blocks render as mathconst [text, setText] = useState("");
for await (const chunk of stream) {
setText((t) => t + chunk);
}
// Re-render on every chunk: unclosed
// ``` fences and $$ blocks mid-stream
// render gracefully, never break
return <Markdown>{text}</Markdown>;
Security
Whether it comes from users, files or models, Markdown can carry malicious
payloads, so LLMRender is
safe by default:
javascript: and data: URLs are neutralized, raw
HTML is ignored unless you opt in, and even then it goes through a strict
tag and attribute allowlist.
dangerouslySetInnerHTML anywhere, everrawHtml blocks scripts, event handlers, iframes and styles
even when enabled
target="_blank" links get
rel="noopener noreferrer" against tabnabbing
// Safe by default: HTML ignored,
// dangerous URLs neutralized
<Markdown>{untrusted}</Markdown>
// Opt in to a safe HTML allowlist
<Markdown rawHtml>{untrusted}</Markdown>
// …or define exactly what's allowed
<Markdown rawHtml={{ b: [], a: ["href"] }}>
{untrusted}
</Markdown>
Styling
The output is a plain <div> with semantic HTML
inside, so Tailwind Typography, Styled Components, CSS Modules or plain
stylesheets all work with zero adapters.
default, dark, adaptive (follows
prefers-color-scheme) and contrast (WCAG AAA)
--llmrender-* CSS variables<div> attribute passes through:
className, style, data-*…
// Pick a theme…
import "llmrender/themes/adaptive.css";
// …then style it like any other div
<Markdown
className="prose dark:prose-invert"
id="answer"
data-testid="chat-message"
>
{text}
</Markdown>
Bundle size
Markdown + math + highlighting + sanitizing, measured as real bundle overhead in identical Vite builds (methodology):
| Package | Base | Math | Highlight | Sanitize | Full size (gzip) |
|---|---|---|---|---|---|
| LLMRender | 9 KB | built-in | built-in | built-in | 12 KB |
react-markdown |
33.3 KB | +74.6 KB | +508 KB | built-in | 340 KB |
marked |
12.1 KB | +74.6 KB | +298 KB | +8.7 KB | 403 KB |
markdown-it |
43.3 KB | +74.6 KB | +298 KB | +8.7 KB | 436 KB |
npm install llmrender
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。