English
markdown-raw
Add the raw container to your VuePress site, with optional style isolation for its content.
Usage
npm i -D @vuepress/plugin-markdown-raw@nextimport { markdownRawPlugin } from '@vuepress/plugin-markdown-raw'
export default {
plugins: [markdownRawPlugin()],
}Guide
raw container
The raw container wraps its content with a <div class="vp-raw"> element. It is meant for content that is rendered by another tool or copied from a component library, whose DOM is not expected to receive the document styles of your site.
The wrapper element does not isolate styles by itself. To make the styles of your site skip the wrapped content, enable the isolateStyles option, or apply the exported PostCSS plugin manually (see Style isolation).
::: raw
Any content, including HTML and Markdown.
:::Style isolation
PostCSS does not provide a way to isolate styles from a part of the DOM. The plugin ships a port of VitePress postcssIsolateStyles: it prefixes the selectors of the matched style files with :not(:where(.vp-raw, .vp-raw *)), so those styles do not apply inside a raw container.
With isolateStyles: true, the plugin injects the PostCSS plugin into the bundler automatically, no matter whether you use @vuepress/bundler-vite, @vuepress/bundler-webpack or @vuepress/bundler-rspack.
By default, only style files whose path matches /vp-doc\.css/ or /base\.css/ are isolated, which matches the VitePress layout. Pass an object to isolate other files:
import { markdownRawPlugin } from '@vuepress/plugin-markdown-raw'
export default {
plugins: [
markdownRawPlugin({
isolateStyles: {
includeFiles: [/vp-doc\.css/, /base\.css/, /my-article\.css/],
ignoreFiles: [/my-article\.css/],
},
}),
],
}If you already manage PostCSS plugins yourself, use the exported plugin directly:
import { postcssIsolateStyles } from '@vuepress/plugin-markdown-raw'
export default {
plugins: [postcssIsolateStyles()],
}Tips
The style isolation only makes sense when the theme styles and the raw content live in the same page. If your site does not need it, keep isolateStyles: false (the default).
Options
isolateStyles
IsolateStylesOptions | booleanDefault
falseWhether to isolate the page styles from the content of the raw container. When enabled, a PostCSS plugin is injected into the bundler.
isolateStyles.includeFiles
RegExp[]Default
[/vp-doc\.css/, /base\.css/]Style files to be isolated, matched with the resolved file path.
isolateStyles.ignoreFiles
RegExp[]Style files to be ignored, matched with the resolved file path.
isolateStyles.prefix
stringDefault
:not(:where(.vp-raw, .vp-raw *))Selector prefix added to the matched selectors.
