Skip to content

markdown-include

@vuepress/plugin-markdown-include

Add markdown include features to your VuePress site.

Usage

npm i -D @vuepress/plugin-markdown-include@next
.vuepress/config.ts
import { markdownIncludePlugin } from '@vuepress/plugin-markdown-include'

export default {
  plugins: [
    markdownIncludePlugin({
      // options
    }),
  ],
}

Syntax

Use <!-- @include: filename --> to include a file.

To partially import a file, you can specify the range of lines to be included:

  • <!-- @include: filename{start-end} -->
  • <!-- @include: filename{start-} -->
  • <!-- @include: filename{-end} -->

Also, you can include a file region:

  • <!-- @include: filename#region -->

File access is restricted

For security, files outside the project root and sensitive files (e.g. .env) are not included by default. Set allowOutsideRoot: true to allow reading files outside the project root, and use projectRoot / denyFiles to customize the check.

File region

File region is a concept in vscode, where the region content is surrounded by #region and #endregion comments.

Here are some examples:

HTML
<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- region snippet -->
    <p>
      Lorem ipsum dolor, sit amet consectetur adipisicing elit. Eligendi,
      repellendus. Voluptatibus alias cupiditate at, fuga tenetur error officiis
      provident quisquam autem, porro facere! Neque quibusdam animi quaerat
      eligendi recusandae eaque.
    </p>
    <!-- endregion snippet -->
    <p>
      Veniam harum illum natus omnis necessitatibus numquam architecto eum
      dignissimos, quos a adipisci et non quam maxime repellendus alias ipsum,
      vero praesentium laborum commodi perferendis velit repellat? Vero,
      cupiditate sequi.
    </p>
  </body>
</html>

Demo

<!-- @include: ./demo.snippet.md -->:

Heading 2

Contents containing bolded text and some markdown enhance features:

Tips

Hey how are you? 😄

<!-- @include: ./demo.snippet.md{9-13} -->:

Tips

Hey how are you? 😄

<!-- @include: ./demo.snippet.md#snippet -->:

Contents containing bolded text and some markdown enhance features:

Options

resolvePath(path: string, cwd: string | null) => string
Default(path) => path

Handle the include file path.

deepboolean

Whether to recursively include files referenced in included Markdown files.

useCommentboolean
Defaulttrue

Whether use <!-- @include: xxx --> instead of @include: xxx to include files.

resolveImagePathboolean
Defaulttrue

Whether resolve the image related path in the included Markdown file.

resolveLinkPathboolean
Defaulttrue

Whether resolve the related file link path in the included Markdown file.

MIT Licensed