Skip to main content

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

string
The source directory containing markdown files. Used for resolving relative paths and code snippets.
MarkdownOptions
Markdown processing options.
ThemeOptions
Syntax highlighting theme. Can be a single theme or an object with light and dark themes.
(LanguageInput | BuiltinLanguage)[]
Additional languages for syntax highlighting.
boolean
default:"false"
Show line numbers in code blocks.
(md: MarkdownItAsync) => Awaitable<void>
Callback to configure the markdown-it instance.
AnchorOptions
Options for markdown-it-anchor plugin.
MarkdownItAttrsOptions
Options for markdown-it-attrs plugin.
FrontmatterPluginOptions
Options for frontmatter parsing.
HeadersPluginOptions | boolean
Options for header extraction. Set to false to disable.
boolean | any
default:"false"
Enable math equations support. Requires markdown-it-mathjax3 to be installed.
boolean
default:"true"
Enable GitHub-flavored alerts (note, tip, warning, etc.).
string
default:"'/'"
Base URL for the site. Used for resolving relative links.
Pick<Logger, 'warn'>
Logger instance for warnings. Defaults to console.

Return Value

MarkdownRenderer
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

ThemeOptions
Shiki theme for syntax highlighting.Type:
Examples:
(LanguageInput | BuiltinLanguage)[]
Additional languages to load for syntax highlighting.See Shiki languages for available languages.
Record<string, string>
Custom language aliases. Maps custom names to existing languages.
string
Fallback language when the specified language is not available.
ShikiTransformer[]
Shiki transformers for code blocks.See Shiki transformers for details.
(shiki: Highlighter) => void | Promise<void>
Callback to set up the Shiki highlighter instance.

Markdown-It Plugins

AnchorOptions
Options for markdown-it-anchor.Controls heading anchor generation.
MarkdownItAttrsOptions & { disable?: boolean }
Options for markdown-it-attrs.Allows adding attributes to markdown elements.
object
Options for emoji support.
Record<string, string>
Custom emoji definitions
string[]
List of enabled emoji
Record<string, string | string[]>
Emoji shortcuts
ContainerOptions
Options for custom containers (::: tip, ::: warning, etc.).
boolean | any
default:"false"
Enable math equations support.Requires installing markdown-it-mathjax3:
Usage:

VitePress Features

boolean
default:"true"
Enable GitHub-flavored alerts.
ImageOptions
Options for image processing.
boolean
default:"true"
Enable CJK-friendly emphasis marks.Adds support for bold in Japanese, Chinese, and Korean text.

Advanced Configuration

(md: MarkdownItAsync) => Awaitable<void>
Setup markdown-it instance before applying VitePress plugins.
(md: MarkdownItAsync) => Awaitable<void>
Setup markdown-it instance after applying VitePress plugins.
boolean
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.
See the Data Loading guide for more details.