Extensions

Add syntax highlighting, mathematics, and diagrams only when your application needs them.

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/code
import 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/math
import 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/pele
import { 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 colorShiki source
bgeditor.background, then theme bg
fgeditor.foreground, then theme fg
lineeditorLineNumber.foreground
accentfocusBorder, then the keyword token
mutedThe comment token, then editorLineNumber.foreground
surfaceeditor.selectionBackground
bordereditorWidget.border

Mermaid

The standard Mermaid renderer supports every diagram type supported by your Mermaid version:

pnpm add @stream-markdown/mermaid
import 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-mermaid
import 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.

© 2026 Vue Stream Markdown.