Include Files

  • Markdown
  • Code Demo
  • Include Files
About 1 min

Let the Markdown file in your VuePress site support including other files.

Config

Syntax

Use @include(filename) to include a file.

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

  • @include(filename{start-end})
  • @include(filename{start-})
  • @include(filename{-end})

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{5-9}):

Tips

Hey how are you? 😄

Advanced

You can also set an object to customize include filepath and include behavior.

interface IncludeOptions {
  /**
   * handle include filePath
   *
   * @default (path) => path
   */
  getPath?: (path: string) => string;

  /**
   * Whether deep include files in included Markdown files
   *
   * @default false
   */
  deep?: boolean;
}

E.g.: you can use @src as an alias for your source directory.

Also, to place your Markdown files directly besides your actual files, but don’t want them rendered as pages, you can set pagePatterns options in VuePress config. See pagePatternsopen in new window for more details.

Loading...