Markdown API
VitePress provides APIs for working with markdown processing, including markdown-it integration and custom plugins.createMarkdownRenderer()
Create a markdown-it renderer instance with VitePress defaults and plugins.Function Signature
Parameters
The source directory containing markdown files. Used for resolving relative paths and code snippets.
Markdown processing options.
Syntax highlighting theme. Can be a single theme or an object with
light and dark themes.Additional languages for syntax highlighting.
Show line numbers in code blocks.
Callback to configure the markdown-it instance.
Options for markdown-it-anchor plugin.
Options for markdown-it-attrs plugin.
Options for frontmatter parsing.
Options for header extraction. Set to
false to disable.Enable math equations support. Requires
markdown-it-mathjax3 to be installed.Enable GitHub-flavored alerts (note, tip, warning, etc.).
Base URL for the site. Used for resolving relative links.
Logger instance for warnings. Defaults to
console.Return Value
A markdown-it instance configured with VitePress defaults and plugins.The instance is async-compatible and includes:
- Syntax highlighting with Shiki
- Frontmatter parsing
- Header extraction
- Custom containers
- Code snippets
- Image processing
- And more
Examples
Basic Usage
With Custom Theme
With Custom Plugin
Render with Frontmatter
Markdown Options
Syntax Highlighting
Shiki theme for syntax highlighting.Type:Examples:
Additional languages to load for syntax highlighting.See Shiki languages for available languages.
Custom language aliases. Maps custom names to existing languages.
Fallback language when the specified language is not available.
Shiki transformers for code blocks.See Shiki transformers for details.
Callback to set up the Shiki highlighter instance.
Markdown-It Plugins
Options for markdown-it-anchor.Controls heading anchor generation.
Options for custom containers (
::: tip, ::: warning, etc.).Enable math equations support.Requires installing Usage:
markdown-it-mathjax3:VitePress Features
Enable GitHub-flavored alerts.
Options for image processing.
Enable CJK-friendly emphasis marks.Adds support for bold in Japanese, Chinese, and Korean text.
Advanced Configuration
Setup markdown-it instance before applying VitePress plugins.
Setup markdown-it instance after applying VitePress plugins.
Disable markdown cache (experimental).
Default attributes for external links.
Built-in Plugins
VitePress includes the following markdown-it plugins by default:Core Plugins
- @mdit-vue/plugin-component - Vue component support
- @mdit-vue/plugin-frontmatter - Frontmatter parsing
- @mdit-vue/plugin-headers - Header extraction
- @mdit-vue/plugin-sfc - SFC block extraction
- @mdit-vue/plugin-title - Title extraction
- @mdit-vue/plugin-toc - Table of contents
Enhancement Plugins
- markdown-it-anchor - Heading anchors
- markdown-it-attrs - Attribute support
- markdown-it-emoji - Emoji support
VitePress Plugins
- preWrapper - Code block wrapper
- snippet - Code snippet import
- container - Custom containers
- image - Image processing
- link - Link processing
- lineNumbers - Line numbers in code
- gitHubAlerts - GitHub-flavored alerts
Examples
Custom Renderer with Math
Adding Custom Plugin
Custom Code Transformers
Content Loader
createContentLoader()
Create a data loader for markdown content.Related
- Markdown Extensions - Built-in markdown features
- Configuration Reference - Markdown config options
- Using Vue in Markdown - Vue component integration