From 94d7578ae4d1e4f9b17eadcc50515a85fc91a03a Mon Sep 17 00:00:00 2001 From: Mister-Hope Date: Fri, 25 Oct 2024 02:36:11 +0800 Subject: [PATCH 1/2] feat: add plugin-markdown-include --- .../plugin-markdown-include/package.json | 55 +++++++++++++++++++ .../plugin-markdown-include/rollup.config.ts | 5 ++ .../plugin-markdown-include/src/node/index.ts | 2 + .../src/node/markdownIncludePlugin.ts | 40 ++++++++++++++ .../src/node/options.ts | 6 ++ .../tsconfig.build.json | 9 +++ pnpm-lock.yaml | 30 ++++++++++ tsconfig.build.json | 3 + 8 files changed, 150 insertions(+) create mode 100644 plugins/markdown/plugin-markdown-include/package.json create mode 100644 plugins/markdown/plugin-markdown-include/rollup.config.ts create mode 100644 plugins/markdown/plugin-markdown-include/src/node/index.ts create mode 100644 plugins/markdown/plugin-markdown-include/src/node/markdownIncludePlugin.ts create mode 100644 plugins/markdown/plugin-markdown-include/src/node/options.ts create mode 100644 plugins/markdown/plugin-markdown-include/tsconfig.build.json diff --git a/plugins/markdown/plugin-markdown-include/package.json b/plugins/markdown/plugin-markdown-include/package.json new file mode 100644 index 0000000000..f0246a537b --- /dev/null +++ b/plugins/markdown/plugin-markdown-include/package.json @@ -0,0 +1,55 @@ +{ + "name": "@vuepress/plugin-markdown-include", + "version": "2.0.0-rc.56", + "description": "VuePress plugin - markdown include", + "keywords": [ + "vuepress-plugin", + "vuepress", + "plugin", + "markdown", + "include" + ], + "homepage": "https://ecosystem.vuejs.press/plugins/markdown/markdown-include.html", + "bugs": { + "url": "https://github.com/vuepress/ecosystem/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vuepress/ecosystem.git", + "directory": "plugins/markdown/plugin-markdown-include" + }, + "license": "MIT", + "author": { + "name": "Mr.Hope", + "email": "mister-hope@outlook.com", + "url": "https://mister-hope.com" + }, + "type": "module", + "exports": { + ".": "./lib/node/index.js", + "./figure.css": "./lib/client/styles/figure.css", + "./mark.css": "./lib/client/styles/mark.css", + "./package.json": "./package.json" + }, + "main": "./lib/node/index.js", + "types": "./lib/node/index.d.ts", + "files": [ + "lib" + ], + "scripts": { + "build": "tsc -b tsconfig.build.json", + "bundle": "rollup -c rollup.config.ts --configPlugin esbuild", + "clean": "rimraf --glob ./lib ./*.tsbuildinfo" + }, + "dependencies": { + "@mdit/plugin-include": "^0.13.1", + "@types/markdown-it": "^14.1.2", + "@vuepress/helper": "workspace:*" + }, + "peerDependencies": { + "vuepress": "2.0.0-rc.18" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/plugins/markdown/plugin-markdown-include/rollup.config.ts b/plugins/markdown/plugin-markdown-include/rollup.config.ts new file mode 100644 index 0000000000..c5946cd8be --- /dev/null +++ b/plugins/markdown/plugin-markdown-include/rollup.config.ts @@ -0,0 +1,5 @@ +import { rollupBundle } from '../../../scripts/rollup.js' + +export default rollupBundle('node/index', { + external: ['@mdit/plugin-include'], +}) diff --git a/plugins/markdown/plugin-markdown-include/src/node/index.ts b/plugins/markdown/plugin-markdown-include/src/node/index.ts new file mode 100644 index 0000000000..fe4d721970 --- /dev/null +++ b/plugins/markdown/plugin-markdown-include/src/node/index.ts @@ -0,0 +1,2 @@ +export * from './markdownIncludePlugin.js' +export type * from './options.js' diff --git a/plugins/markdown/plugin-markdown-include/src/node/markdownIncludePlugin.ts b/plugins/markdown/plugin-markdown-include/src/node/markdownIncludePlugin.ts new file mode 100644 index 0000000000..88ce73d2ec --- /dev/null +++ b/plugins/markdown/plugin-markdown-include/src/node/markdownIncludePlugin.ts @@ -0,0 +1,40 @@ +import type { IncludeEnv } from '@mdit/plugin-include' +import { include } from '@mdit/plugin-include' +import type { Plugin } from 'vuepress/core' +import type { MarkdownEnv } from 'vuepress/markdown' +import { path } from 'vuepress/utils' +import type { MarkdownIncludePluginOptions } from './options.js' + +export const markdownIncludePlugin = + (options: MarkdownIncludePluginOptions): Plugin => + (app) => { + const source = app.dir.source() + + return { + name: '@vuepress/plugin-markdown-include', + + extendsMarkdown: (md) => { + md.use(include, { + currentPath: (env: MarkdownEnv) => env.filePath, + ...options, + }) + }, + extendsPage: (page): void => { + const { markdownEnv, frontmatter, filePathRelative } = page + const { includedFiles = [] } = markdownEnv as IncludeEnv + + // mark included files as page deps + page.deps.push(...includedFiles) + + // add included files as git deps + ;((frontmatter.gitInclude as string[] | undefined) ??= []).push( + ...includedFiles.map((file) => + path.relative( + path.resolve(source, filePathRelative, '..'), + path.resolve(source, filePathRelative, file), + ), + ), + ) + }, + } + } diff --git a/plugins/markdown/plugin-markdown-include/src/node/options.ts b/plugins/markdown/plugin-markdown-include/src/node/options.ts new file mode 100644 index 0000000000..90ff319002 --- /dev/null +++ b/plugins/markdown/plugin-markdown-include/src/node/options.ts @@ -0,0 +1,6 @@ +import type { MarkdownItIncludeOptions } from '@mdit/plugin-include' + +export type MarkdownIncludePluginOptions = Omit< + MarkdownItIncludeOptions, + 'currentPath' +> diff --git a/plugins/markdown/plugin-markdown-include/tsconfig.build.json b/plugins/markdown/plugin-markdown-include/tsconfig.build.json new file mode 100644 index 0000000000..85b37d29a2 --- /dev/null +++ b/plugins/markdown/plugin-markdown-include/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "../../../tsconfig.build.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./lib" + }, + "include": ["./src"], + "references": [{ "path": "../../../tools/helper/tsconfig.build.json" }] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aeca364f1e..a95487c126 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -717,6 +717,21 @@ importers: specifier: 2.0.0-rc.18 version: 2.0.0-rc.18(@vuepress/bundler-vite@2.0.0-rc.18(@types/node@22.7.9)(jiti@1.21.6)(lightningcss@1.27.0)(sass-embedded@1.80.4)(sass@1.80.4)(terser@5.36.0)(tsx@4.19.1)(typescript@5.6.3)(yaml@2.4.5))(@vuepress/bundler-webpack@2.0.0-rc.18(esbuild@0.23.1)(typescript@5.6.3))(typescript@5.6.3)(vue@3.5.12(typescript@5.6.3)) + plugins/markdown/plugin-markdown-include: + dependencies: + '@mdit/plugin-include': + specifier: ^0.13.1 + version: 0.13.1(markdown-it@14.1.0) + '@types/markdown-it': + specifier: ^14.1.2 + version: 14.1.2 + '@vuepress/helper': + specifier: workspace:* + version: link:../../../tools/helper + vuepress: + specifier: 2.0.0-rc.18 + version: 2.0.0-rc.18(@vuepress/bundler-vite@2.0.0-rc.18(@types/node@22.7.9)(jiti@1.21.6)(lightningcss@1.27.0)(sass-embedded@1.80.4)(sass@1.80.4)(terser@5.36.0)(tsx@4.19.1)(typescript@5.6.3)(yaml@2.4.5))(@vuepress/bundler-webpack@2.0.0-rc.18(esbuild@0.23.1)(typescript@5.6.3))(typescript@5.6.3)(vue@3.5.12(typescript@5.6.3)) + plugins/markdown/plugin-markdown-math: dependencies: '@mdit/plugin-katex-slim': @@ -2499,6 +2514,14 @@ packages: markdown-it: optional: true + '@mdit/plugin-include@0.13.1': + resolution: {integrity: sha512-rWGJ3/L2Ocv+8KDNoXPb6H1f+aLqx0FzJKcNqJl+0HOAEScuyKS1GC4OxeWefVMQ87QoG/mYqoCbpDsJeiDbLQ==} + peerDependencies: + markdown-it: ^14.1.0 + peerDependenciesMeta: + markdown-it: + optional: true + '@mdit/plugin-katex-slim@0.13.1': resolution: {integrity: sha512-OO4n51aLo0Igv0aICXOaTO5+ZW/jW8Lnl8u1kxs2zkFVNUqpqNHAo8l4QxtscQk5L4XhXGgaTj2ZgAv7rtH96Q==} engines: {node: '>= 18'} @@ -9911,6 +9934,13 @@ snapshots: optionalDependencies: markdown-it: 14.1.0 + '@mdit/plugin-include@0.13.1(markdown-it@14.1.0)': + dependencies: + '@types/markdown-it': 14.1.2 + upath: 2.0.1 + optionalDependencies: + markdown-it: 14.1.0 + '@mdit/plugin-katex-slim@0.13.1(katex@0.16.11)(markdown-it@14.1.0)': dependencies: '@mdit/plugin-tex': 0.13.1(markdown-it@14.1.0) diff --git a/tsconfig.build.json b/tsconfig.build.json index 32e9c295ed..c4a7ad3486 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -51,6 +51,9 @@ "path": "./plugins/markdown/plugin-markdown-hint/tsconfig.build.json" }, { "path": "./plugins/markdown/plugin-markdown-image/tsconfig.build.json" }, + { + "path": "./plugins/markdown/plugin-markdown-include/tsconfig.build.json" + }, { "path": "./plugins/markdown/plugin-markdown-math/tsconfig.build.json" }, { "path": "./plugins/markdown/plugin-markdown-stylize/tsconfig.build.json" From 2a3aa4f29c90727a9ca5d6f26fa4ccc3bc9241a3 Mon Sep 17 00:00:00 2001 From: Mister-Hope Date: Fri, 25 Oct 2024 03:35:46 +0800 Subject: [PATCH 2/2] docs: add docs --- docs/.vuepress/config.ts | 6 + docs/.vuepress/configs/sidebar/en.ts | 1 + docs/.vuepress/configs/sidebar/zh.ts | 1 + docs/package.json | 1 + docs/plugins/markdown/demo.snippet.md | 13 + docs/plugins/markdown/markdown-include.md | 357 +++++++++++++++++++ docs/zh/plugins/markdown/demo.snippet.md | 13 + docs/zh/plugins/markdown/markdown-include.md | 357 +++++++++++++++++++ pnpm-lock.yaml | 3 + 9 files changed, 752 insertions(+) create mode 100644 docs/plugins/markdown/demo.snippet.md create mode 100644 docs/plugins/markdown/markdown-include.md create mode 100644 docs/zh/plugins/markdown/demo.snippet.md create mode 100644 docs/zh/plugins/markdown/markdown-include.md diff --git a/docs/.vuepress/config.ts b/docs/.vuepress/config.ts index 3f7bff54bb..39bdd11505 100644 --- a/docs/.vuepress/config.ts +++ b/docs/.vuepress/config.ts @@ -9,6 +9,7 @@ import { docsearchPlugin } from '@vuepress/plugin-docsearch' import { feedPlugin } from '@vuepress/plugin-feed' import { markdownExtPlugin } from '@vuepress/plugin-markdown-ext' import { markdownImagePlugin } from '@vuepress/plugin-markdown-image' +import { markdownIncludePlugin } from '@vuepress/plugin-markdown-include' import { markdownMathPlugin } from '@vuepress/plugin-markdown-math' import { markdownStylizePlugin } from '@vuepress/plugin-markdown-stylize' import { redirectPlugin } from '@vuepress/plugin-redirect' @@ -98,6 +99,9 @@ export default defineUserConfig({ mark: true, size: true, }), + markdownIncludePlugin({ + deep: true, + }), markdownMathPlugin({ type: 'katex', }), @@ -167,4 +171,6 @@ export default defineUserConfig({ : [], cachePlugin(), ], + + pagePatterns: ['**/*.md', '!**/*.snippet.md', '!.vuepress', '!node_modules'], }) diff --git a/docs/.vuepress/configs/sidebar/en.ts b/docs/.vuepress/configs/sidebar/en.ts index 15fbb80dcf..50de87cd1b 100644 --- a/docs/.vuepress/configs/sidebar/en.ts +++ b/docs/.vuepress/configs/sidebar/en.ts @@ -101,6 +101,7 @@ export const sidebarEn: SidebarOptions = { 'markdown-container', 'markdown-ext', 'markdown-image', + 'markdown-include', 'markdown-hint', 'markdown-math', 'markdown-stylize', diff --git a/docs/.vuepress/configs/sidebar/zh.ts b/docs/.vuepress/configs/sidebar/zh.ts index e2542f78c9..ead2ad709f 100644 --- a/docs/.vuepress/configs/sidebar/zh.ts +++ b/docs/.vuepress/configs/sidebar/zh.ts @@ -101,6 +101,7 @@ export const sidebarZh: SidebarOptions = { 'markdown-container', 'markdown-ext', 'markdown-image', + 'markdown-include', 'markdown-hint', 'markdown-math', 'markdown-stylize', diff --git a/docs/package.json b/docs/package.json index 084ee3f0c9..15e0de7a40 100644 --- a/docs/package.json +++ b/docs/package.json @@ -20,6 +20,7 @@ "@vuepress/plugin-feed": "workspace:*", "@vuepress/plugin-markdown-ext": "workspace:*", "@vuepress/plugin-markdown-image": "workspace:*", + "@vuepress/plugin-markdown-include": "workspace:*", "@vuepress/plugin-markdown-math": "workspace:*", "@vuepress/plugin-markdown-stylize": "workspace:*", "@vuepress/plugin-markdown-tab": "workspace:*", diff --git a/docs/plugins/markdown/demo.snippet.md b/docs/plugins/markdown/demo.snippet.md new file mode 100644 index 0000000000..798f8ccbff --- /dev/null +++ b/docs/plugins/markdown/demo.snippet.md @@ -0,0 +1,13 @@ +## Heading 2 + + + +Contents containing **bolded text** and some markdown enhance features: + + + +::: tip + +Hey how are **you**? :smile: + +::: diff --git a/docs/plugins/markdown/markdown-include.md b/docs/plugins/markdown/markdown-include.md new file mode 100644 index 0000000000..85b9cdd9bc --- /dev/null +++ b/docs/plugins/markdown/markdown-include.md @@ -0,0 +1,357 @@ +# markdown-include + + + +Add additional features to your markdown includes. + +## Usage + +```bash +npm i -D @vuepress/plugin-markdown-include@next +``` + +```ts +import { markdownIncludePlugin } from '@vuepress/plugin-markdown-include' + +export default { + plugins: [ + markdownIncludePlugin({ + // options + }), + ], +} +``` + +## Syntax + +Use `` to include a file. + +To partially import the file, you can specify the range of lines to be included: + +- `` +- `` +- `` + +Also, you can include file region: + +- `` + +:::: info File region + +File region is a concept in vscode, where the region content is surrounded by `#region` and `#endregion` comments. + +Here are some examples: + +::: code-tabs#language + +@tab HTML + +```html + + + + + + + Document + + + +

+ 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. +

+ +

+ 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. +

+ + +``` + +@tab Markdown + +```md +## Hello world + + + +Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates +inventore iure quo aut doloremque, ipsum ab voluptatem ipsa, velit laborum +illo quae omnis reiciendis hic, ut dolorem non debitis in! + + + +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. +``` + +@tab TS + +```ts +import { include } from '@mdit/plugin-include' +import MarkdownIt from 'markdown-it' + +// #region snippet +const mdIt = MarkdownIt().use(include, { + // your options, currentPath is required + currentPath: (env) => env.filePath, +}) +// #endregion snippet + +mdIt.render('', { + filePath: 'path/to/current/file.md', +}) +``` + +@tab JS + +```js +const { include } = require('@mdit/plugin-include') +const MarkdownIt = require('markdown-it') + +// #region snippet +const mdIt = MarkdownIt().use(include, { + // your options, currentPath is required + currentPath: (env) => env.filePath, +}) +// #endregion snippet + +mdIt.render('', { + filePath: 'path/to/current/file.md', +}) +``` + +@tab css + +```css +html, +body { + margin: 0; + padding: 0; +} + +/* #region snippet */ +h1 { + font-size: 1.5rem; +} +/* #endregion snippet */ + +h2 { + font-size: 1.2rem; +} +``` + +@tab Less + +```less +html, +body { + margin: 0; + padding: 0; +} + +/* #region snippet */ +h1 { + font-size: 1.5rem; +} +/* #endregion snippet */ + +h2 { + font-size: 1.2rem; +} +``` + +@tab Sass + +```scss +html, +body { + margin: 0; + padding: 0; +} + +/* #region snippet */ +h1 { + font-size: 1.5rem; +} +/* #endregion snippet */ + +h2 { + font-size: 1.2rem; +} +``` + +@tab Java + +```java +public class HelloWorld { + // #region snippet + public static void main(String args[]){ + System.out.println("Hello World"); + } + // #endregion snippet +} +``` + +@tab Python + +```py +class MyClass: + msg = "world" + + #region snippet + def sayHello(self): + print("Hello " + self.msg + "!") + #region snippet + + def sayBye(self): + print("Bye " + self.msg + "!") +``` + +@tab Visual Basic + +```vb +Imports System + +Module Module1 + # Region snippet + Sub Main() + Console.WriteLine("Hello World!") + Console.WriteLine("Press Enter Key to Exit.") + Console.ReadLine() + End Sub + # EndRegion +End Module +``` + +@tab Bat + +```bat +>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" +if '%errorlevel%' NEQ '0' ( +echo Requesting administrative privileges... +goto UACPrompt +) else ( goto gotAdmin ) + +::#region snippet +:UACPrompt +echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" +echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" +"%temp%\getadmin.vbs" +exit /B +::#endregion snippet + +:gotAdmin +if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) +pushd "%CD%" +CD /D "%~dp0" +``` + +@tab C\# + +```cs +using System; + +namespace HelloWorldApp { + + class Geeks { + + // #region snippet + static void Main(string[] args) { + + // statement + // printing Hello World! + Console.WriteLine("Hello World!"); + + // To prevents the screen from + // running and closing quickly + Console.ReadKey(); + } + // #endregion snippet + } +} +``` + +@tab C/C++ + +```cpp +#include +#include + +std::vector v; + +#pragma region snippet +int f() { + for (int item : v) std::cout << item << std::endl; + return v.size(); +} +#pragma endregion snippet + +int main() { + int n, u; + std::cin >> n; + for (int i = 1; i <= n; ++i) { + std::cin >> u; + v.push_back(u); + } + std::cout << f(); + return 0; +} +``` + +::: + +:::: + +## Demo + +``: + + + +``: + + + +``: + + + +## Options + +### resolvePath + +- Type: `(path: string, cwd: string | null) => string` +- Default: `(path) => path` +- Details: Handle the include file path. + +### deep + +- Type: `boolean` +- Details: Whether enable figure support. + +### useComment + +- Type: `boolean` +- Default: `true` +- Details: Whether use `` instead of `@include: xxx` to include files. + +### resolveImagePath + +- Type: `boolean` +- Default: `true` +- Details: Whether resolve the image related path in the included Markdown file. + +### resolveLinkPath + +- Type: `boolean` +- Default: `true` +- Details: Whether resolve the related file link path in the included Markdown file. diff --git a/docs/zh/plugins/markdown/demo.snippet.md b/docs/zh/plugins/markdown/demo.snippet.md new file mode 100644 index 0000000000..b3cec0049a --- /dev/null +++ b/docs/zh/plugins/markdown/demo.snippet.md @@ -0,0 +1,13 @@ +## 二级标题 + + + +内容包含**加粗文字**和一些其他增强内容: + + + +::: tip + +你最近怎么样了? :smile: + +::: diff --git a/docs/zh/plugins/markdown/markdown-include.md b/docs/zh/plugins/markdown/markdown-include.md new file mode 100644 index 0000000000..a5c93b5c9c --- /dev/null +++ b/docs/zh/plugins/markdown/markdown-include.md @@ -0,0 +1,357 @@ +# markdown-include + + + +向你的 Markdown 图像添加附加功能。 + +## 使用方法 + +```bash +npm i -D @vuepress/plugin-markdown-include@next +``` + +```ts +import { markdownIncludePlugin } from '@vuepress/plugin-markdown-include' + +export default { + plugins: [ + markdownIncludePlugin({ + // 选项 + }), + ], +} +``` + +## 语法 + +使用 `` 导入文件。 + +如果要部分导入文件,你可以指定导入的行数 + +- `` +- `` +- `` + +同时你也可以导入文件区域: + +- `` + +:::: info 文件区域 + +文件区域是 vscode 中的一个概念,区域内容被 `#region` 和 `#endregion` 注释包围。 + +这里有些例子: + +::: code-tabs#language + +@tab HTML + +```html + + + + + + + Document + + + +

+ 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. +

+ +

+ 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. +

+ + +``` + +@tab Markdown + +```md +## Hello world + + + +Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptates +inventore iure quo aut doloremque, ipsum ab voluptatem ipsa, velit laborum +illo quae omnis reiciendis hic, ut dolorem non debitis in! + + + +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. +``` + +@tab TS + +```ts +import { include } from '@mdit/plugin-include' +import MarkdownIt from 'markdown-it' + +// #region snippet +const mdIt = MarkdownIt().use(include, { + // your options, currentPath is required + currentPath: (env) => env.filePath, +}) +// #endregion snippet + +mdIt.render('', { + filePath: 'path/to/current/file.md', +}) +``` + +@tab JS + +```js +const { include } = require('@mdit/plugin-include') +const MarkdownIt = require('markdown-it') + +// #region snippet +const mdIt = MarkdownIt().use(include, { + // your options, currentPath is required + currentPath: (env) => env.filePath, +}) +// #endregion snippet + +mdIt.render('', { + filePath: 'path/to/current/file.md', +}) +``` + +@tab css + +```css +html, +body { + margin: 0; + padding: 0; +} + +/* #region snippet */ +h1 { + font-size: 1.5rem; +} +/* #endregion snippet */ + +h2 { + font-size: 1.2rem; +} +``` + +@tab Less + +```less +html, +body { + margin: 0; + padding: 0; +} + +/* #region snippet */ +h1 { + font-size: 1.5rem; +} +/* #endregion snippet */ + +h2 { + font-size: 1.2rem; +} +``` + +@tab Sass + +```scss +html, +body { + margin: 0; + padding: 0; +} + +/* #region snippet */ +h1 { + font-size: 1.5rem; +} +/* #endregion snippet */ + +h2 { + font-size: 1.2rem; +} +``` + +@tab Java + +```java +public class HelloWorld { + // #region snippet + public static void main(String args[]){ + System.out.println("Hello World"); + } + // #endregion snippet +} +``` + +@tab Python + +```py +class MyClass: + msg = "world" + + #region snippet + def sayHello(self): + print("Hello " + self.msg + "!") + #region snippet + + def sayBye(self): + print("Bye " + self.msg + "!") +``` + +@tab Visual Basic + +```vb +Imports System + +Module Module1 + # Region snippet + Sub Main() + Console.WriteLine("Hello World!") + Console.WriteLine("Press Enter Key to Exit.") + Console.ReadLine() + End Sub + # EndRegion +End Module +``` + +@tab Bat + +```bat +>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" +if '%errorlevel%' NEQ '0' ( +echo Requesting administrative privileges... +goto UACPrompt +) else ( goto gotAdmin ) + +::#region snippet +:UACPrompt +echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" +echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" +"%temp%\getadmin.vbs" +exit /B +::#endregion snippet + +:gotAdmin +if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) +pushd "%CD%" +CD /D "%~dp0" +``` + +@tab C\# + +```cs +using System; + +namespace HelloWorldApp { + + class Geeks { + + // #region snippet + static void Main(string[] args) { + + // statement + // printing Hello World! + Console.WriteLine("Hello World!"); + + // To prevents the screen from + // running and closing quickly + Console.ReadKey(); + } + // #endregion snippet + } +} +``` + +@tab C/C++ + +```cpp +#include +#include + +std::vector v; + +#pragma region snippet +int f() { + for (int item : v) std::cout << item << std::endl; + return v.size(); +} +#pragma endregion snippet + +int main() { + int n, u; + std::cin >> n; + for (int i = 1; i <= n; ++i) { + std::cin >> u; + v.push_back(u); + } + std::cout << f(); + return 0; +} +``` + +::: + +:::: + +## 演示 + +``: + + + +``: + + + +``: + + + +## 配置项 + +### resolvePath + +- 类型:`(path: string, cwd: string | null) => string` +- 默认值:`(path) => path` +- 详情:处理 include 文件路径。 + +### deep + +- 类型:`boolean` +- 详情:是否启用图片 Figure 支持。 + +### useComment + +- 类型:`boolean` +- 默认值:`true` +- 详情:是否使用 `` 代替 `@include: xxx` 导入文件。 + +### resolveImagePath + +- 类型:`boolean` +- 默认值:`true` +- 详情:是否解析包含的 Markdown 文件的里的相对图像路径。 + +### resolveLinkPath + +- 类型:`boolean` +- 默认值:`true` +- 详情:是否解析包含的 Markdown 文件的里的文件相对路径。 diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a95487c126..f084c075ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -155,6 +155,9 @@ importers: '@vuepress/plugin-markdown-image': specifier: workspace:* version: link:../plugins/markdown/plugin-markdown-image + '@vuepress/plugin-markdown-include': + specifier: workspace:* + version: link:../plugins/markdown/plugin-markdown-include '@vuepress/plugin-markdown-math': specifier: workspace:* version: link:../plugins/markdown/plugin-markdown-math