Skip to content

Markdown

The theme wires the Markdown plugins it needs, so the syntax below works out of the box. Each section links to the plugin that owns the syntax and its full options.

@vuepress/theme-default

Hint Containers

The theme enables @vuepress/plugin-markdown-hint with both the hint containers and the GFM alerts.

::: tip
This is a tip.
:::

::: warning
This is a warning.
:::

::: danger
This is a danger message, rendered with the caution style.
:::

::: details
A collapsible block.
:::

The available containers are tip, warning, danger, important, note, info, caution and details. Their default titles are the theme options tip, warning, danger, important and note, and the plugin locales for the others.

The text after the container name replaces the title, and {no-title} removes the title while keeping the icon:

::: tip Custom Title
The title of this block is "Custom Title".
:::

::: warning {no-title}
This block has no title.
:::

::: details always needs a summary, so {no-title} is ignored there.

The GFM alerts are enabled too, so a blockquote whose first line is > [!note] renders as a hint container:

> [!TIP]
> A tip written as a GFM alert.

See Markdown Hint for the options, such as disabling the alerts.

Code Tabs

Code tabs are provided by @vuepress/plugin-markdown-tab:

::: code-tabs

@tab pnpm

```sh
pnpm add -D @vuepress/theme-default@next
```

@tab npm

```sh
npm i -D @vuepress/theme-default@next
```

:::

@tab:active marks the tab selected by default, and @tab title#value overrides the value of the tab. A #id after ::: code-tabs groups the groups that share the same id, so they switch together and keep the choice:

::: code-tabs#package-manager

The generic tab group is opt-in, because the theme only enables codeTabs by default:

export default defineUserConfig({
  theme: defaultTheme({
    themePlugins: { markdownTab: { tabs: true } },
  }),
})
::: tabs

@tab Fruit

Apple

@tab Vegetable

Carrot

:::

The tab contents are Vue components, so they may use any client-side syntax.

v-pre

The theme enables the v-pre container of @vuepress/plugin-markdown-ext, which renders its content without compiling it:

::: v-pre
{{ This is not compiled as a Vue expression }}
:::

The other extensions of the plugin — the GFM support, the footnotes, the task lists and the component fence — are opt-in through themePlugins.markdownExt. For example:

defaultTheme({
  themePlugins: {
    markdownExt: { gfm: true, footnote: true, tasklist: true },
  },
})

raw

The theme enables the raw container of @vuepress/plugin-markdown-raw. It renders its content as-is, without wrapping it in the paragraph rules of markdown:

::: raw
<div class="my-widget">...</div>
:::

The content is wrapped in a div.vp-raw, and the theme enables the style isolation of the plugin, so the styles of the theme do not leak into it. Links inside a raw container trigger a full page navigation instead of the client-side router, because the router cannot track them.

Use it when a block must be rendered by the browser exactly as written, such as an iframe, a script or a third-party widget.

Heading Anchors

Every heading gets an id and an anchor link. VuePress renders the heading text inside the <a class="header-anchor"> element, so the theme keeps the text in place and the anchor is the text itself — there is no # icon next to a heading on hover. The URL hash still updates while scrolling, because the theme wires @vuepress/plugin-active-header-links to the outline.

To link to a section, use its slug as the hash: [Install](#install). The slug is generated by VuePress, and it stays the same for the same heading text.

Set externalLinkIcon to true to show an icon after the external links of the document content:

defaultTheme({ externalLinkIcon: true })

The icon is only added to the links in the content — not to the links of the navbar, the sidebar or the footer. Add the no-icon class to a link to opt it out:

[Internal-like external link](https://example.com){.no-icon}

Links that contain an image or an inline SVG are skipped, since the icon would break their layout.

Code Blocks

The theme enables @vuepress/plugin-shiki with a light and a dark theme at once, so the code blocks follow the color mode of the site. The theme CSS consumes the --shiki-light and --shiki-dark variables that the plugin emits.

The features enabled by default are:

  • Line numbers, for every code block. Turn them off for one block with :no-line-numbers, or set the first number with :line-numbers=10.
  • Line highlighting, with a range in the info string after the language: {5-8}.
  • Collapsed lines, with :collapsed-lines or :collapsed-lines=10.
  • A title bar, with title="..." in the info string:
```ts title=".vuepress/config.ts"
import { defineUserConfig } from 'vuepress'
```

See Shiki for the notation of the other features, such as the diff and the focus markers, and for replacing the two themes.

Copy Code

The theme enables @vuepress/plugin-copy-code, which adds a copy button to every code block of the content. The button and its hint follow the site language through the plugin locales.

See Also

MIT Licensed