dr-ui
Components

Streaming Markdown

StreamingMarkdown uses Streamdown with Shiki for syntax highlighting. Shiki ships many themes and languages by default, which can significantly increase your bundle size.

See Optimization for how to trim the Shiki payload after install.

Renders Markdown (including incremental streams) with Streamdown and design-system typography

Installation

npx shadcn@latest add @dr-ui/streaming-markdown

Registry dependencies

@dr-ui/utils
@dr-ui/heading
@dr-ui/theme

Dependencies

streamdown@^2.5.0
lucide-react@^1.7.0
@streamdown/code@^1.1.1
@streamdown/math@^1.0.2
@shikijs/themes@^4.0.2

Basic

Capybara: The World’s Largest Rodent

Introduction

The capybara is a semi-aquatic mammal native to South America. Known for its calm behavior and social nature, it is often called one of the most relaxed animals in the wild.

Key Characteristics

  • Friendly and highly social
  • Excellent swimmer
  • Active during early morning and evening
  • Often seen resting near water

Habitat and Diet

Capybaras live near rivers, lakes, and wetlands. Their diet mainly consists of grasses and aquatic plants.

Common Foods

  1. Grasses
  2. Aquatic plants
  3. Fruits (occasionally)
  4. Tree bark

Capybara Facts Table

FeatureDescription
Average Weight35–66 kg
Lifespan8–10 years
HabitatWetlands, rivers, grasslands
Activity TimeCrepuscular (dawn and dusk)

Learn More

Wikipedia


Capybaras are a great example of how animals adapt to both land and water environments.

typescript
function greet(name: string): string {  return `Hello, ${name}!`;}

Here is an inline math expression: E=mc2E = mc^2

And a block math expression:

i=1ni=n(n+1)2\sum_{i=1}^{n} i = \frac{n(n+1)}{2}

Installation

npx shadcn@latest add @dr-ui/streaming-markdown

Optimization

Syntax highlighting is the main bundle cost. Reduce it in two ways: load only the themes your app uses, and switch from Shiki’s full language bundle to the web bundle (~56 languages instead of ~235).

In a representative app setup, these changes reduced the number of Shiki-related files from 360 to 122. Font assets are not trimmed — they stay as part of the standard app stack.

1. Limit themes with createCodePlugin

StreamingMarkdown highlights code with github-light and github-dark-dimmed. In streaming-markdown.tsx, use createCodePlugin with only those themes instead of the default code export (which registers every bundled theme):

import { createCodePlugin } from '@streamdown/code';

const plugins = {
  code: createCodePlugin({
    themes: ['github-light', 'github-dark-dimmed'],
  }),
  // ...
};

Keep shikiTheme on <Streamdown /> aligned with the same pair:

const shikiTheme = ['github-light', 'github-dark-dimmed'] as const;

2. Point your bundler at lib/shiki-themes.ts and use the Shiki web language bundle

createCodePlugin still resolves themes through Shiki’s themes.mjs, which lists every bundled theme. The install includes lib/shiki-themes.ts as a drop-in replacement that only imports the two themes above. Point your bundler at that file when Shiki loads ./themes.mjs.

Vite — add a resolveId plugin and alias shiki to the web bundle:

// vite.config.ts
import path from 'path';

export default defineConfig({
  plugins: [
    {
      name: 'shiki-themes-subset',
      enforce: 'pre',
      resolveId(source, importer) {
        if (
          source === './themes.mjs' &&
          importer?.includes('shiki/dist/')
        ) {
          return path.resolve(__dirname, './lib/shiki-themes.ts');
        }
      },
    },
  ],
  resolve: {
    alias: [
      { find: '@', replacement: path.resolve(__dirname, './src') },
      { find: /^shiki$/, replacement: 'shiki/bundle/web' },
    ],
  },
});

Adjust the path if your project keeps lib/ under src/ (for example ./src/lib/shiki-themes.ts).

On this page