1.0.0 • Published 2 years ago

vuepress-plugin-demo-code v1.0.0

Weekly downloads
473
License
MIT
Repository
github
Last release
2 years ago

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

  • 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

Install

$ npm i -D vuepress-plugin-demo-code
# OR
$ yarn add -D vuepress-plugin-demo-code

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',
            ],
            showText: 'show code',
            hideText: 'hide',
            styleStr: 'text-decoration: underline;',
            minHeight: 200,
            onlineBtns: {
                codepen: true,
                jsfiddle: true,
                codesandbox: true,
            },
            codesandbox: {
                deps: { 'lodash': 'latest' },
                json: '',
                query: '',
                embed: '',
            },
            demoCodeMark: 'demo-code',
        }]
    ],
}

jsLibs

  • Type: Array
  • Default: []

Js libraries for the demo.

cssLibs

  • Type: Array
  • Default: []

Css libraries for the demo.

showText

  • Type: String
  • Default: show code

The display text of unfold code button.

hideText

  • Type: String
  • Default: hide code

The display text of fold code button.

minHeight

  • Type: Number
  • Default: 200(px)

The height of the code when it is folded.

onlineBtns

  • Type: Object
  • Default: { codepen: true, jsfiddle: true, codesandbox: true }

Display online edit buttons.

codesandbox

  • Type: Object
  • Default: { deps: {}, json: '', query: 'module=App.vue'', embed: '' }

It passes CodeSandbox options.

deps is dependencies

demoCodeMark

  • Type: String
  • Default: demo

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

Related

License

MIT

Copyright (c) StEve Young

2.0.0-beta.1

2 years ago

2.0.0-beta.0

2 years ago

1.0.0

2 years ago

0.7.0-0

2 years ago

1.0.0-4

2 years ago

1.0.0-1

2 years ago

1.0.0-3

2 years ago

1.0.0-2

2 years ago

0.7.2

2 years ago

0.7.0

2 years ago

1.0.0-0

2 years ago

0.6.0-0

3 years ago

0.6.0

3 years ago

0.5.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.5.0-1

4 years ago

0.5.0-0

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.4.0-0

4 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.6-0

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago