---
title: 高阶
author: pengzhanbo
icon: ic:outline-auto-fix-high
createTime: 2024/03/05 16:27:59
permalink: /guide/markdown/advance/
---
## iconify 图标
在 Markdown 文件中使用 [iconify](https://iconify.design/) 的图标。 主题虽然提供了
[`
这是段落
::: ``` **输出:** ::: demo-wrapper这是段落
::: ## can I use 此功能默认不启用,你可以在配置文件中启用它。 ::: code-tabs @tab .vuepress/config.ts ```ts export default defineUserConfig({ theme: plumeTheme({ plugins: { markdownPower: { caniuse: true, // [!code highlight] }, } }) }) ``` ::: 在编写文章时, 提供嵌入 [can-i-use](https://caniuse.com/) WEB feature 各平台支持说明 的功能。 方便在描述某个 WEB feature 时,能更直观的表述 该特性的支持程度。 在你的 文章 markdown文件中,使用以下格式: ``` md @[caniuse](feature) ``` ### 语法 ``` md @[caniuse](feature) @[caniuse{browser_versions}](feature) @[caniuse embed_type](feature) @[caniuse embed_type{browser_versions}](feature) ``` - `feature` 必填。 正确取值请参考 [https://caniuse.bitsofco.de/](https://caniuse.bitsofco.de/) - `{browser_versions}` 可选。当前特性在多个版本中的支持情况。 默认值为: `{-2,-1,1}` 格式: `{number,number,...}` 取值范围为 `-5 ~ 3` - 小于`0` 表示低于当前浏览器版本的支持情况 - `0` 表示当前浏览器版本的支持情况 - 大于`0` 表示高于当前浏览器版本的支持情况 - `embed_type` 可选。 资源嵌入的类型。 类型: `'embed' | 'image'` 默认值为:`'embed'` ### 示例 **获取 css 伪类选择器 `:dir()` 在各个浏览器的支持情况:** ```md @[caniuse](css-matches-pseudo) ``` 效果: @[caniuse](css-matches-pseudo) **以图片的形式,获取 css 伪类选择器 `:dir()` 在各个浏览器的支持情况:** ```md @[caniuse image](css-matches-pseudo) ``` 效果: @[caniuse image](css-matches-pseudo) **获取 css 伪类选择器 `:dir()` 特定范围浏览器的支持情况:** ```md @[caniuse{-2,-1,1,2,3}](css-matches-pseudo) ``` 效果: @[caniuse{-2,-1,1,2,3}](css-matches-pseudo) ## CodePen 主题支持在 Markdown 文件中嵌入 [CodePen](https://codepen.io/)。 ### 配置 此功能默认不启用,你可以在配置文件中启用它。 ::: code-tabs @tab .vuepress/config.ts ```ts export default defineUserConfig({ theme: plumeTheme({ plugins: { markdownPower: { codepen: true, // [!code highlight] }, } }) }) ``` ::: ### 语法 简单语法: ```md @[codepen](user/slash) ``` 更多选项支持: ```md @[codepen preview editable tab="css,result" theme="dark" height="500px" width="100%"](user/slash) ``` - `preview`: 是否渲染为预览模式 - `editable`: 是否可编辑 - `tab`: 默认显示的标签, 默认为 `result`,多个使用 `,` 分隔 - `theme`: 主题, 可选值 `dark` 和 `light` - `height`: 容器高度, 默认为 `400px` - `width`: 容器宽度, 默认为 `100%` - `user`: CodePen 用户名 - `slash`: CodePen 代码文件名 ### 示例 输入: ```md @[codepen](leimapapa/RwOZQOW) ``` 输出: @[codepen](leimapapa/RwOZQOW) **预览模式:** 输入: ```md @[codepen preview](leimapapa/RwOZQOW) ``` 输出: @[codepen preview](leimapapa/RwOZQOW) **编辑模式:** 输入: ```md @[codepen editable tab="html,result"](leimapapa/RwOZQOW) ``` 输出: @[codepen editable tab="html,result"](leimapapa/RwOZQOW) ## Replit 主题支持在 Markdown 文件中嵌入 [Replit](https://replit.com/)。 ### 配置 此功能默认不启用,你可以在配置文件中启用它。 ::: code-tabs @tab .vuepress/config.ts ```ts export default defineUserConfig({ theme: plumeTheme({ plugins: { markdownPower: { replit: true, // [!code highlight] }, } }) }) ``` ::: ### 语法 简单的语法 ```md @[replit](user/repl-name) ``` 更多选项 ```md @[replit title="" width="100%" height="450px" theme="dark"](user/repl-name#filepath) ``` - `title`: 标题 - `width`: 容器宽度 - `height`: 容器高度 - `theme`: 主题, 可选值 `dark` 和 `light` - `user`: Replit 用户名 - `repl-name`: Replit repl 名称 - `filepath`: Replit 默认打开的文件路径 输入: ```md @[replit](@TechPandaPro/Cursor-Hangout#package.json) ```` 输出: @[replit](@TechPandaPro/Cursor-Hangout#package.json) ## 导入文件 主题支持在 Markdown 文件中导入文件切片。 导入文件 默认不启用,你可以通过配置来启用它。 ::: code-tabs @tab .vuepress/config.ts ```ts export default defineUserConfig({ theme: plumeTheme({ plugins: { markdownEnhance: { include: true, // [!code highlight] }, } }) }) ``` ::: ### 语法 使用 `` 导入文件。 如果要部分导入文件,你可以指定导入的行数: - `` - `` - `` 同时你也可以导入文件区域: - `` ::::tip 文件区域 文件区域是 vscode 中的一个概念,区域内容被 `#region` 和 `#endregion` 注释包围。 :::: ### 高级 你还可以设置一个对象来自定义包含文件路径和包含行为。 ```ts interface IncludeOptions { /** * 处理 include 文件路径 * * @default (path) => path */ resolvePath?: (path: string, cwd: string | null) => string /** * 是否深度导入包含的 Markdown 文件 * * @default false */ deep?: boolean /** * 是否使用 `` 代替 `@include: xxx` 导入文件 * * @default true */ useComment?: boolean /** * 是否解析包含的 Markdown 文件的里的相对图像路径 * * @default true */ resolveImagePath?: boolean /** * 是否解析包含的 Markdown 文件的里的文件相对路径 * * @default true */ resolveLinkPath?: boolean } ``` 例如: 你可以使用 @src 作为源文件夹的别名。 ::: code-tabs @tab .vuepress/config.ts ```ts{5-11} export default defineUserConfig({ theme: plumeTheme({ plugins: { markdownEnhance: { include: { resolvePath: (file) => { if (file.startsWith('@src')) return file.replace('@src', path.resolve(__dirname, '..')) return file }, }, }, } }) }) ``` ::: 此外,如果你想将 Markdown 文件直接放在实际文件旁边,但不希望它们呈现为页面, 你可以在 VuePress 配置中设置 `pagePatterns` 选项。 有关详细信息,请参阅 [pagePatterns](https://vuejs.press/zh/reference/config.html#pagepatterns)。 ::: code-tabs @tab .vuepress/config.ts ```ts export default defineUserConfig({ // 现在任何带有 `.snippet.md` 扩展名的文件都不会呈现为页面 pagePatterns: ['**/*.md', '!**/*.snippet.md', '!.vuepress', '!node_modules'], // [!code ++] theme: plumeTheme({ plugins: { markdownEnhance: { include: true, }, } }) }) ``` ::: ### 示例 在项目中有一个 `foo.snippet.md` 文件: :::: code-tabs @tab foo.snippet.md ```md ### 三级标题 这是 foo.snippet.md 文件中的内容。 ::: info 提示容器包括的内容 ::: 这里是被 `` 包裹的内容。 通过 `` 来引入。 ``` :::: 使用 `` 导入文件: :::: demo-wrapper title="Include by file" :::: 使用 `` 导入文件内的 5 到 7 行: :::: demo-wrapper title="Include by lines" :::: 使用 `` 导入 `snippet` 区域 :::: demo-wrapper title="Include by file region" :::: ## 代码演示 代码演示 默认不启用,你可以通过配置来启用它。 ::: code-tabs @tab .vuepress/config.ts ```ts export default defineUserConfig({ theme: plumeTheme({ plugins: { markdownEnhance: { demo: true, }, } }) }) ``` ::: ### 语法 ```` md ::: [类型]-demo 可选的标题文字 ```html ``` ```json // json block 作为插件配置存放处 { // 放置你的配置 (可选的) } ``` ::: ```` ::: tip 提示 JSON 块是可选的,可用的配置详见[配置](https://vuepress-theme-hope.github.io/v2/md-enhance/zh/config.html) ::: 插件支持三种类型 - normal(默认) - vue - react ### 可用的语言 你可以在演示块中使用不同语言。 当你设置一些不能在浏览器上直接运行的语言时,由于插件无法解析它们,因此网页演示将被禁用。插件只显示代码。同时提供一个 "在 CodePen 中打开" 按钮允许用户直接在 CodePen 打开并浏览代码。 可用的 HTML 语言: - `"html"` (默认) - `"slim"` - `"haml"` - `"markdown"` 可用的 JS 语言: - `"javascript"` (default) - `"coffeescript"` - `"babel"` - `"livescript"` - `"typescript"` > 你也可以在代码块中使用 `js`, `ts`, `coffee` 和 `ls。` 可用的 CSS 语言: - `"css"` (default) - `"less"` - `"scss"` - `"sass"` - `"stylus"` ### 不支持的语言 ::: normal-demo 一个使用浏览器不支持解析语言 Demo ```md # 标题 十分强大 ``` ```ts const message: string = 'VuePress Theme Hope' document.querySelector('h1').innerHTML = message ``` ```scss h1 { font-style: italic; + p { color: red; } } ``` ::: :::: details 代码 ```` md ::: normal-demo 一个使用浏览器不支持解析语言 Demo ```md # 标题 十分强大 ``` ```ts const message: string = 'VuePress Theme Hope' document.querySelector('h1').innerHTML = message ``` ```scss h1 { font-style: italic; + p { color: red; } } ``` ::: ```` :::: ### 普通代码演示 格式: ```` md ::: normal-demo 可选的标题文字 ```html ``` ```js // js code ``` ```css /* css code */ ``` ```json // 配置 (可选) { "jsLib": [ // ... ], "cssLib": [ // ... ] } ``` ::: ```` ::: warning 注意事项 我们使用 `"ShadowDOM"` 进行样式隔离,并已经将 `document` 替换为了 `shadowRoot` 对象。如果需要访问页面的 `document,请访问` `window.document`。 ::: #### 例子 ::: normal-demo Demo 演示 ```html非常强大!
``` ```js document.querySelector('#very').addEventListener('click', () => { alert('非常强大') }) ``` ```css span { color: red; } ``` ::: :::: details 代码 ```` md ::: normal-demo Demo 演示 ```html非常强大!
``` ```js document.querySelector('#very').addEventListener('click', () => { alert('非常强大') }) ``` ```css span { color: red; } ``` ::: ```` :::: ### Vue 代码演示 #### 格式 ```` md ::: vue-demo 可选的标题文字 ```vueHello Word is
{{ message }}!
Hello Word is
{{ message }}!
Hello Word !
{message}
Hello Word !
{message}