BuptStEve / vuepress-plugin-demo-code

📝 Demo and code plugin for vuepress
https://buptsteve.github.io/vuepress-plugin-demo-code/
MIT License
124 stars 28 forks source link
code demo vuepress vuepress-plugin

vuepress-plugin-demo-code

Downloads per month Version Next Version License

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

Features

Install

$ npm i -D vuepress-plugin-demo-code
# OR
$ pnpm i -D vuepress-plugin-demo-code
# OR
$ yarn add -D vuepress-plugin-demo-code
$ 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

Usage

Write vuepress config

module.exports = {
  plugins: ['demo-code'],
}

Options

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/animate.css@3.7.0/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: { ... },
    }]
  ],
}

jsLibs

Js libraries for the demo.

cssLibs

Css libraries for the demo.

vueVersion

The semantic version string of vue. For more information on semantic versioning syntax, see the npm semver calculator.

showText

The display text of unfold code button.

hideText

The display text of fold code button.

minHeight

The height of the code when it is folded.

onlineBtns

Display online edit buttons.

jsfiddle

It passes jsfiddle options.

codesandbox

It passes CodeSandbox options.

deps is dependencies

demoCodeMark

The mark of the plugin, follows the tag after :::.

copyOptions

It passes vuepress-plugin-code-copy's options, or false to disable it.

Related

License

MIT

Copyright (c) StEve Young

Contributors ✨

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!