Extensions
vue-stream-markdown works without any rich-renderer package. Code remains readable source, math stays ordinary Markdown text, and Mermaid fences remain code blocks until the corresponding extension is supplied.
Extension factories receive their renderer options and return instances for the extensions prop.
Complete example
<script setup lang="ts">
import { code } from '@stream-markdown/code'
import { math } from '@stream-markdown/math'
import { pele } from '@stream-markdown/pele'
import { Markdown, MarkdownProvider } from 'vue-stream-markdown'
import 'katex/dist/katex.min.css'
const extensions = {
code: code({
theme: ['github-light', 'github-dark'],
langs: ['typescript', 'vue'],
}),
math: math({
config: { throwOnError: false },
}),
pele: pele(),
}
</script>
<template>
<MarkdownProvider :extensions="extensions">
<Markdown :content="content" />
</MarkdownProvider>
</template>Create extension instances once. For a chat or message list, pass them through MarkdownProvider so every message can share the same configuration:
<script setup lang="ts">
import { code } from '@stream-markdown/code'
import { Markdown, MarkdownProvider } from 'vue-stream-markdown'
const extensions = { code: code() }
</script>
<template>
<MarkdownProvider :extensions="extensions">
<Markdown v-for="message in messages" :key="message.id" :content="message.content" />
</MarkdownProvider>
</template>An instance can replace one provider extension or disable it with false:
<Markdown :extensions="{ code: false }" />Code
Install @stream-markdown/code to enable Shiki highlighting:
pnpm add @stream-markdown/codeimport type { CodeExtensionOptions } from '@stream-markdown/code'
import { code } from '@stream-markdown/code'
const options: CodeExtensionOptions = {
theme: ['vitesse-light', 'vitesse-dark'],
langs: ['typescript', 'vue'],
langAlias: { 'custom-lang': 'typescript' },
codeToTokenOptions: {
includeExplanation: false,
},
}
const codeExtension = code(options)Call await codeExtension.getHighlighter() to reuse the shared Shiki highlighter with the configured themes loaded. Use disposeShikiHighlighter() only after all consumers have finished using the shared instance.
Math
Install @stream-markdown/math to add both Comark math parsing and KaTeX rendering:
pnpm add @stream-markdown/mathimport type { MathExtensionOptions } from '@stream-markdown/math'
import { math } from '@stream-markdown/math'
const options: MathExtensionOptions = {
config: {
throwOnError: false,
macros: {
'\\RR': '\\mathbb{R}',
},
},
}
const mathExtension = math(options)For local package loading, import KaTeX CSS in your application:
import 'katex/dist/katex.min.css'The extension adds both math parsing and KaTeX rendering. Without it, math-like source remains ordinary text.
Pele
pnpm add @stream-markdown/peleimport { pele } from '@stream-markdown/pele'
const peleExtension = pele({
colors: { accent: '#5b7bd5' },
})Pass the instance as extensions.pele. Hex colors supplied through colors take precedence over the active Shiki theme, followed by the extension's light or dark defaults. The resolved colors are embedded in SVG downloads.
Use fromShikiTheme() to give Pele a palette from a specific loaded Shiki theme. You can reuse the highlighter from the code extension.
import { code } from '@stream-markdown/code'
import { fromShikiTheme, pele } from '@stream-markdown/pele'
const codeExtension = code({ theme: ['vitesse-light', 'vitesse-dark'] })
const highlighter = await codeExtension.getHighlighter()
const peleExtension = pele({
colors: fromShikiTheme(highlighter.getTheme('vitesse-dark')),
})| Pele color | Shiki source |
|---|---|
bg | editor.background, then theme bg |
fg | editor.foreground, then theme fg |
line | editorLineNumber.foreground |
accent | focusBorder, then the keyword token |
muted | The comment token, then editorLineNumber.foreground |
surface | editor.selectionBackground |
border | editorWidget.border |
Mermaid
The standard Mermaid renderer supports every diagram type supported by your Mermaid version:
pnpm add @stream-markdown/mermaidimport type { MermaidExtensionOptions } from '@stream-markdown/mermaid'
import { mermaid } from '@stream-markdown/mermaid'
const options: MermaidExtensionOptions = {
theme: ['neutral', 'dark'],
config: {
securityLevel: 'strict',
flowchart: { curve: 'basis' },
},
}
const mermaidExtension = mermaid(options)Beautiful Mermaid
Install the lightweight Beautiful Mermaid renderer independently:
pnpm add @stream-markdown/beautiful-mermaidimport type { BeautifulMermaidExtensionOptions } from '@stream-markdown/beautiful-mermaid'
import { beautifulMermaid } from '@stream-markdown/beautiful-mermaid'
const options: BeautifulMermaidExtensionOptions = {
theme: ['github-light', 'github-dark'],
config: { padding: 12 },
}
const beautifulMermaidExtension = beautifulMermaid(options)See Mermaid Diagrams for the order used when several diagram extensions are configured.
Custom error components
Provider error components belong to their extension factory:
import DiagramError from './diagram-error.vue'
const extensions = {
mermaid: mermaid({ errorComponent: DiagramError }),
math: math({ errorComponent: DiagramError }),
}CDN loading
CDN configuration also belongs to each extension rather than <Markdown>:
const cdnOptions = {
getUrl(module: string, version: string) {
if (module === 'katex-css')
return `https://esm.sh/katex@${version}/dist/katex.min.css`
if (module === 'pele')
return `https://esm.sh/pele@${version}/lazy`
return `https://esm.sh/${module}@${version}`
},
}
const extensions = {
code: code({ cdnOptions }),
math: math({ cdnOptions }),
beautifulMermaid: beautifulMermaid({ cdnOptions }),
mermaid: mermaid({ cdnOptions }),
pele: pele({ cdnOptions }),
}You can also set baseUrl and provider switches such as shiki, katex, mermaid, beautifulMermaid, or pele. Local dependencies remain the default when no CDN URL is configured. Pele uses its lazy ESM entry with baseUrl. Set pele: false to keep Pele local while other extensions use the CDN.