Skip to content

VitePress Markmap Preview ​

npm

A VitePress plugin for previewing Markmap mind maps in Markdown.

✨ Features ​

  • 🗺️ Markmap Integration: Render interactive mind maps directly in Markdown
  • 🎨 Customizable: Support all markmap configuration options
  • 🔧 Easy Setup: One-click installation and quick configuration
  • 📁 Component Support: Provide Vue components for mind map rendering
  • 🚀 TypeScript: Complete TypeScript support and type definitions
  • ⚙️ Flexible Configuration: Support custom configuration via frontmatter syntax

📦 Installation ​

bash
npm install vitepress-markmap-preview
# or
pnpm add vitepress-markmap-preview
# or
yarn add vitepress-markmap-preview

🚀 Quick Start ​

Step 1: Configure VitePress ​

Add the plugin to your VitePress configuration:

typescript
// .vitepress/config.ts
import { defineConfig } from 'vitepress';
import { vitepressMarkmapPreview } from 'vitepress-markmap-preview';

export default defineConfig({
  markdown: {
    config(md) {
      vitepressMarkmapPreview(md);
    },
  },
});

Step 2: Register Components ​

Register Vue components in your theme:

typescript
// .vitepress/theme/index.ts
import type { Theme } from 'vitepress';
import DefaultTheme from 'vitepress/theme';
import { initComponent } from 'vitepress-markmap-preview/component';
import 'vitepress-markmap-preview/dist/index.css';

export default {
  extends: DefaultTheme,
  enhanceApp({ app }) {
    initComponent(app);
  },
} satisfies Theme;

📖 Usage ​

📝 Basic Usage ​

You can directly use markmap code blocks in Markdown to create mind maps:

⚙️ Custom Configuration ​

Support custom markmap configuration options via frontmatter syntax:

📂 Reading External Files ​

Use the PreviewMarkmapPath component to read specified Markdown file content and display it as a mind map:

vue
<PreviewMarkmapPath path="./other.md" showToolbar />

If you don't want to show the toolbar, simply omit the showToolbar attribute.

📄 Reading Current File ​

When no path attribute is specified, it will read the current Markdown file content:

vue
<PreviewMarkmapPath />

⚙️ Configuration Options ​

🧩 PreviewMarkmapPath Component Properties ​

PropertyTypeDefaultDescription
pathstring-Path to the Markdown file to read
showToolbarbooleanfalseWhether to show the toolbar

🎨 Markmap Configuration Options ​

Support the following options via the markmap field in frontmatter:

Basic Options ​

OptionTypeDefaultDescription
showToolbarbooleantrueWhether to show the toolbar
colorstring[]d3.schemeCategory10Array of node colors
initialExpandLevelnumber-1Initial expansion level, -1 means expand all levels
maxWidthnumber0Maximum width of nodes, 0 means no limit
durationnumber500Animation duration (milliseconds)

Layout Options ​

OptionTypeDefaultDescription
spacingHorizontalnumber80Horizontal spacing
spacingVerticalnumber5Vertical spacing
paddingXnumber2X-axis padding

Interaction Options ​

OptionTypeDefaultDescription
zoombooleantrueWhether to allow zooming
panbooleantrueWhether to allow panning
autoFitbooleanfalseWhether to automatically fit the container
fitRationumber1Fit ratio

Advanced Options ​

OptionTypeDefaultDescription
colorFreezeLevelnumber0Color freeze level
toggleRecursivelybooleanfalseWhether to toggle recursively
scrollForPanbooleanfalseWhether to scroll for panning
maxInitialScalenumber1Maximum initial scale
lineWidthnumber1Width of lines between nodes

🔧 Configuration Examples ​

Basic Configuration Example ​

yaml
---
showToolbar: true
markmap:
  color: ['#2ecc71', '#3498db', '#9b59b6']
  initialExpandLevel: 2
  maxWidth: 400
  duration: 300
---

Advanced Configuration Example ​

yaml
---
showToolbar: false
markmap:
  color: ['#ff6b6b', '#4ecdc4', '#45b7d1', '#96ceb4', '#feca57']
  initialExpandLevel: -1
  maxWidth: 600
  duration: 500
  spacingHorizontal: 100
  spacingVertical: 10
  zoom: true
  pan: true
  colorFreezeLevel: 2
  lineWidth: 2
---

Dark Mode Adaptation Configuration ​

yaml
---
showToolbar: true
markmap:
  color: ['#2ecc71', '#3498db', '#9b59b6', '#f39c12', '#e74c3c']
  initialExpandLevel: 1
  maxWidth: 500
  duration: 400
  spacingHorizontal: 80
  spacingVertical: 5
---

📚 More Examples ​

Check out the Configuration Examples for more detailed usage examples and configuration instructions.

📄 License ​

MIT License

🙏 Acknowledgments ​


Made with ❤️ by flingyp