English | 简体中文
demo-code plugin for vuepress.
With this plugin, you can both display demo and code via following syntax.
::: demo
<div @click="onClick">Click me!</div>
<script>
export default {
methods: {
onClick: () => { window.alert(1) },
},
}
</script>
:::
Please click here to see the demo
- Only one source code
- Foldable code
- Support online editing
- ✔ Codepen
- ✔ JSFiddle
- ✔ CodeSandbox
- Designed for long code
- Sticky fold button
- Auto scroll to top when you fold code
-
First of all, install vuepress v1.x
-
Then install the plugin
$ npm i -D vuepress-plugin-demo-code
# OR
$ pnpm i -D vuepress-plugin-demo-code
# OR
$ yarn add -D vuepress-plugin-demo-code
- If you are using vuepress 2.x, please install the next version.
$ npm i -D vuepress-plugin-demo-code@next
# OR
$ pnpm i -D vuepress-plugin-demo-code@next
# OR
$ yarn add -D vuepress-plugin-demo-code@next
Write vuepress config
module.exports = {
plugins: ['demo-code'],
}
This plugin supports the following configurations.
module.exports = {
plugins: [
['demo-code', {
jsLibs: [
// umd
'https://unpkg.com/tua-storage/dist/TuaStorage.umd.js',
],
cssLibs: [
'https://unpkg.com/[email protected]/animate.min.css',
],
vueVersion: '^3',
showText: 'show code',
hideText: 'hide',
styleStr: 'text-decoration: underline;',
minHeight: 200,
onlineBtns: {
codepen: true,
jsfiddle: true,
codesandbox: true,
},
jsfiddle: {
framework: 'library/pure', // default
// framework: 'vue/2.6.11',
},
codesandbox: {
deps: { 'lodash': 'latest' },
json: '',
query: '',
embed: '',
},
demoCodeMark: 'demo-code',
copyOptions: { ... },
}]
],
}
- Type:
Array
- Default:
[]
Js libraries for the demo.
- Type:
Array
- Default:
[]
Css libraries for the demo.
- Type:
String
(semantic versioning syntax) - Default:
^2.6.14
The semantic version string of vue. For more information on semantic versioning syntax, see the npm semver calculator.
- Type:
String
- Default:
show code
The display text of unfold code button.
- Type:
String
- Default:
hide code
The display text of fold code button.
- Type:
Number
- Default:
200
(px)
The height of the code when it is folded.
- Type:
Object
- Default:
{ codepen: true, jsfiddle: true, codesandbox: true }
Display online edit buttons.
- Type:
Object
- Default:
{ framework: 'library/pure' }
It passes jsfiddle options.
- Type:
Object
- Default:
{ deps: {}, json: '', query: 'module=App.vue'', embed: '' }
It passes CodeSandbox options.
deps
is dependencies
- Type:
String
- Default:
demo
The mark of the plugin, follows the tag after :::
.
- Type:
Object/Boolean
- Default:
{ align: 'top', selector: '.demo-and-code-wrapper div[class*="language-"] pre' }
It passes vuepress-plugin-code-copy's options, or false
to disable it.
Copyright (c) StEve Young
Thanks goes to these wonderful people (emoji key):
StEve Young 💻 📖 🚇 🌍 |
leandrofngl 🐛 |
Tian Jian 🐛 |
Spence 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!