Skip to content

Markdown Extensions

VitePress uses markdown-it as its Markdown renderer and adds many useful extensions on top of it, making content creation easier and more powerful.

Frontmatter

You can use YAML frontmatter at the top of each Markdown file to define metadata. This data can be used on the page, in components, and in configuration files.

yaml
---
title: My Document Title
description: This is a page description.
home: true
---

title and description will be automatically used by VitePress to set the page's <title> and <meta name="description"> tags.

Header Anchors

All headers (from # to ######) will automatically get an anchor link. When you hover over a header, a clickable § icon will appear. This makes it easy for users to share links to specific sections.

VitePress intelligently handles links in Markdown. Relative links pointing to .md files will be converted to correct route links, while external links will automatically have target="_blank" rel="noopener noreferrer" added.

Custom Containers

You can use custom containers to highlight specific information. This is a very useful feature for displaying tips, warnings, or danger messages.

Syntax

markdown
::: tip
This is a tip
:::

::: warning
This is a warning
:::

::: danger
This is a danger warning
:::

::: details
This is a collapsible details block

Here is more information...
:::

Effect

TIP

This is a tip

WARNING

This is a warning

DANGER

This is a danger warning

Syntax Highlighting

VitePress has built-in syntax highlighting support for code blocks, powered by Shiki. You just need to specify the language of the code block.

markdown
```javascript
export default {
  name: 'MyComponent'
}
```

Line Highlighting

You can add {} after the code block language to specify the lines you want to highlight.

markdown
```js{4-5,8}
// ... (code)
const a = 1;
const b = 2;

function add(a, b) { 
  return a + b;      
}

add(a, b); 

```
  • {4-5,8}: Highlight lines 4, 5, and 8.
  • // [!code focus]: Focus highlighting for the current line.
  • // [!code ++]: Add highlighting (green).
  • // [!code --]: Delete highlighting (red).

Import Code Snippets

You can import code snippets directly from existing files, which is very useful for showing real code examples.

markdown
<<< @/path/to/your/code/file.js

You can also specify the line range to import:

markdown
<<< @/path/to/your/code/file.js{2-10}

Using Vue in Markdown

One of VitePress's standout features is the ability to seamlessly use Vue components within Markdown files. You can use them just like in regular Vue Single File Components (SFCs), including Vue template syntax and components.

markdown
This is a Markdown paragraph.

<MyVueComponent :prop="someValue" />

{{ 1 + 1 }} <!-- Output: 2 -->

This provides endless possibilities for creating rich, interactive documentation.

Content is for learning and research only.