Markdown Extensions

Header Anchors

Headers automatically get anchor links applied. Rendering of anchors can be configured using the markdown.anchor option.

Internal links are converted to <router-link> for SPA navigation. Also, every README.md or index.md contained in each sub-directory will automatically be converted to index.html, with corresponding URL /.

Given the following directory structure:

  1. .
  2. ├─ README.md
  3. ├─ foo
  4. ├─ README.md
  5. ├─ one.md
  6. └─ two.md
  7. └─ bar
  8. ├─ README.md
  9. ├─ three.md
  10. └─ four.md

And providing you are in foo/one.md:

  1. [Home](/) <!-- Sends the user to the root README.md -->
  2. [foo](/foo/) <!-- Sends the user to index.html of directory foo -->
  3. [foo heading](./#heading) <!-- Anchors user to a heading in the foo README file -->
  4. [bar - three](../bar/three.md) <!-- You can append .md (recommended) -->
  5. [bar - four](../bar/four.html) <!-- Or you can append .html -->

Redirection for URLs

VuePress supports redirecting to clean links. If a link /foo is not found, VuePress will look for a existing /foo/ or /foo.html. Conversely, when one of /foo/ or /foo.html is not found, VuePress will also try the other. With this feature, we can customize your website’s URLs with the official plugin vuepress-plugin-clean-urlsMarkdown Extensions - 图1.

TIP

Regardless of whether the permalink and clean-urls plugins are used, your relative path should be defined by the current file structure. In the above example, even though you set the path of /foo/one.md to /foo/one/, you should still access /foo/two.md via ./two.md.

Outbound links automatically gets target="_blank" rel="noopener noreferrer":

You can customize the attributes added to external links by setting config.markdown.externalLinks.

Frontmatter

YAML frontmatterMarkdown Extensions - 图4 is supported out of the box:

  1. ---
  2. title: Blogging Like a Hacker
  3. lang: en-US
  4. ---

This data will be available to the rest of the page, along with all custom and theming components.

For more details, check out the Frontmatter page.

GitHub-Style Tables

Input

  1. | Tables | Are | Cool |
  2. | ------------- |:-------------:| -----:|
  3. | col 3 is | right-aligned | $1600 |
  4. | col 2 is | centered | $12 |
  5. | zebra stripes | are neat | $1 |

Output

TablesAreCool
col 3 isright-aligned$1600
col 2 iscentered$12
zebra stripesare neat$1

Emoji 🎉

Input

  1. :tada: :100:

Output

🎉 💯

A list of all emojis available can be found hereMarkdown Extensions - 图5.

Table of Contents

Input

  1. [[toc]]

Output

Rendering of TOC can be configured using the markdown.toc option.

Custom Containers default theme

Input

  1. ::: tip
  2. This is a tip
  3. :::
  4. ::: warning
  5. This is a warning
  6. :::
  7. ::: danger
  8. This is a dangerous warning
  9. :::
  10. ::: details
  11. This is a details block, which does not work in IE / Edge
  12. :::

Output

TIP

This is a tip

WARNING

This is a warning

WARNING

This is a dangerous warning

This is a details block, which does not work in IE / Edge

You can also customize the title of the block:

  1. ::: danger STOP
  2. Danger zone, do not proceed
  3. :::
  4. ::: details Click me to view the code
  5. ```js
  6. console.log('Hello, VuePress!')
  7. ```
  8. :::

STOP

Danger zone, do not proceed

Click me to view the code

  1. console.log('Hello, VuePress!')

Also see:

Syntax Highlighting in Code Blocks

VuePress uses PrismMarkdown Extensions - 图7 to highlight language syntax in Markdown code blocks, using coloured text. Prism supports a wide variety of programming languages. All you need to do is append a valid language alias to the beginning backticks for the code block:

Input

  1. ``` js
  2. export default {
  3. name: 'MyComponent',
  4. // ...
  5. }
  6. ```

Output

  1. export default {
  2. name: 'MyComponent',
  3. // ...
  4. }

Input

  1. ``` html
  2. <ul>
  3. <li
  4. v-for="todo in todos"
  5. :key="todo.id"
  6. >
  7. {{ todo.text }}
  8. </li>
  9. </ul>
  10. ```

Output

  1. <ul>
  2. <li
  3. v-for="todo in todos"
  4. :key="todo.id"
  5. >
  6. {{ todo.text }}
  7. </li>
  8. </ul>

Check out the list of valid languagesMarkdown Extensions - 图8 on the Prism site.

Line Highlighting in Code Blocks

Input

  1. ``` js{4}
  2. export default {
  3. data () {
  4. return {
  5. msg: 'Highlighted!'
  6. }
  7. }
  8. }
  9. ```

Output

  1. export default {
  2. data () {
  3. return {
  4. msg: 'Highlighted!'
  5. }
  6. }
  7. }

Line Numbers

You can enable line numbers for each code blocks via config:

  1. module.exports = {
  2. markdown: {
  3. lineNumbers: true
  4. }
  5. }
  • Demo:ImageImage

Import Code Snippets beta

You can import code snippets from existing files via following syntax:

  1. <<< @/filepath

It also supports line highlighting:

  1. <<< @/filepath{highlightLines}

Input

  1. <<< @/../@vuepress/markdown/__tests__/fragments/snippet.js{2}

Output

  1. export default function () {
  2. // ..
  3. }

TIP

Since the import of the code snippets will be executed before webpack compilation, you can’t use the path alias in webpack. The default value of @ is process.cwd().

Advanced Configuration

VuePress uses markdown-itMarkdown Extensions - 图11 as the Markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the markdown-it instance using the markdown option in .vuepress/config.js:

  1. module.exports = {
  2. markdown: {
  3. // options for markdown-it-anchor
  4. anchor: { permalink: false },
  5. // options for markdown-it-toc
  6. toc: { includeLevel: [1, 2] },
  7. extendMarkdown: md => {
  8. // use more markdown-it plugins!
  9. md.use(require('markdown-it-xxx'))
  10. }
  11. }
  12. }