diff --git a/.prettierignore b/.prettierignore index c9a3bf07696b..3e33aa18a846 100644 --- a/.prettierignore +++ b/.prettierignore @@ -11,3 +11,9 @@ packages/**/*.d.ts !packages/**/test/*.js !packages/**/types/*.d.ts !.vuepress/** + +docs/md-enhance/src/guide/demo.md +docs/md-enhance/src/zh/guide/demo.md + +test/src/guide/markdown.md +test/src/zh/guide/markdown.md diff --git a/docs/add-this/src/.vuepress/config.js b/docs/add-this/src/.vuepress/config.js index a663d4d4f3b7..2e61dadb803f 100644 --- a/docs/add-this/src/.vuepress/config.js +++ b/docs/add-this/src/.vuepress/config.js @@ -17,15 +17,15 @@ module.exports = config({ logo: "/logo.svg", nav: [ - { text: "Home", icon: "homefill", link: "/" }, + { text: "Home", icon: "home", link: "/" }, { text: "Guide", - icon: "creativefill", + icon: "creative", link: "/guide/", }, { text: "Config", - icon: "configuration", + icon: "config", link: "/config/", }, ], @@ -51,15 +51,15 @@ module.exports = config({ locales: { "/zh/": { nav: [ - { text: "主页", icon: "homefill", link: "/zh/" }, + { text: "主页", icon: "home", link: "/zh/" }, { text: "指南", - icon: "creativefill", + icon: "creative", link: "/zh/guide/", }, { text: "配置", - icon: "configuration", + icon: "config", link: "/zh/config/", }, ], diff --git a/docs/add-this/src/.vuepress/styles/index.styl b/docs/add-this/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/add-this/src/.vuepress/styles/index.styl +++ b/docs/add-this/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/add-this/src/config.md b/docs/add-this/src/config.md index 53b673586645..1ee246599940 100644 --- a/docs/add-this/src/config.md +++ b/docs/add-this/src/config.md @@ -1,6 +1,6 @@ --- title: API Config -icon: configuration +icon: config --- ## pubid diff --git a/docs/add-this/src/guide.md b/docs/add-this/src/guide.md index d6fe3a15786a..dcee98a3a9b8 100644 --- a/docs/add-this/src/guide.md +++ b/docs/add-this/src/guide.md @@ -1,6 +1,6 @@ --- title: Guide -icon: creativefill +icon: creative --- ## Register diff --git a/docs/add-this/src/readme.md b/docs/add-this/src/readme.md index 2b8c6cf226bd..fe9d6b63bf85 100644 --- a/docs/add-this/src/readme.md +++ b/docs/add-this/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-add-this -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-add-this tagline: AddThis plugin for vuepress diff --git a/docs/add-this/src/zh/config.md b/docs/add-this/src/zh/config.md index cbf30f2a6412..a74c94abb3cd 100644 --- a/docs/add-this/src/zh/config.md +++ b/docs/add-this/src/zh/config.md @@ -1,6 +1,6 @@ --- title: 配置 -icon: configuration +icon: config --- ## pubid diff --git a/docs/add-this/src/zh/guide.md b/docs/add-this/src/zh/guide.md index 6f005bfeb1f8..28da3e1ca70e 100644 --- a/docs/add-this/src/zh/guide.md +++ b/docs/add-this/src/zh/guide.md @@ -1,6 +1,6 @@ --- title: 指南 -icon: creativefill +icon: creative --- ## 注册 diff --git a/docs/add-this/src/zh/readme.md b/docs/add-this/src/zh/readme.md index 63095773d51b..730fe6291e64 100644 --- a/docs/add-this/src/zh/readme.md +++ b/docs/add-this/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-add-this -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-add-this tagline: 为 VuePress 提供 addthis 支持 diff --git a/docs/comment/src/.vuepress/config.js b/docs/comment/src/.vuepress/config.js index 73a9e0265902..c00900f878da 100644 --- a/docs/comment/src/.vuepress/config.js +++ b/docs/comment/src/.vuepress/config.js @@ -13,14 +13,14 @@ module.exports = config({ logo: "/logo.svg", nav: [ - { text: "Home", icon: "homefill", link: "/" }, + { text: "Home", icon: "home", link: "/" }, { text: "Guide", - icon: "creativefill", + icon: "creative", items: [ { text: "Page Info", - icon: "infofill", + icon: "info", link: "/guide/page-info/", }, { text: "Valine", icon: "valine", link: "/guide/valine/" }, @@ -29,9 +29,9 @@ module.exports = config({ }, { text: "Config", - icon: "configuration", + icon: "config", items: [ - { text: "Config", icon: "configuration", link: "/config/" }, + { text: "Config", icon: "config", link: "/config/" }, { text: "Valine", icon: "valine", @@ -91,14 +91,14 @@ module.exports = config({ locales: { "/zh/": { nav: [ - { text: "主页", icon: "homefill", link: "/zh/" }, + { text: "主页", icon: "home", link: "/zh/" }, { text: "指南", - icon: "creativefill", + icon: "creative", items: [ { text: "页面信息", - icon: "infofill", + icon: "info", link: "/zh/guide/page-info/", }, { text: "Valine", icon: "valine", link: "/zh/guide/valine/" }, @@ -107,9 +107,9 @@ module.exports = config({ }, { text: "配置", - icon: "configuration", + icon: "config", items: [ - { text: "配置", icon: "configuration", link: "/zh/config/" }, + { text: "配置", icon: "config", link: "/zh/config/" }, { text: "Valine", icon: "valine", link: "/zh/config/valine/" }, { text: "Vssue", icon: "vssue", link: "/zh/config/vssue/" }, ], diff --git a/docs/comment/src/.vuepress/styles/index.styl b/docs/comment/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/comment/src/.vuepress/styles/index.styl +++ b/docs/comment/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/comment/src/config/readme.md b/docs/comment/src/config/readme.md index 754c7e8f20be..158333eb4d14 100644 --- a/docs/comment/src/config/readme.md +++ b/docs/comment/src/config/readme.md @@ -1,6 +1,6 @@ --- title: API Config -icon: configuration +icon: config --- ## baseLang diff --git a/docs/comment/src/guide/page-info.md b/docs/comment/src/guide/page-info.md index bab1a1f35546..e77f3fa91984 100644 --- a/docs/comment/src/guide/page-info.md +++ b/docs/comment/src/guide/page-info.md @@ -1,6 +1,6 @@ --- title: Page information -icon: infofill +icon: info --- The `` component is enabled globally by default. You can disable it by setting `pageInfo: false` in `Front Matter` of a specific page. diff --git a/docs/comment/src/guide/readme.md b/docs/comment/src/guide/readme.md index a88056148f32..114035618819 100644 --- a/docs/comment/src/guide/readme.md +++ b/docs/comment/src/guide/readme.md @@ -1,5 +1,5 @@ --- -icon: creativefill +icon: creative --- # Guide diff --git a/docs/comment/src/guide/vssue.md b/docs/comment/src/guide/vssue.md index 3071173d6188..dd2637a0dee8 100644 --- a/docs/comment/src/guide/vssue.md +++ b/docs/comment/src/guide/vssue.md @@ -1,5 +1,5 @@ --- -icon: creativefill +icon: creative --- # Using Vssue diff --git a/docs/comment/src/readme.md b/docs/comment/src/readme.md index 253c8a0274eb..716fbca024e3 100644 --- a/docs/comment/src/readme.md +++ b/docs/comment/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-comment -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-comment tagline: Comment and visitors plugin for vuepress diff --git a/docs/comment/src/zh/config/readme.md b/docs/comment/src/zh/config/readme.md index 8b147136a657..554c07a537b3 100644 --- a/docs/comment/src/zh/config/readme.md +++ b/docs/comment/src/zh/config/readme.md @@ -1,6 +1,6 @@ --- title: 配置 -icon: configuration +icon: config --- ## baseLang diff --git a/docs/comment/src/zh/guide/page-info.md b/docs/comment/src/zh/guide/page-info.md index 285bde51eee2..368080fc4b5f 100644 --- a/docs/comment/src/zh/guide/page-info.md +++ b/docs/comment/src/zh/guide/page-info.md @@ -1,6 +1,6 @@ --- title: 页面信息 -icon: infofill +icon: info --- `` 组件默认全局启用。你可以在特定页面的 `Front Matter` 中设置 `pageInfo: false` 来局部禁用它。 diff --git a/docs/comment/src/zh/guide/readme.md b/docs/comment/src/zh/guide/readme.md index 6698b433dfc6..cdf7e9f0232d 100644 --- a/docs/comment/src/zh/guide/readme.md +++ b/docs/comment/src/zh/guide/readme.md @@ -1,6 +1,6 @@ --- title: 指南 -icon: creativefill +icon: creative --- 此插件暴露两个组件,路径为 `@mr-hope/vuepress-plugin-comment/<组件名>.vue`。请在你的主题中手动引入。 diff --git a/docs/comment/src/zh/guide/vssue.md b/docs/comment/src/zh/guide/vssue.md index a835c766d400..866c2e896a09 100644 --- a/docs/comment/src/zh/guide/vssue.md +++ b/docs/comment/src/zh/guide/vssue.md @@ -1,5 +1,5 @@ --- -icon: creativefill +icon: creative --- # 使用 Vssue diff --git a/docs/comment/src/zh/readme.md b/docs/comment/src/zh/readme.md index eab1b7e326c9..38c76dede2c8 100644 --- a/docs/comment/src/zh/readme.md +++ b/docs/comment/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-comment -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-comment tagline: 评论与阅读量插件 diff --git a/docs/copy-code/src/.vuepress/config.js b/docs/copy-code/src/.vuepress/config.js index 20f0c464c7f8..26866c26b178 100644 --- a/docs/copy-code/src/.vuepress/config.js +++ b/docs/copy-code/src/.vuepress/config.js @@ -22,15 +22,15 @@ module.exports = config({ iconPrefix: "vuepress-", nav: [ - { text: "Home", icon: "homefill", link: "/" }, + { text: "Home", icon: "home", link: "/" }, { text: "Guide", - icon: "creativefill", + icon: "creative", link: "/guide/", }, { text: "Config", - icon: "configuration", + icon: "config", link: "/config/", }, ], @@ -53,15 +53,15 @@ module.exports = config({ locales: { "/zh/": { nav: [ - { text: "主页", icon: "homefill", link: "/zh/" }, + { text: "主页", icon: "home", link: "/zh/" }, { text: "指南", - icon: "creativefill", + icon: "creative", link: "/zh/guide/", }, { text: "配置", - icon: "configuration", + icon: "config", link: "/zh/config/", }, ], diff --git a/docs/copy-code/src/.vuepress/styles/index.styl b/docs/copy-code/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/copy-code/src/.vuepress/styles/index.styl +++ b/docs/copy-code/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/copy-code/src/config.md b/docs/copy-code/src/config.md index 41b7937092c8..034890c9d456 100644 --- a/docs/copy-code/src/config.md +++ b/docs/copy-code/src/config.md @@ -1,6 +1,6 @@ --- title: API Config -icon: configuration +icon: config --- ## baseLang diff --git a/docs/copy-code/src/guide.md b/docs/copy-code/src/guide.md index cb595119a84c..b20cc0056453 100644 --- a/docs/copy-code/src/guide.md +++ b/docs/copy-code/src/guide.md @@ -1,6 +1,6 @@ --- title: Guide -icon: creativefill +icon: creative --- ## Usage diff --git a/docs/copy-code/src/readme.md b/docs/copy-code/src/readme.md index 57e2d3c6e51b..4df7cd2936e9 100644 --- a/docs/copy-code/src/readme.md +++ b/docs/copy-code/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-copy-code" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-copy-code" tagline: Code Copy plugin for vuepress diff --git a/docs/copy-code/src/zh/config.md b/docs/copy-code/src/zh/config.md index c19ee0885c4a..496386c4c677 100644 --- a/docs/copy-code/src/zh/config.md +++ b/docs/copy-code/src/zh/config.md @@ -1,6 +1,6 @@ --- title: 配置 -icon: configuration +icon: config --- ## 插件配置 diff --git a/docs/copy-code/src/zh/guide.md b/docs/copy-code/src/zh/guide.md index 7e4db0db9393..50fcf77027ac 100644 --- a/docs/copy-code/src/zh/guide.md +++ b/docs/copy-code/src/zh/guide.md @@ -1,6 +1,6 @@ --- title: 指南 -icon: creativefill +icon: creative --- ## 使用 diff --git a/docs/copy-code/src/zh/readme.md b/docs/copy-code/src/zh/readme.md index 0afe20d805cb..51b587d35481 100644 --- a/docs/copy-code/src/zh/readme.md +++ b/docs/copy-code/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-copy-code" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-copy-code" tagline: 为 VuePress 提供代码块一键复制 diff --git a/docs/last-update/src/.vuepress/styles/index.styl b/docs/last-update/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/last-update/src/.vuepress/styles/index.styl +++ b/docs/last-update/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/last-update/src/readme.md b/docs/last-update/src/readme.md index 8fe440aebcd8..9a61022af451 100644 --- a/docs/last-update/src/readme.md +++ b/docs/last-update/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-last-update" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-last-update" tagline: Last update plugin for vuepress diff --git a/docs/last-update/src/zh/readme.md b/docs/last-update/src/zh/readme.md index 97f6dac6c8f6..1d7dcb92be36 100644 --- a/docs/last-update/src/zh/readme.md +++ b/docs/last-update/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-last-update" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-last-update" tagline: 最后更新时间插件 diff --git a/docs/md-enhance/src/.vuepress/config.js b/docs/md-enhance/src/.vuepress/config.js index fc9f352b1650..d6bb283e8b96 100644 --- a/docs/md-enhance/src/.vuepress/config.js +++ b/docs/md-enhance/src/.vuepress/config.js @@ -6,6 +6,25 @@ module.exports = config({ dest: "./dist", + head: [ + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js" }, + ], + [ + "script", + { + src: + "https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js", + }, + ], + ["script", { src: "https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js" }], + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/@babel/standalone/babel.min.js" }, + ], + ], + locales: { "/zh/": { title: "Markdown 增强", @@ -17,9 +36,9 @@ module.exports = config({ logo: "/logo.svg", nav: [ - { text: "Home", icon: "homefill", link: "/" }, - { text: "Guide", icon: "creativefill", link: "/guide/" }, - { text: "Config", icon: "configuration", link: "/config/" }, + { text: "Home", icon: "home", link: "/" }, + { text: "Guide", icon: "creative", link: "/guide/" }, + { text: "Config", icon: "config", link: "/config/" }, ], sidebar: { "/guide/": [ @@ -30,6 +49,7 @@ module.exports = config({ "mark", "flowchart", "tex", + "demo", "presentation", ], @@ -57,9 +77,9 @@ module.exports = config({ locales: { "/zh/": { nav: [ - { text: "主页", icon: "homefill", link: "/zh/" }, - { text: "指南", icon: "creativefill", link: "/zh/guide/" }, - { text: "配置", icon: "configuration", link: "/zh/config/" }, + { text: "主页", icon: "home", link: "/zh/" }, + { text: "指南", icon: "creative", link: "/zh/guide/" }, + { text: "配置", icon: "config", link: "/zh/config/" }, ], sidebar: { "/zh/guide/": [ @@ -70,6 +90,7 @@ module.exports = config({ "mark", "flowchart", "tex", + "demo", "presentation", ], diff --git a/docs/md-enhance/src/.vuepress/styles/index.styl b/docs/md-enhance/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/md-enhance/src/.vuepress/styles/index.styl +++ b/docs/md-enhance/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/md-enhance/src/config.md b/docs/md-enhance/src/config.md index 1a9342d09aec..bcfbd78a958c 100644 --- a/docs/md-enhance/src/config.md +++ b/docs/md-enhance/src/config.md @@ -1,6 +1,6 @@ --- title: Config -icon: configuration +icon: config --- You can pass these options to the plugin: @@ -75,6 +75,86 @@ Whether to enable $\TeX$ syntax support. Whether to enable flowchart syntax support. +## demo + +- Type: `CodeDemoGlobalOptions | boolean` +- Default: `false` + +Whether to enable code demo support. + +### demo.jsLib + +- Type: `string[]` +- Required: No + +CodePen, JsFiddle requires an external JS library for dating. + +### demo.cssLib + +- Type: `string[]` +- Required: No + +CodePen, JsFiddle need an external CSS library for dating. + +::: warning +The above two options are only used by third-party code demo service, you need to import these libraries in `head`. +::: + +### demo.jsfiddle + +- Type: `boolean` +- Default value: `true` + +Whether to display the JSFiddle button, + +### demo.codepen + +- Type: `boolean` +- Default value: `true` + +Whether to display the CodePen button, + +### demo.horizo​​ntal + +- Type: `boolean` +- Default value: `false` + +Whether to display the code and view window horizontally + +### demo.codepenLayout + +- Type: `"top" | "left" | "correct"` +- Default value: `"left"` + +CodePen editor layout + +### demo.editors + +- Type: `string` +- Default value: `"101"` + +### others + +The following are the library links used by the third-party code demo service. Unless your environment cannot visit jsdelivr or the speed is slow, don’t override the default values. + +::: warning +Please note that if you use them, you still need to manually include them in your site using `head`. + +React depends on Babel. +::: + +#### demo.vue + +Default value: `"https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"` + +#### demo.react + +Default value: `"https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js"` + +#### demo.reactDOM + +Default value: `"https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js"` + ## presentation - Type: `PresentationOptions | boolean` diff --git a/docs/md-enhance/src/guide/demo.md b/docs/md-enhance/src/guide/demo.md new file mode 100644 index 000000000000..f375df278611 --- /dev/null +++ b/docs/md-enhance/src/guide/demo.md @@ -0,0 +1,396 @@ +--- +icon: discover +--- + +# Code Demo + +Let you insert code demos in your Markdown file. + +## Configuration + +```js {7} +module.exports = { + plugins: [ + [ + "md-enhance", + { + // Enable Code Demo + demo: true, + }, + ], + ], +}; +``` + +## Syntax + +You should use the following syntax: + +````md +::: demo [type] + +```html + + +``` + +```json +{ + // your config here (optional) +} +``` + +::: +```` + +::: tip +The json block is optional. +::: + +The plugin support three types: + +- vanilla (default) +- vue +- react + +### Vanilla + +Syntax: + +````md +::: demo + +```html + + + + + +``` + +```json +// config (optional) +``` + +:::: +```` + +### Vue + +Syntax: + +````md +::: demo vue + +```html + + + +``` + +```json +// config (optional) +``` + +::: +```` + +### React + +Syntax: + +````md +::: demo react + +```js +export default class App extends React.Component { + // your react component +} +App.__style__ = ` + your styles +`; +``` + +::: +```` + +::: warning +This plugin is not bundling any librarys, so you must import them by setting `head` in your `.vuepress/config.js` files. + +```js +// .vuepress/config.js +module.exports = { + head: [ + // react needs React, ReactDOM and Babel + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js" }, + ], + [ + "script", + { + src: + "https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js", + }, + ], + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/@babel/standalone/babel.min.js" }, + ], + // vue only needs vue + ["script", { src: "https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js" }], + ], +}; +``` + +We also make an enhance: If you import Babel, then Vue and Vanilla script will be parsed to es6 using babel. +::: + +### PreProcessor + +You can config preprocessor in your demo block. But only jsPreprocessor `'babel'` is supported at runtime when you import babel standalone library. + +When you set other proprocessor, since the plugin is not able to resolve them, demo display will be disabled, and only codes can be seen. And the plugin will provide you a button to open it in CodePen. + +HTML preprocessors: + +- `"none"` (default) +- `"slim"` +- `"haml"` +- `"markdown"` + +JS preprocessors: + +- `"none"` (default) +- `"coffeescript"` +- `"babel"` +- `"livescript"` +- `"typescript"` + +CSS preprocessors: + +- `"none"` (default) +- `"less"` +- `"scss"` +- `"sass"` +- `"stylus"` + +## Demo + +::: demo + +```html + +

Mr.Hope

+

Is very handsome

+ + + +``` + +::: + +````md +::: demo + +```html + +

Mr.Hope

+

Is very handsome

+ + + +``` + +::: +```` + +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "very handsome" }; + } + render() { + return ( +
+ Mr.Hope is {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: + +````md +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "very handsome" }; + } + render() { + return ( +
+ Mr.Hope is {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: +```` + +::: demo vue + +```html + + + +``` + +::: + +````md +::: demo vue + +```html + + + +``` + +::: +```` + +::: demo + +```html + +# Title + +is very handsome. + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: + +````md +::: demo + +```html + + # Title is very handsome. + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: +```` diff --git a/docs/md-enhance/src/guide/mark.md b/docs/md-enhance/src/guide/mark.md index effbf1c85a58..9a8c8dc0c7e9 100644 --- a/docs/md-enhance/src/guide/mark.md +++ b/docs/md-enhance/src/guide/mark.md @@ -1,5 +1,5 @@ --- -icon: writefill +icon: write --- # Mark diff --git a/docs/md-enhance/src/guide/readme.md b/docs/md-enhance/src/guide/readme.md index ae7a1bff69c2..004dcdd02260 100644 --- a/docs/md-enhance/src/guide/readme.md +++ b/docs/md-enhance/src/guide/readme.md @@ -22,4 +22,6 @@ If you don’t need them and want to reduce your site size, you can remove them - [$\TeX$ Syntax](tex.md) +- [Code demo](demo.md) + - [Presentation](presentation.md) diff --git a/docs/md-enhance/src/readme.md b/docs/md-enhance/src/readme.md index 1004c661b087..537ef0ac8297 100644 --- a/docs/md-enhance/src/readme.md +++ b/docs/md-enhance/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-md-enhance -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-md-enhance tagline: Enhancement for markdown in VuePress diff --git a/docs/md-enhance/src/zh/config.md b/docs/md-enhance/src/zh/config.md index 81ee17a29acd..22a7b72e8655 100644 --- a/docs/md-enhance/src/zh/config.md +++ b/docs/md-enhance/src/zh/config.md @@ -1,6 +1,6 @@ --- title: 配置 -icon: configuration +icon: config --- 你可以传递以下选项来启用或禁用一些功能 @@ -73,14 +73,96 @@ icon: configuration - 类型: `boolean` - 默认值: `false` -是否启用 流程图 语法支持。 +是否启用流程图支持。 + +## demo + +- 类型: `CodeDemoGlobalOptions | boolean` +- 默认值: `false` + +是否启用代码案例支持。 + +### demo.jsLib + +- 类型: `string[]` +- 必填: 否 + +CodePen, JsFiddle 需要引入的外部 JS 库。 + +### demo.cssLib + +- 类型: `string[]` +- 必填: 否 + +CodePen, JsFiddle 需要引入的外部 CSS 库。 + +::: warning +上述两个选项仅仅是给第三方代码演示使用的,你需要自行在 `head` 中导入这些库。 +::: + +### demo.jsfiddle + +- 类型: `boolean` +- 默认值: `true` + +是否显示 JSFiddle 按钮, + +### demo.codepen + +- 类型: `boolean` +- 默认值: `true` + +是否显示 CodePen 按钮, + +### demo.horizontal + +- 类型: `boolean` +- 默认值: `false` + +是否水平显示代码和视图窗口 + +### demo.codepenLayout + +- 类型: `"top" | "left" | "right"` +- 默认值: `"left"` + +CodePen 编辑器布局 + +### demo.editors + +- 类型: `string` +- 默认值: `"101"` + +CodePen 编辑器显示情况,第一位代表 HTML ,第二位代表 JS,第三位代表演示页面。 + +### 其他 + +以下是第三方代码演示使用的库地址,除非你的环境无法访问 jsdelivr 或访问缓慢,否则无需覆盖默认设置。 + +::: warning +请注意,如果你用到了它们,你仍需要利用 `head` 手动在你的网站中导入它们。 + +React 依赖于 Babel。 +::: + +#### demo.vue + +默认值: `"https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"` + +#### demo.react + +默认值: `"https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js"` + +#### demo.reactDOM + +默认值: `"https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js"` ## presentation - 类型: `PresentationOptions | boolean` - 默认值: `false` -是否启用 幻灯片 语法支持。 +是否启用幻灯片支持。 你可以传入一个对象,这个对象将用于 reveal.js 配置。 diff --git a/docs/md-enhance/src/zh/guide/demo.md b/docs/md-enhance/src/zh/guide/demo.md new file mode 100644 index 000000000000..f719d54e3c8e --- /dev/null +++ b/docs/md-enhance/src/zh/guide/demo.md @@ -0,0 +1,396 @@ +--- +icon: discover +--- + +# 代码演示 + +让你的 VuePress 站点中的 Markdown 文件支持代码案例。 + +## 配置 + +```js {7} +module.exports = { + plugins: [ + [ + "md-enhance", + { + // 启用代码演示 + demo: true, + }, + ], + ], +}; +``` + +## 语法 + +您应该使用以下语法: + +````md +::: demo [类型] + +```html + + +``` + +```json +{ + // 放置你的配置 (optional) +} +``` + +::: +```` + +::: tip +json 块是可选的。 +::: + +该插件支持三种类型: + +- vanilla (默认) +- vue +- react + +### Vanilla + +写法: + +````md +::: demo + +```html + + + + + +``` + +```json +// 配置 (可选) +``` + +:::: +```` + +### Vue + +语法: + +````md +::: demo vue + +```html + + + +``` + +```json +// 配置 (可选) +``` + +::: +```` + +### React + +语法: + +````md +::: demo react + +```js +export default class App extends React.Component { + // react 组件 +} +App.__style__ = ` + your styles +`; +``` + +::: +```` + +::: warning +该插件未捆绑任何库,因此您必须通过在 `.vuepress/config.js` 文件中设置 `head` 来导入它们。 + +```js +// .vuepress/config.js +module.exports = { + head: [ + // react 需要 React, ReactDOM 和 Babel 库 + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js" }, + ], + [ + "script", + { + src: + "https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js", + }, + ], + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/@babel/standalone/babel.min.js" }, + ], + // vue 只需要 vue 库 + ["script", { src: "https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js" }], + ], +}; +``` + +我们还进行了增强: 如果你导入 Babel,则将使用 babel 将脚本解析为 es6,以确保能在浏览器上正常运行。 +::: + +### 预处理器 + +您可以在演示块中配置预处理器。但是,在运行时仅支持 JS 预处理器 `'babel'`(你还需要手动导入 babel 独立库)。 + +当您设置其他预处理器时,由于插件无法解析它们,因此演示将被禁用,您只能看到代码。插件将为您提供一个 "在 CodePen 中打开" 按钮。 + +HTML 预处理器: + +- `"none"` (默认) +- `"slim"` +- `"haml"` +- `"markdown"` + +JS 预处理器: + +- `"none"` (默认) +- `"coffeescript"` +- `"babel"` +- `"livescript"` +- `"typescript"` + +CSS 预处理器: + +- `"none"` (默认) +- `"less"` +- `"scss"` +- `"sass"` +- `"stylus"` + +## 演示 + +::: demo + +```html + +

Mr.Hope

+

Is 十分

+ + + +``` + +::: + +````md +::: demo + +```html + +

Mr.Hope

+

Is 十分

+ + + +``` + +::: +```` + +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "十分帅" }; + } + render() { + return ( +
+ Mr.Hope {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: + +````md +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "十分帅" }; + } + render() { + return ( +
+ Mr.Hope {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: +```` + +::: demo vue + +```html + + + +``` + +::: + +````md +::: demo vue + +```html + + + +``` + +::: +```` + +::: demo + +```html + +# 标题 + +十分帅! + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: + +````md +::: demo + +```html + + # 标题 十分帅! + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: +```` diff --git a/docs/md-enhance/src/zh/guide/mark.md b/docs/md-enhance/src/zh/guide/mark.md index abb707bc05c0..690ca0a81cc2 100644 --- a/docs/md-enhance/src/zh/guide/mark.md +++ b/docs/md-enhance/src/zh/guide/mark.md @@ -1,5 +1,5 @@ --- -icon: writefill +icon: write --- # 标记 diff --git a/docs/md-enhance/src/zh/guide/readme.md b/docs/md-enhance/src/zh/guide/readme.md index de16962fffe3..90eb01cc0f22 100644 --- a/docs/md-enhance/src/zh/guide/readme.md +++ b/docs/md-enhance/src/zh/guide/readme.md @@ -22,4 +22,6 @@ icon: markdown - [$\TeX$ 语法](tex.md) +- [代码案例](demo.md) + - [幻灯片](presentation.md) diff --git a/docs/md-enhance/src/zh/readme.md b/docs/md-enhance/src/zh/readme.md index f7455c39420f..585d0c77e29a 100644 --- a/docs/md-enhance/src/zh/readme.md +++ b/docs/md-enhance/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-md-enhance -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-md-enhance tagline: 为 VuePress 提供更多 Markdown 增强功能 diff --git a/docs/photo-swipe/src/.vuepress/config.js b/docs/photo-swipe/src/.vuepress/config.js index 9d4ed18afbd3..6cabb6440502 100644 --- a/docs/photo-swipe/src/.vuepress/config.js +++ b/docs/photo-swipe/src/.vuepress/config.js @@ -22,9 +22,9 @@ module.exports = config({ iconPrefix: "vuepress-", nav: [ - { text: "Home", icon: "homefill", link: "/" }, - { text: "Demo", icon: "creativefill", link: "/demo/" }, - { text: "Config", icon: "configuration", link: "/config/" }, + { text: "Home", icon: "home", link: "/" }, + { text: "Demo", icon: "creative", link: "/demo/" }, + { text: "Config", icon: "config", link: "/config/" }, ], footer: { @@ -45,9 +45,9 @@ module.exports = config({ locales: { "/zh/": { nav: [ - { text: "主页", icon: "homefill", link: "/zh/" }, - { text: "演示", icon: "creativefill", link: "/zh/demo/" }, - { text: "配置", icon: "configuration", link: "/zh/config/" }, + { text: "主页", icon: "home", link: "/zh/" }, + { text: "演示", icon: "creative", link: "/zh/demo/" }, + { text: "配置", icon: "config", link: "/zh/config/" }, ], }, }, diff --git a/docs/photo-swipe/src/.vuepress/styles/index.styl b/docs/photo-swipe/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/photo-swipe/src/.vuepress/styles/index.styl +++ b/docs/photo-swipe/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/photo-swipe/src/config.md b/docs/photo-swipe/src/config.md index d86ec049480e..353d27265f62 100644 --- a/docs/photo-swipe/src/config.md +++ b/docs/photo-swipe/src/config.md @@ -1,6 +1,6 @@ --- title: config -icon: configuration +icon: config --- ## Plugin Options diff --git a/docs/photo-swipe/src/demo.md b/docs/photo-swipe/src/demo.md index 0ef810bbd98c..bcacad8e9df8 100644 --- a/docs/photo-swipe/src/demo.md +++ b/docs/photo-swipe/src/demo.md @@ -1,6 +1,6 @@ --- title: Demo -icon: creativefill +icon: creative --- ![Logo1](/logo.png) diff --git a/docs/photo-swipe/src/readme.md b/docs/photo-swipe/src/readme.md index 56b9051e13d6..d0f341109dd5 100644 --- a/docs/photo-swipe/src/readme.md +++ b/docs/photo-swipe/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-photo-swipe -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-photo-swipe tagline: Photo swipe plugin for vuepress diff --git a/docs/photo-swipe/src/zh/config.md b/docs/photo-swipe/src/zh/config.md index 9b35bfc2cb9b..768ecd3deab4 100644 --- a/docs/photo-swipe/src/zh/config.md +++ b/docs/photo-swipe/src/zh/config.md @@ -1,6 +1,6 @@ --- title: 配置 -icon: configuration +icon: config --- ## 选项 diff --git a/docs/photo-swipe/src/zh/demo.md b/docs/photo-swipe/src/zh/demo.md index 99131252edb6..9c021b810dbe 100644 --- a/docs/photo-swipe/src/zh/demo.md +++ b/docs/photo-swipe/src/zh/demo.md @@ -1,6 +1,6 @@ --- title: 演示 -icon: creativefill +icon: creative --- ![Logo1](/logo.png) diff --git a/docs/photo-swipe/src/zh/readme.md b/docs/photo-swipe/src/zh/readme.md index cca5afb62101..3caab3f9cbde 100644 --- a/docs/photo-swipe/src/zh/readme.md +++ b/docs/photo-swipe/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-plugin-photo-swipe -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-plugin-photo-swipe tagline: 为 VuePress 提供图片预览支持 diff --git a/docs/pwa/src/.vuepress/config.js b/docs/pwa/src/.vuepress/config.js index 033e0d78c398..c916fc970fa6 100644 --- a/docs/pwa/src/.vuepress/config.js +++ b/docs/pwa/src/.vuepress/config.js @@ -22,15 +22,15 @@ module.exports = config({ iconPrefix: "vuepress-", nav: [ - { text: "Home", icon: "homefill", link: "/" }, + { text: "Home", icon: "home", link: "/" }, { text: "Guide", - icon: "creativefill", + icon: "creative", link: "/guide/", }, { text: "Config", - icon: "configuration", + icon: "config", link: "/config/", }, ], @@ -53,15 +53,15 @@ module.exports = config({ locales: { "/zh/": { nav: [ - { text: "主页", icon: "homefill", link: "/zh/" }, + { text: "主页", icon: "home", link: "/zh/" }, { text: "指南", - icon: "creativefill", + icon: "creative", link: "/zh/guide/", }, { text: "配置", - icon: "configuration", + icon: "config", link: "/zh/config/", }, ], diff --git a/docs/pwa/src/.vuepress/styles/index.styl b/docs/pwa/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/pwa/src/.vuepress/styles/index.styl +++ b/docs/pwa/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/pwa/src/config.md b/docs/pwa/src/config.md index e812953d5aac..df1f6cf4be0c 100644 --- a/docs/pwa/src/config.md +++ b/docs/pwa/src/config.md @@ -1,6 +1,6 @@ --- title: config -icon: configuration +icon: config --- ## baseLang diff --git a/docs/pwa/src/guide.md b/docs/pwa/src/guide.md index 7a2aa1dd6218..479597d5c906 100644 --- a/docs/pwa/src/guide.md +++ b/docs/pwa/src/guide.md @@ -1,6 +1,6 @@ --- title: Guide -icon: creativefill +icon: creative --- ## Content Cache and update diff --git a/docs/pwa/src/readme.md b/docs/pwa/src/readme.md index 99cb406b4f91..edf75c8ca31b 100644 --- a/docs/pwa/src/readme.md +++ b/docs/pwa/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-pwa" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-pwa" tagline: A powerfull PWA plugin diff --git a/docs/pwa/src/zh/config.md b/docs/pwa/src/zh/config.md index 422fa2660d83..7de1802340a5 100644 --- a/docs/pwa/src/zh/config.md +++ b/docs/pwa/src/zh/config.md @@ -1,6 +1,6 @@ --- title: 配置 -icon: configuration +icon: config --- ## baseLang diff --git a/docs/pwa/src/zh/guide.md b/docs/pwa/src/zh/guide.md index 4e1e9cf66af9..e05293ac030b 100644 --- a/docs/pwa/src/zh/guide.md +++ b/docs/pwa/src/zh/guide.md @@ -1,6 +1,6 @@ --- title: 指南 -icon: creativefill +icon: creative --- ## 内容缓存和更新 diff --git a/docs/pwa/src/zh/readme.md b/docs/pwa/src/zh/readme.md index f60917dfb5a4..94d364b65d7f 100644 --- a/docs/pwa/src/zh/readme.md +++ b/docs/pwa/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-pwa" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-pwa" tagline: 一个强大的 PWA 插件 diff --git a/docs/reading-time/src/.vuepress/styles/index.styl b/docs/reading-time/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/reading-time/src/.vuepress/styles/index.styl +++ b/docs/reading-time/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/reading-time/src/readme.md b/docs/reading-time/src/readme.md index d50fc0d79acb..bd48eb9dec3a 100644 --- a/docs/reading-time/src/readme.md +++ b/docs/reading-time/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-reading-time" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-reading-time" tagline: Words and reading time counter diff --git a/docs/reading-time/src/zh/readme.md b/docs/reading-time/src/zh/readme.md index 4e26c7b74248..81ccd61fb175 100644 --- a/docs/reading-time/src/zh/readme.md +++ b/docs/reading-time/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-reading-time" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-reading-time" tagline: 字数与阅读时间统计 diff --git a/docs/seo/src/.vuepress/styles/index.styl b/docs/seo/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/seo/src/.vuepress/styles/index.styl +++ b/docs/seo/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/seo/src/readme.md b/docs/seo/src/readme.md index 6a2e3de703ad..881674cd2bfd 100644 --- a/docs/seo/src/readme.md +++ b/docs/seo/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-seo" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-seo" tagline: Inject into your webpage to enhance the SEO of your webpage. diff --git a/docs/seo/src/zh/readme.md b/docs/seo/src/zh/readme.md index 32c249e684f4..b348bdc4b11a 100644 --- a/docs/seo/src/zh/readme.md +++ b/docs/seo/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-seo" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-seo" tagline: 向你的网页注入 ,来增强你网页的 SEO。 diff --git a/docs/sitemap/src/.vuepress/styles/index.styl b/docs/sitemap/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/sitemap/src/.vuepress/styles/index.styl +++ b/docs/sitemap/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/sitemap/src/readme.md b/docs/sitemap/src/readme.md index 5080dcae0bec..1ec7698df387 100644 --- a/docs/sitemap/src/readme.md +++ b/docs/sitemap/src/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-sitemap" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-sitemap" tagline: Automatically generate a sitemap for your website when you build it. diff --git a/docs/sitemap/src/zh/readme.md b/docs/sitemap/src/zh/readme.md index 56422ee4f0d2..a5baa7270ddd 100644 --- a/docs/sitemap/src/zh/readme.md +++ b/docs/sitemap/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: "@mr-hope/vuepress-plugin-sitemap" -icon: homefill +icon: home heroImage: /logo.svg heroText: "@mr-hope/vuepress-plugin-sitemap" tagline: 自动在你构建网页时为你生成网页的 sitemap。 diff --git a/docs/theme/src/.vuepress/navBar.js b/docs/theme/src/.vuepress/navBar.js index ac46b0bc9360..63f8539cf9d5 100644 --- a/docs/theme/src/.vuepress/navBar.js +++ b/docs/theme/src/.vuepress/navBar.js @@ -1,12 +1,12 @@ module.exports = { en: [ - { text: "Home", link: "/", icon: "homefill" }, - { text: "Guide", link: "/guide/", icon: "creativefill" }, - { text: "Config", link: "/config/", icon: "configuration" }, - { text: "FAQ", link: "/FAQ/", icon: "questionfill" }, + { text: "Home", link: "/", icon: "home" }, + { text: "Guide", link: "/guide/", icon: "creative" }, + { text: "Config", link: "/config/", icon: "config" }, + { text: "FAQ", link: "/FAQ/", icon: "question" }, { text: "Basic", - icon: "infofill", + icon: "info", prefix: "/basic/", items: [ { text: "Markdown", link: "markdown/", icon: "markdown" }, @@ -15,7 +15,7 @@ module.exports = { }, { text: "Project", - icon: "infofill", + icon: "info", items: [ { text: "Changelog", @@ -75,13 +75,13 @@ module.exports = { ], zh: [ - { text: "主页", link: "/zh/", icon: "homefill" }, - { text: "指南", link: "/zh/guide/", icon: "creativefill" }, - { text: "配置", link: "/zh/config/", icon: "configuration" }, - { text: "常见问题", link: "/zh/FAQ/", icon: "questionfill" }, + { text: "主页", link: "/zh/", icon: "home" }, + { text: "指南", link: "/zh/guide/", icon: "creative" }, + { text: "配置", link: "/zh/config/", icon: "config" }, + { text: "常见问题", link: "/zh/FAQ/", icon: "question" }, { text: "基础", - icon: "infofill", + icon: "info", prefix: "/zh/basic/", items: [ { text: "Markdown", link: "markdown/", icon: "markdown" }, @@ -90,7 +90,7 @@ module.exports = { }, { text: "项目", - icon: "infofill", + icon: "info", items: [ { text: "更新日志", diff --git a/docs/theme/src/.vuepress/sideBar.js b/docs/theme/src/.vuepress/sideBar.js index bfc0d3789073..d87fdcc7f95f 100644 --- a/docs/theme/src/.vuepress/sideBar.js +++ b/docs/theme/src/.vuepress/sideBar.js @@ -3,13 +3,13 @@ module.exports = { "/guide/": [ { title: "Get Started", - icon: "creativefill", + icon: "creative", collapsable: false, children: ["", "install"], }, { title: "New Features", - icon: "discoverfill", + icon: "discover", prefix: "feature/", collapsable: false, children: [ @@ -33,6 +33,7 @@ module.exports = { "mark", "tex", "flowchart", + "demo", "presentation", ], }, @@ -54,7 +55,7 @@ module.exports = { "/config/": [ { title: "ThemeConfig", - icon: "configuration", + icon: "config", prefix: "theme/", collapsable: false, children: ["", "default", "feature", "plugin", "apperance"], @@ -104,13 +105,13 @@ module.exports = { "/zh/guide/": [ { title: "快速上手", - icon: "creativefill", + icon: "creative", collapsable: false, children: ["", "install"], }, { title: "新增功能", - icon: "discoverfill", + icon: "discover", prefix: "feature/", collapsable: false, children: [ @@ -134,6 +135,7 @@ module.exports = { "mark", "tex", "flowchart", + "demo", "presentation", ], }, @@ -155,7 +157,7 @@ module.exports = { "/zh/config/": [ { title: "主题配置", - icon: "configuration", + icon: "config", prefix: "theme/", collapsable: false, children: ["", "default", "feature", "plugin", "apperance"], diff --git a/docs/theme/src/.vuepress/styles/index.styl b/docs/theme/src/.vuepress/styles/index.styl index 9970ab3d94d1..c655d62cee8c 100644 --- a/docs/theme/src/.vuepress/styles/index.styl +++ b/docs/theme/src/.vuepress/styles/index.styl @@ -1 +1 @@ -@import '//at.alicdn.com/t/font_1446717_yja086re30b.css' +@import '//at.alicdn.com/t/font_1446717_q5huxk6v1h.css' diff --git a/docs/theme/src/FAQ/readme.md b/docs/theme/src/FAQ/readme.md index 557f23c24806..fdb2f3f6d9ae 100644 --- a/docs/theme/src/FAQ/readme.md +++ b/docs/theme/src/FAQ/readme.md @@ -1,5 +1,5 @@ --- -icon: questionfill +icon: question category: FAQ --- diff --git a/docs/theme/src/basic/readme.md b/docs/theme/src/basic/readme.md index 6084ea5eb0e9..3b7bbadb7526 100644 --- a/docs/theme/src/basic/readme.md +++ b/docs/theme/src/basic/readme.md @@ -1,5 +1,5 @@ --- -icon: infofill +icon: info --- # Basic diff --git a/docs/theme/src/basic/vuepress/case.md b/docs/theme/src/basic/vuepress/case.md index ca870ad8d282..e8df7ef3dfd2 100644 --- a/docs/theme/src/basic/vuepress/case.md +++ b/docs/theme/src/basic/vuepress/case.md @@ -1,6 +1,6 @@ --- title: VuePress Cases -icon: discoverfill +icon: discover category: basic tags: - vuepress diff --git a/docs/theme/src/basic/vuepress/theme.md b/docs/theme/src/basic/vuepress/theme.md index f0de4222c946..a5deadd3a357 100644 --- a/docs/theme/src/basic/vuepress/theme.md +++ b/docs/theme/src/basic/vuepress/theme.md @@ -1,6 +1,6 @@ --- title: Theme Config -icon: skinfill +icon: skin category: basic tags: - vuepress diff --git a/docs/theme/src/config/page.md b/docs/theme/src/config/page.md index 953ba8679134..0ae73f80f97d 100644 --- a/docs/theme/src/config/page.md +++ b/docs/theme/src/config/page.md @@ -1,6 +1,6 @@ --- title: Page Configuration -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/config/readme.md b/docs/theme/src/config/readme.md index ccc8489016ee..7eb0ee1517e9 100644 --- a/docs/theme/src/config/readme.md +++ b/docs/theme/src/config/readme.md @@ -1,6 +1,6 @@ --- title: Config -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/config/stylus.md b/docs/theme/src/config/stylus.md index a330ec391516..d8d2daf0aba1 100644 --- a/docs/theme/src/config/stylus.md +++ b/docs/theme/src/config/stylus.md @@ -1,6 +1,6 @@ --- title: stylus configuration -icon: skinfill +icon: skin category: config tags: - config diff --git a/docs/theme/src/config/theme/apperance.md b/docs/theme/src/config/theme/apperance.md index 7f4162ed51ba..9cad26e23ac1 100644 --- a/docs/theme/src/config/theme/apperance.md +++ b/docs/theme/src/config/theme/apperance.md @@ -1,6 +1,6 @@ --- title: Theme Layout Config -icon: configuration +icon: config category: config tags: - themeConfig diff --git a/docs/theme/src/config/theme/default.md b/docs/theme/src/config/theme/default.md index 2de3e6271cd9..a5fcca4e832f 100644 --- a/docs/theme/src/config/theme/default.md +++ b/docs/theme/src/config/theme/default.md @@ -1,6 +1,6 @@ --- title: Default Theme Config -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/config/theme/feature.md b/docs/theme/src/config/theme/feature.md index 752210e79d46..b6b54d7f7b19 100644 --- a/docs/theme/src/config/theme/feature.md +++ b/docs/theme/src/config/theme/feature.md @@ -1,6 +1,6 @@ --- title: Theme Feature Config -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/config/theme/plugin.md b/docs/theme/src/config/theme/plugin.md index 4b12dbf4c4fb..ca046c980453 100644 --- a/docs/theme/src/config/theme/plugin.md +++ b/docs/theme/src/config/theme/plugin.md @@ -1,6 +1,6 @@ --- title: Theme Plugin Config -icon: configuration +icon: config category: config tags: - config @@ -83,6 +83,86 @@ Whether to enable TeX syntax support Whether to enable flowchart syntax support +### mdEnhance.demo + +- Type: `CodeDemoGlobalOptions | boolean` +- Default: `false` + +Whether to enable code demo support. + +#### mdEnhance.demo.jsLib + +- Type: `string[]` +- Required: No + +CodePen, JsFiddle requires an external JS library for dating. + +#### mdEnhance.demo.cssLib + +- Type: `string[]` +- Required: No + +CodePen, JsFiddle need an external CSS library for dating. + +::: warning +The above two options are only used by third-party code demo service, you need to import these libraries in `head`. +::: + +#### mdEnhance.demo.jsfiddle + +- Type: `boolean` +- Default value: `true` + +Whether to display the JSFiddle button, + +#### mdEnhance.demo.codepen + +- Type: `boolean` +- Default value: `true` + +Whether to display the CodePen button, + +#### mdEnhance.demo.horizo​​ntal + +- Type: `boolean` +- Default value: `false` + +Whether to display the code and view window horizontally + +#### mdEnhance.demo.codepenLayout + +- Type: `"top" | "left" | "correct"` +- Default value: `"left"` + +CodePen editor layout + +#### mdEnhance.demo.editors + +- Type: `string` +- Default value: `"101"` + +#### mdEnhance.others + +The following are the library links used by the third-party code demo service. Unless your environment cannot visit jsdelivr or the speed is slow, don’t override the default values. + +::: warning +Please note that if you use them, you still need to manually include them in your site using `head`. + +React depends on Babel. +::: + +##### mdEnhance.demo.vue + +Default value: `"https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"` + +##### mdEnhance.demo.react + +Default value: `"https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js"` + +##### mdEnhance.demo.reactDOM + +Default value: `"https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js"` + ### mdEnhance.presentation - Type: `PresentationOptions | boolean` diff --git a/docs/theme/src/config/theme/readme.md b/docs/theme/src/config/theme/readme.md index 27a8b1c80c03..3426d5af00a3 100644 --- a/docs/theme/src/config/theme/readme.md +++ b/docs/theme/src/config/theme/readme.md @@ -1,6 +1,6 @@ --- title: Theme Config -icon: configuration +icon: config category: config tags: - themeConfig diff --git a/docs/theme/src/demo/readme.md b/docs/theme/src/demo/readme.md index f84d655a8e04..b382ed402eb5 100644 --- a/docs/theme/src/demo/readme.md +++ b/docs/theme/src/demo/readme.md @@ -1,6 +1,6 @@ --- title: Demos -icon: discoverfill +icon: discover category: demo --- diff --git a/docs/theme/src/guide/feature/markdown/demo.md b/docs/theme/src/guide/feature/markdown/demo.md new file mode 100644 index 000000000000..71a2fa3dca11 --- /dev/null +++ b/docs/theme/src/guide/feature/markdown/demo.md @@ -0,0 +1,394 @@ +--- +icon: discover +category: markdown +tags: + - feature + - markdown +--- + +# Code Demo + +Let you insert code demos in your Markdown file. + +## Configuration + +```js {4} +module.exports = { + themeConfig: { + mdEnhance: { + demo: true, + }, + }, +}; +``` + +## Syntax + +You should use the following syntax: + +````md +::: demo [type] + +```html + + +``` + +```json +{ + // your config here (optional) +} +``` + +::: +```` + +::: tip +The json block is optional. +::: + +The plugin support three types: + +- vanilla (default) +- vue +- react + +### Vanilla + +Syntax: + +````md +::: demo + +```html + + + + + +``` + +```json +// config (optional) +``` + +:::: +```` + +### Vue + +Syntax: + +````md +::: demo vue + +```html + + + +``` + +```json +// config (optional) +``` + +::: +```` + +### React + +Syntax: + +````md +::: demo react + +```js +export default class App extends React.Component { + // your react component +} +App.__style__ = ` + your styles +`; +``` + +::: +```` + +::: warning +This plugin is not bundling any librarys, so you must import them by setting `head` in your `.vuepress/config.js` files. + +```js +// .vuepress/config.js +module.exports = { + head: [ + // react needs React, ReactDOM and Babel + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js" }, + ], + [ + "script", + { + src: + "https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js", + }, + ], + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/@babel/standalone/babel.min.js" }, + ], + // vue only needs vue + ["script", { src: "https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js" }], + ], +}; +``` + +We also make an enhance: If you import Babel, then Vue and Vanilla script will be parsed to es6 using babel. +::: + +### PreProcessor + +You can config preprocessor in your demo block. But only jsPreprocessor `'babel'` is supported at runtime when you import babel standalone library. + +When you set other proprocessor, since the plugin is not able to resolve them, demo display will be disabled, and only codes can be seen. And the plugin will provide you a button to open it in CodePen. + +HTML preprocessors: + +- `"none"` (default) +- `"slim"` +- `"haml"` +- `"markdown"` + +JS preprocessors: + +- `"none"` (default) +- `"coffeescript"` +- `"babel"` +- `"livescript"` +- `"typescript"` + +CSS preprocessors: + +- `"none"` (default) +- `"less"` +- `"scss"` +- `"sass"` +- `"stylus"` + +## Demo + +::: demo + +```html + +

Mr.Hope

+

Is very handsome

+ + + +``` + +::: + +````md +::: demo + +```html + +

Mr.Hope

+

Is very handsome

+ + + +``` + +::: +```` + +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "very handsome" }; + } + render() { + return ( +
+ Mr.Hope is {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: + +````md +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "very handsome" }; + } + render() { + return ( +
+ Mr.Hope is {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: +```` + +::: demo vue + +```html + + + +``` + +::: + +````md +::: demo vue + +```html + + + +``` + +::: +```` + +::: demo + +```html + + # Title is very handsome. + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: + +````md +::: demo + +```html + + # Title is very handsome. + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: +```` diff --git a/docs/theme/src/guide/feature/markdown/mark.md b/docs/theme/src/guide/feature/markdown/mark.md index 0020afed85df..220f706e61f9 100644 --- a/docs/theme/src/guide/feature/markdown/mark.md +++ b/docs/theme/src/guide/feature/markdown/mark.md @@ -1,5 +1,5 @@ --- -icon: writefill +icon: write tags: - feature - markdown diff --git a/docs/theme/src/guide/feature/page-info.md b/docs/theme/src/guide/feature/page-info.md index 2984d95f2d09..199ae3eac7d7 100644 --- a/docs/theme/src/guide/feature/page-info.md +++ b/docs/theme/src/guide/feature/page-info.md @@ -1,5 +1,5 @@ --- -icon: infofill +icon: info category: feature tags: - page-info diff --git a/docs/theme/src/guide/feature/readme.md b/docs/theme/src/guide/feature/readme.md index 51179354bb88..927e23b9463f 100644 --- a/docs/theme/src/guide/feature/readme.md +++ b/docs/theme/src/guide/feature/readme.md @@ -1,5 +1,5 @@ --- -icon: discoverfill +icon: discover category: feature tags: - intro @@ -35,7 +35,7 @@ tags: Please import the corresponding icon CSS file in `index.styl` under `.vuepress/styles`. E.g: ```css - @import "//at.alicdn.com/t/font_1446717_giwlq66d28j.css"; + @import "//at.alicdn.com/t/font_1446717_q5huxk6v1h.css"; ``` The class added to the icon is `iconfont`, and the prefix of the icon is `icon-` by default, which can be changed in the `iconPrefix` field in the theme configuration. diff --git a/docs/theme/src/guide/feature/theme.md b/docs/theme/src/guide/feature/theme.md index 8d53be3e9097..55d443018141 100644 --- a/docs/theme/src/guide/feature/theme.md +++ b/docs/theme/src/guide/feature/theme.md @@ -1,5 +1,5 @@ --- -icon: skinfill +icon: skin category: feature tags: - style diff --git a/docs/theme/src/guide/layout/home.md b/docs/theme/src/guide/layout/home.md index b8c9cc289842..09bebcfa28bb 100644 --- a/docs/theme/src/guide/layout/home.md +++ b/docs/theme/src/guide/layout/home.md @@ -1,5 +1,5 @@ --- -icon: homefill +icon: home category: layout tags: - home @@ -82,7 +82,7 @@ Feature description ```yaml --- home: true -icon: homefill +icon: home title: vuepress-theme-hope heroImage: /logo.svg heroText: vuepress-theme-hope diff --git a/docs/theme/src/guide/layout/navbar.md b/docs/theme/src/guide/layout/navbar.md index 162eead3b5f0..386f816c76b2 100644 --- a/docs/theme/src/guide/layout/navbar.md +++ b/docs/theme/src/guide/layout/navbar.md @@ -23,8 +23,8 @@ The basic configuration items are `text` navigation bar text, `link` navigation module.exports = { themeConfig: { nav: [ - { text: "Home", link: "/", icon: "homefill" }, - { text: "Guide", link: "/guide/", icon: "infofill" }, + { text: "Home", link: "/", icon: "home" }, + { text: "Guide", link: "/guide/", icon: "info" }, { text: "External", link: "https://google.com", icon: "markdown" }, ], }, @@ -87,7 +87,7 @@ module.exports = { nav: [ { text: "Basic", - icon: "infofill", + icon: "info", prefix: "/basic/", items: [ { text: "Markdown", link: "markdown", icon: "markdown" }, @@ -262,12 +262,12 @@ module.exports = { themeConfig: { nav: [ // add icon field to each item to display icon - { text: "Home", link: "/", icon: "homefill" }, - { text: "Guide", link: "/guide/", icon: "creativefill" }, - { text: "Config", link: "/config/", icon: "configuration" }, + { text: "Home", link: "/", icon: "home" }, + { text: "Guide", link: "/guide/", icon: "creative" }, + { text: "Config", link: "/config/", icon: "config" }, { text: "Basic", - icon: "infofill", + icon: "info", prefix: "/basic/", items: [ { text: "Markdown", link: "markdown/", icon: "markdown" }, @@ -276,7 +276,7 @@ module.exports = { }, { text: "Project", - icon: "infofill", + icon: "info", items: [ { text: "Changelog", diff --git a/docs/theme/src/guide/layout/sidebar.md b/docs/theme/src/guide/layout/sidebar.md index c494dbf7f5a4..007bcad0f65e 100644 --- a/docs/theme/src/guide/layout/sidebar.md +++ b/docs/theme/src/guide/layout/sidebar.md @@ -209,13 +209,13 @@ module.exports = { "/guide/": [ { title: "Get Started", - icon: "creativefill", + icon: "creative", collapsable: false, children: ["", "install"], }, { title: "New Features", - icon: "discoverfill", + icon: "discover", prefix: "feature/", collapsable: false, children: [ @@ -258,7 +258,7 @@ module.exports = { "/config/": [ { title: "ThemeConfig", - icon: "configuration", + icon: "config", prefix: "theme/", collapsable: false, children: ["", "default", "feature", "plugin", "apperance"], diff --git a/docs/theme/src/guide/readme.md b/docs/theme/src/guide/readme.md index c9034ba419de..d765ec56de08 100644 --- a/docs/theme/src/guide/readme.md +++ b/docs/theme/src/guide/readme.md @@ -1,5 +1,5 @@ --- -icon: infofill +icon: info --- # Introduction diff --git a/docs/theme/src/readme.md b/docs/theme/src/readme.md index 983d194a1213..3cecf2977b8e 100644 --- a/docs/theme/src/readme.md +++ b/docs/theme/src/readme.md @@ -1,6 +1,6 @@ --- home: true -icon: homefill +icon: home title: vuepress-theme-hope heroImage: /logo.svg heroText: vuepress-theme-hope diff --git a/docs/theme/src/zh/FAQ/readme.md b/docs/theme/src/zh/FAQ/readme.md index b099940f3aaf..fdc44ec13ea8 100644 --- a/docs/theme/src/zh/FAQ/readme.md +++ b/docs/theme/src/zh/FAQ/readme.md @@ -1,5 +1,5 @@ --- -icon: questionfill +icon: question category: FAQ --- diff --git a/docs/theme/src/zh/basic/readme.md b/docs/theme/src/zh/basic/readme.md index 58843a3a7798..56691c6de7f5 100644 --- a/docs/theme/src/zh/basic/readme.md +++ b/docs/theme/src/zh/basic/readme.md @@ -1,5 +1,5 @@ --- -icon: infofill +icon: info --- # 基础知识 diff --git a/docs/theme/src/zh/basic/vuepress/case.md b/docs/theme/src/zh/basic/vuepress/case.md index b4a23f525ec9..8451384a68df 100644 --- a/docs/theme/src/zh/basic/vuepress/case.md +++ b/docs/theme/src/zh/basic/vuepress/case.md @@ -1,6 +1,6 @@ --- title: VuePress 案例 -icon: discoverfill +icon: discover category: basic tags: - vuepress diff --git a/docs/theme/src/zh/basic/vuepress/theme.md b/docs/theme/src/zh/basic/vuepress/theme.md index a264897de772..0b128644f3b1 100644 --- a/docs/theme/src/zh/basic/vuepress/theme.md +++ b/docs/theme/src/zh/basic/vuepress/theme.md @@ -1,6 +1,6 @@ --- title: 主题配置 -icon: skinfill +icon: skin category: basic tags: - vuepress diff --git a/docs/theme/src/zh/config/page.md b/docs/theme/src/zh/config/page.md index 3bd9ef284dbc..8d900cb60356 100644 --- a/docs/theme/src/zh/config/page.md +++ b/docs/theme/src/zh/config/page.md @@ -1,6 +1,6 @@ --- title: 页面配置 -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/zh/config/readme.md b/docs/theme/src/zh/config/readme.md index 4cf281ed4edd..7a6a4b5498d5 100644 --- a/docs/theme/src/zh/config/readme.md +++ b/docs/theme/src/zh/config/readme.md @@ -1,6 +1,6 @@ --- title: 配置 -icon: configuration +icon: config category: config tags: config --- diff --git a/docs/theme/src/zh/config/stylus.md b/docs/theme/src/zh/config/stylus.md index aa6d0bc8bc7f..f1decdbdf245 100644 --- a/docs/theme/src/zh/config/stylus.md +++ b/docs/theme/src/zh/config/stylus.md @@ -1,6 +1,6 @@ --- title: stylus 配置 -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/zh/config/theme/apperance.md b/docs/theme/src/zh/config/theme/apperance.md index 06b4ad3dc271..54be8ad9ab99 100644 --- a/docs/theme/src/zh/config/theme/apperance.md +++ b/docs/theme/src/zh/config/theme/apperance.md @@ -1,6 +1,6 @@ --- title: 主题布局配置 -icon: configuration +icon: config category: config tags: - themeConfig diff --git a/docs/theme/src/zh/config/theme/default.md b/docs/theme/src/zh/config/theme/default.md index 3db2426c09fc..74d130d314c6 100644 --- a/docs/theme/src/zh/config/theme/default.md +++ b/docs/theme/src/zh/config/theme/default.md @@ -1,6 +1,6 @@ --- title: 默认主题配置 -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/zh/config/theme/feature.md b/docs/theme/src/zh/config/theme/feature.md index e069f84f9f51..d69838cde682 100644 --- a/docs/theme/src/zh/config/theme/feature.md +++ b/docs/theme/src/zh/config/theme/feature.md @@ -1,6 +1,6 @@ --- title: 主题功能配置 -icon: configuration +icon: config category: config tags: - config diff --git a/docs/theme/src/zh/config/theme/plugin.md b/docs/theme/src/zh/config/theme/plugin.md index 12edf8634cfe..b5c2f6a960de 100644 --- a/docs/theme/src/zh/config/theme/plugin.md +++ b/docs/theme/src/zh/config/theme/plugin.md @@ -1,6 +1,6 @@ --- title: 主题插件配置 -icon: configuration +icon: config category: config tags: - config @@ -83,6 +83,88 @@ Markdown 功能增强,详情请见 [vuepress-plugin-md-enhance 文档][md-enha 是否启用 流程图 语法支持 +### mdEnhance.demo + +- 类型: `CodeDemoGlobalOptions | boolean` +- 默认值: `false` + +是否启用代码案例支持。 + +#### mdEnhance.demo.jsLib + +- 类型: `string[]` +- 必填: 否 + +CodePen, JsFiddle 需要引入的外部 JS 库。 + +#### mdEnhance.demo.cssLib + +- 类型: `string[]` +- 必填: 否 + +CodePen, JsFiddle 需要引入的外部 CSS 库。 + +::: warning +上述两个选项仅仅是给第三方代码演示使用的,你需要自行在 `head` 中导入这些库。 +::: + +#### mdEnhance.demo.jsfiddle + +- 类型: `boolean` +- 默认值: `true` + +是否显示 JSFiddle 按钮, + +#### mdEnhance.demo.codepen + +- 类型: `boolean` +- 默认值: `true` + +是否显示 CodePen 按钮, + +#### mdEnhance.demo.horizontal + +- 类型: `boolean` +- 默认值: `false` + +是否水平显示代码和视图窗口 + +#### mdEnhance.demo.codepenLayout + +- 类型: `"top" | "left" | "right"` +- 默认值: `"left"` + +CodePen 编辑器布局 + +#### mdEnhance.demo.editors + +- 类型: `string` +- 默认值: `"101"` + +CodePen 编辑器显示情况,第一位代表 HTML ,第二位代表 JS,第三位代表演示页面。 + +#### 其他 + +以下是第三方代码演示使用的库地址,除非你的环境无法访问 jsdelivr 或访问缓慢,否则无需覆盖默认设置。 + +::: warning +请注意,如果你用到了它们,你仍需要利用 `head` 手动在你的网站中导入它们。 + +React 依赖于 Babel。 +::: + +##### mdEnhance.demo.vue + +默认值: `"https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"` + +##### mdEnhance.demo.react + +默认值: `"https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js"` + +##### mdEnhance.demo.reactDOM + +默认值: `"https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js"` + ### mdEnhance.presentation - 类型: `PresentationOptions | boolean` diff --git a/docs/theme/src/zh/config/theme/readme.md b/docs/theme/src/zh/config/theme/readme.md index c29a53670336..f77ea76730e6 100644 --- a/docs/theme/src/zh/config/theme/readme.md +++ b/docs/theme/src/zh/config/theme/readme.md @@ -1,6 +1,6 @@ --- title: 主题配置 -icon: configuration +icon: config category: config tags: - themeConfig diff --git a/docs/theme/src/zh/demo/readme.md b/docs/theme/src/zh/demo/readme.md index ea433f9eefa4..a5a97c9e0368 100644 --- a/docs/theme/src/zh/demo/readme.md +++ b/docs/theme/src/zh/demo/readme.md @@ -1,6 +1,6 @@ --- title: 项目案例 -icon: discoverfill +icon: discover category: demo --- diff --git a/docs/theme/src/zh/guide/feature/markdown/demo.md b/docs/theme/src/zh/guide/feature/markdown/demo.md new file mode 100644 index 000000000000..91b5ed038d99 --- /dev/null +++ b/docs/theme/src/zh/guide/feature/markdown/demo.md @@ -0,0 +1,390 @@ +--- +icon: discover +--- + +# 代码演示 + +让你的 VuePress 站点中的 Markdown 文件支持代码案例。 + +## 配置 + +```js {7} +module.exports = { + themeConfig: { + mdEnhance: { + demo: true, + }, + }, +}; +``` + +## 语法 + +您应该使用以下语法: + +````md +::: demo [类型] + +```html + + +``` + +```json +{ + // 放置你的配置 (optional) +} +``` + +::: +```` + +::: tip +json 块是可选的。 +::: + +该插件支持三种类型: + +- vanilla (默认) +- vue +- react + +### Vanilla + +写法: + +````md +::: demo + +```html + + + + + +``` + +```json +// 配置 (可选) +``` + +:::: +```` + +### Vue + +语法: + +````md +::: demo vue + +```html + + + +``` + +```json +// 配置 (可选) +``` + +::: +```` + +### React + +语法: + +````md +::: demo react + +```js +export default class App extends React.Component { + // react 组件 +} +App.__style__ = ` + your styles +`; +``` + +::: +```` + +::: warning +该插件未捆绑任何库,因此您必须通过在 `.vuepress/config.js` 文件中设置 `head` 来导入它们。 + +```js +// .vuepress/config.js +module.exports = { + head: [ + // react 需要 React, ReactDOM 和 Babel 库 + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/react/umd/react.production.min.js" }, + ], + [ + "script", + { + src: + "https://cdn.jsdelivr.net/npm/react-dom/umd/react-dom.production.min.js", + }, + ], + [ + "script", + { src: "https://cdn.jsdelivr.net/npm/@babel/standalone/babel.min.js" }, + ], + // vue 只需要 vue 库 + ["script", { src: "https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js" }], + ], +}; +``` + +我们还进行了增强: 如果你导入 Babel,则将使用 babel 将脚本解析为 es6,以确保能在浏览器上正常运行。 +::: + +### 预处理器 + +您可以在演示块中配置预处理器。但是,在运行时仅支持 JS 预处理器 `'babel'`(你还需要手动导入 babel 独立库)。 + +当您设置其他预处理器时,由于插件无法解析它们,因此演示将被禁用,您只能看到代码。插件将为您提供一个 "在 CodePen 中打开" 按钮。 + +HTML 预处理器: + +- `"none"` (默认) +- `"slim"` +- `"haml"` +- `"markdown"` + +JS 预处理器: + +- `"none"` (默认) +- `"coffeescript"` +- `"babel"` +- `"livescript"` +- `"typescript"` + +CSS 预处理器: + +- `"none"` (默认) +- `"less"` +- `"scss"` +- `"sass"` +- `"stylus"` + +## 演示 + +::: demo + +```html + +

Mr.Hope

+

Is 十分

+ + + +``` + +::: + +````md +::: demo + +```html + +

Mr.Hope

+

Is 十分

+ + + +``` + +::: +```` + +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "十分帅" }; + } + render() { + return ( +
+ Mr.Hope {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: + +````md +::: demo react + +```js +export default class App extends React.Component { + constructor(props) { + super(props); + this.state = { message: "十分帅" }; + } + render() { + return ( +
+ Mr.Hope {this.state.message} +
+ ); + } +} +App.__style__ = ` +.box-react span { + color: red; +} +`; +``` + +::: +```` + +::: demo vue + +```html + + + +``` + +::: + +````md +::: demo vue + +```html + + + +``` + +::: +```` + +::: demo + +```html + + # 标题 十分帅! + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: + +````md +::: demo + +```html + + # 标题 十分帅! + + + +``` + +```json +{ + "html": "markdown", + "js": "typescript", + "css": "scss" +} +``` + +::: +```` diff --git a/docs/theme/src/zh/guide/feature/markdown/mark.md b/docs/theme/src/zh/guide/feature/markdown/mark.md index 7cf9657af9e4..2984fed68b1f 100644 --- a/docs/theme/src/zh/guide/feature/markdown/mark.md +++ b/docs/theme/src/zh/guide/feature/markdown/mark.md @@ -1,5 +1,5 @@ --- -icon: writefill +icon: write tags: - feature - markdown diff --git a/docs/theme/src/zh/guide/feature/page-info.md b/docs/theme/src/zh/guide/feature/page-info.md index 55ecbfd3c6b5..85fa01ab637e 100644 --- a/docs/theme/src/zh/guide/feature/page-info.md +++ b/docs/theme/src/zh/guide/feature/page-info.md @@ -1,5 +1,5 @@ --- -icon: infofill +icon: info category: feature tags: - page-info diff --git a/docs/theme/src/zh/guide/feature/readme.md b/docs/theme/src/zh/guide/feature/readme.md index 1fe88485657e..f96d7ed81c24 100644 --- a/docs/theme/src/zh/guide/feature/readme.md +++ b/docs/theme/src/zh/guide/feature/readme.md @@ -1,5 +1,5 @@ --- -icon: discoverfill +icon: discover category: feature tags: - intro @@ -35,7 +35,7 @@ tags: 请在 `.vuepress/styles` 的 `index.styl` 中导入对应的图标 CSS 文件。例如: ```css - @import "//at.alicdn.com/t/font_1446717_giwlq66d28j.css"; + @import "//at.alicdn.com/t/font_1446717_q5huxk6v1h.css"; ``` 图标会默认添加 `iconfont` 类名,图标 class 的前缀默认为 `icon-`,可以在主题配置中的 `iconPrefix` 字段进行更改。 diff --git a/docs/theme/src/zh/guide/feature/theme.md b/docs/theme/src/zh/guide/feature/theme.md index 29d7290ad801..a15b01c3bdbe 100644 --- a/docs/theme/src/zh/guide/feature/theme.md +++ b/docs/theme/src/zh/guide/feature/theme.md @@ -1,5 +1,5 @@ --- -icon: skinfill +icon: skin category: feature tags: - style diff --git a/docs/theme/src/zh/guide/layout/home.md b/docs/theme/src/zh/guide/layout/home.md index 2c50ea19cf3f..da4ead02cfcf 100644 --- a/docs/theme/src/zh/guide/layout/home.md +++ b/docs/theme/src/zh/guide/layout/home.md @@ -1,5 +1,5 @@ --- -icon: homefill +icon: home category: layout tags: - home @@ -83,7 +83,7 @@ tags: --- home: true title: vuepress-theme-hope -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-theme-hope tagline: 一个具有强大功能的 vuepress 主题✨ diff --git a/docs/theme/src/zh/guide/layout/navbar.md b/docs/theme/src/zh/guide/layout/navbar.md index 988c17be950d..ab98bbcb4644 100644 --- a/docs/theme/src/zh/guide/layout/navbar.md +++ b/docs/theme/src/zh/guide/layout/navbar.md @@ -21,8 +21,8 @@ tags: module.exports = { themeConfig: { nav: [ - { text: "主页", link: "/", icon: "homefill" }, - { text: "VuePress介绍", link: "/vuepress/", icon: "infofill" }, + { text: "主页", link: "/", icon: "home" }, + { text: "VuePress介绍", link: "/vuepress/", icon: "info" }, { text: "Markdown介绍", link: "/markdown/", icon: "markdown" }, ], }, @@ -85,7 +85,7 @@ module.exports = { nav: [ { text: "基础", - icon: "infofill", + icon: "info", prefix: "/basic/", items: [ { text: "Markdown", link: "markdown", icon: "markdown" }, @@ -256,12 +256,12 @@ module.exports = { themeConfig: { nav: [ // 可在每一项中添加 icon 字段来显示图标 - { text: "主页", link: "/zh/", icon: "homefill" }, - { text: "指南", link: "/zh/guide/", icon: "creativefill" }, + { text: "主页", link: "/zh/", icon: "home" }, + { text: "指南", link: "/zh/guide/", icon: "creative" }, { text: "配置", link: "/zh/config/", icon: "code" }, { text: "基础", - icon: "infofill", + icon: "info", prefix: "/zh/basic/", items: [ { text: "Markdown", link: "markdown", icon: "markdown" }, diff --git a/docs/theme/src/zh/guide/layout/sidebar.md b/docs/theme/src/zh/guide/layout/sidebar.md index 2d0cef9915ae..6b0614111b16 100644 --- a/docs/theme/src/zh/guide/layout/sidebar.md +++ b/docs/theme/src/zh/guide/layout/sidebar.md @@ -209,13 +209,13 @@ module.exports = { "/zh/guide/": [ { title: "快速上手", - icon: "creativefill", + icon: "creative", collapsable: false, children: ["", "install"], }, { title: "新增功能", - icon: "discoverfill", + icon: "discover", prefix: "feature/", collapsable: false, children: [ diff --git a/docs/theme/src/zh/guide/readme.md b/docs/theme/src/zh/guide/readme.md index b9a39bc599b4..d94778ed79c6 100644 --- a/docs/theme/src/zh/guide/readme.md +++ b/docs/theme/src/zh/guide/readme.md @@ -1,5 +1,5 @@ --- -icon: infofill +icon: info category: instruction tags: intro --- diff --git a/docs/theme/src/zh/readme.md b/docs/theme/src/zh/readme.md index 54e8bdd81a3f..081385993226 100644 --- a/docs/theme/src/zh/readme.md +++ b/docs/theme/src/zh/readme.md @@ -1,7 +1,7 @@ --- home: true title: vuepress-theme-hope -icon: homefill +icon: home heroImage: /logo.svg heroText: vuepress-theme-hope tagline: 一个具有强大功能的 vuepress 主题✨ diff --git a/packages/comment/PageInfo.vue b/packages/comment/PageInfo.vue index bab9cef8b85d..66a71064f02e 100644 --- a/packages/comment/PageInfo.vue +++ b/packages/comment/PageInfo.vue @@ -86,6 +86,6 @@ $pageInfoTextSize ?= 14px height 1em margin-right 0.25em - .theme-default-content:not(.custom) h1:first-child + .theme-default-content:not(.custom) > h1:first-child display none diff --git a/packages/md-enhance/LICENSE b/packages/md-enhance/LICENSE index 714a1138ad6a..1a51a51cfef0 100644 --- a/packages/md-enhance/LICENSE +++ b/packages/md-enhance/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2014-2015 Vitaly Puzrin, Alex Kocharin. +Copyright (c) 2018 melon Copyright (C) 2020 by MrHope Permission is hereby granted, free of charge, to any person diff --git a/packages/md-enhance/lib/index.ts b/packages/md-enhance/lib/index.ts index 55a1d3c2d4b0..d50ac8c538de 100644 --- a/packages/md-enhance/lib/index.ts +++ b/packages/md-enhance/lib/index.ts @@ -2,6 +2,7 @@ import { resolve } from "path"; import lineNumbers = require("@vuepress/markdown/lib/lineNumbers"); +import { codeDemoDefaultSetting } from "./markdown-it/code-demo"; import flowchart from "./markdown-it/flowchart"; import footnote from "./markdown-it/footnote"; import katex from "./markdown-it/katex"; @@ -26,6 +27,12 @@ export = ( define: (): Record => ({ MARKDOWN_ENHANCE_OPTIONS: markdownOption, + CODE_DEMO_OPTIONS: { + ...codeDemoDefaultSetting, + ...(typeof markdownOption.codeDemo === "boolean" + ? {} + : markdownOption.codeDemo), + }, REVEAL_PLUGINS: typeof markdownOption.presentation === "object" && Array.isArray(markdownOption.presentation.plugins) @@ -40,6 +47,8 @@ export = ( enhanceAppFiles: resolve(__dirname, "../src/enhanceAppFile.js"), + clientRootMixin: resolve(__dirname, "../src/clientRootMixin.js"), + chainMarkdown: (md): void => { if (markdownOption.lineNumbers !== false) md.plugin("line-numbers").use(lineNumbers); diff --git a/packages/md-enhance/lib/markdown-it/code-demo.ts b/packages/md-enhance/lib/markdown-it/code-demo.ts new file mode 100644 index 000000000000..ac83480f3aa4 --- /dev/null +++ b/packages/md-enhance/lib/markdown-it/code-demo.ts @@ -0,0 +1,55 @@ +import hash = require("hash-sum"); +import Token = require("markdown-it/lib/token"); + +export const codeDemoRender = (tokens: Token[], idx: number): string => { + const { nesting, info } = tokens[idx]; + + if (nesting === -1) + return ` + + + `; + + let codeStr = ""; + let configStr = ""; + + for (let i = idx; i < tokens.length; i++) { + const { type, content, info } = tokens[i]; + if (type === "container_demo_close") break; + if (!content) continue; + if (type === "fence") { + if (info === "json") configStr = encodeURIComponent(content); + else codeStr = encodeURIComponent(content); + } + } + + return ` +