Skip to content

Vue 2 streaming Markdown renderer for AI chat

markstream-vue2 is the Vue 2.6 / 2.7 renderer in the Markstream family. Use it when a legacy Vue 2 app needs AI chat Markdown, LLM token streams, SSE/WebSocket output, incomplete Markdown state handling, Mermaid, KaTeX, Shiki-backed code blocks, or Vue 2 component rendering.

For Vue 3, Nuxt 3, or a new project, start with markstream-vue instead.

When to use markstream-vue2

Use markstream-vue2 when:

  • The app must stay on Vue 2.6 or Vue 2.7
  • Markdown streams from an LLM, SSE endpoint, or WebSocket
  • Unclosed fences, partial math, or partial HTML-like tags should not flicker
  • Long AI responses need bounded live rendering
  • Mermaid, KaTeX, and code blocks appear during streaming
  • Custom Vue 2 node components need to render inside Markdown

Use a simpler Vue Markdown renderer when:

  • The app only renders short completed Markdown
  • You only need markdown -> HTML
  • The project can migrate to Vue 3 and use markstream-vue

Quick Start

bash
pnpm add markstream-vue2

Vue 2.6 apps also need:

bash
pnpm add @vue/composition-api
js
import VueCompositionAPI from '@vue/composition-api'
import { VueRendererMarkdown } from 'markstream-vue2'
import Vue from 'vue'
import 'markstream-vue2/index.css'

Vue.use(VueCompositionAPI)
Vue.use(VueRendererMarkdown)

Vue 2.7 apps do not need @vue/composition-api, but should still install the renderer plugin:

js
import { VueRendererMarkdown } from 'markstream-vue2'
import Vue from 'vue'
import 'markstream-vue2/index.css'

Vue.use(VueRendererMarkdown)

Minimal Vue 2 message component:

vue
<script>
import MarkdownRender from 'markstream-vue2'

export default {
  components: { MarkdownRender },
  props: { content: String, done: Boolean },
}
</script>

<template>
  <MarkdownRender :content="content" :final="done" :fade="false" />
</template>

Vue CLI 4 / Webpack 4 projects should use the real CSS file path because Webpack 4 does not support package.json#exports:

js
import 'markstream-vue2/dist/index.css'

Streaming example

For normal chat streaming, append chunks to content and flip final when the stream ends:

vue
<script>
import MarkdownRender from 'markstream-vue2'

export default {
  components: { MarkdownRender },
  data: () => ({ content: '', final: false }),
}
</script>

<template>
  <MarkdownRender :content="content" :final="final" :fade="false" />
</template>

For high-frequency long streams, use the parser/node path described in the Vue 2 quick start so parsing cadence stays under your control.

Mermaid, KaTeX, and code blocks

Install optional peers only for the blocks you render:

bash
pnpm add stream-markdown

Then enable Shiki-backed code blocks:

js
import { MarkdownCodeBlockNode, setCustomComponents } from 'markstream-vue2'

setCustomComponents({ code_block: MarkdownCodeBlockNode })

For Mermaid diagrams, install mermaid. For KaTeX math, install katex and import its stylesheet:

bash
pnpm add mermaid
pnpm add katex
js
import 'katex/dist/katex.min.css'

The default Mermaid and KaTeX loaders are enabled. Use enableMermaid() or enableKatex() only after disabling them or when providing a custom loader.

Compared with Vue Markdown renderers

Needmarkstream-vue2Normal Vue Markdown renderer
Vue 2.6 / 2.7 supportYesVaries by package
Streaming AI chatBuilt for accumulating content and optional nodesUsually rerenders completed Markdown
Incomplete MarkdownStreaming-aware mid-state handlingOften unstable while syntax is incomplete
Mermaid / KaTeX / code blocksMarkstream integrations and optional peersPlugin dependent
New Vue 3 projectsUse markstream-vue insteadUse a Vue 3 package

Try it

FAQ

Should I use markstream-vue2 for a new Vue project?

No. Use markstream-vue for Vue 3 and new Nuxt projects. markstream-vue2 exists for legacy Vue 2.6 and Vue 2.7 apps.

Does markstream-vue2 work with Vue 2.6?

Yes, but Vue 2.6 apps must install and register @vue/composition-api before using the renderer.

When is markstream-vue2 better than a normal Vue Markdown renderer?

Use markstream-vue2 when Markdown is still streaming from an LLM, SSE, or WebSocket, or when incomplete Markdown states, long output, Mermaid, KaTeX, or code blocks need stable rendering.