Markdown Extensions

Header Anchors

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

Inbound links ending in .md or .html are converted to <router-link> for SPA navigation.

Each sub-directory in your static site should contain a README.md. It will automatically be converted to index.html.

::: tip
When writing the relative path to a directory’s index.html, don’t forget to close it off with a /, otherwise you will get a 404. For example, use /config/ instead of /config.
:::

If you want to link to another markdown file within a directory, remember to:

  1. Append it with either .html or .md
  2. Make sure the case matches since the path is case-sensitive

Example

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
  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 anchor](/foo/#heading) <!-- Anchors user to a heading in the foo README file -->
  4. [foo - one](/foo/one.html) <!-- You can append .html -->
  5. [foo - two](/foo/two.md) <!-- Or you can append .md -->

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

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

Front Matter

YAML front matter is supported out of the box:

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

The data will be available to the rest of the page, plus all custom and theming components as $page.

title and lang will be automatically set on the current page. In addition you can specify extra meta tags to be injected:

  1. ---
  2. meta:
  3. - name: description
  4. content: hello
  5. - name: keywords
  6. content: super duper SEO
  7. ---

Alternative Front Matter Formats

In addition, VuePress also supports JSON or TOML front matter.

JSON front matter needs to start and end in curly braces:

  1. ---
  2. {
  3. "title": "Blogging Like a Hacker",
  4. "lang": "en-US"
  5. }
  6. ---

TOML front matter needs to be explicitly marked as TOML:

  1. ---toml
  2. title = "Blogging Like a Hacker"
  3. lang = "en-US"
  4. ---

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

Tables Are Cool
col 3 is right-aligned $1600
col 2 is centered $12
zebra stripes are neat $1

Emoji :tada:

Input

  1. :tada: :100:

Output

:tada: :100:

A list of all emojis available can be found here.

Table of Contents

Input

  1. [[toc]]

Output

[[toc]]

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

Custom Containers

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. :::

Output

::: tip
This is a tip
:::

::: warning
This is a warning
:::

::: danger
This is a dangerous thing
:::

You can also customize the title of the block:

  1. ::: danger STOP
  2. Danger zone, do not proceed
  3. :::

::: danger STOP
Danger zone, do not proceed
:::

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:


Image


Image

" class="reference-link">Import Code Snippets

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

  1. <<< @/filepath

It also supports line highlighting:

  1. <<< @/filepath{highlightLines}

Input

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

Output

<<< @/test/markdown/fragments/snippet.js{2}

::: 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-it 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. config: md => {
  8. // use more markdown-it plugins!
  9. md.use(require('markdown-it-xxx'))
  10. }
  11. }
  12. }