1.1.2 • Published 6 months ago

vitepress-plugin-code-demo v1.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

vitepress-plugin-code-demo

Introduce

This project is based on vitepress and markdown-it implementation to display components and code examples in documents.

Installation

# npm
npm install vitepress-plugin-code-demo --save-dev

# yarn 
yarn add vitepress-plugin-code-demo -D

# pnpm
pnpm add vitepress-plugin-code-demo

Usage

configure in your vitepress/theme entry file

// ./vitepress/theme/index.ts
import { Demo, ApiTable } from '@vitepress-plugin-code-demo/components';

export default {
  ...DefaultTheme,
  enhanceApp({ app }: { app: App }) {
    app.component('Demo', Demo);
    app.component('ApiTable', ApiTable);
  }
}

configure in your vite config

// vite.config.ts
import { defineConfig } from 'vite';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { MarkdownTransform } from 'vitepress-plugin-code-demo';
import vueDocgenPlugin from 'vite-plugin-vue-docgen';

export default defineConfig(async ({ mode }) => {
  return {
    plugins: [
      vueJsx(),
      vueDocgenPlugin(),
      MarkdownTransform(),
    ],
  };
})

configure markdown to add plugin

// ./vitepress/config.ts
import { defineConfig } from 'vitepress'
import { codeDemoPlugin } from 'vitepress-plugin-code-demo';

export default defineConfig({
  markdown: {
    config(md) {
      md.use(codeDemoPlugin({
        exampleRoot: resolve(__dirname, '../'),
      }))
    }
  }v
})

Preview

<!-- normal -->
::: demo src="pro-button/normal"
:::

<!-- iframe -->
::: demo src="pro-button/normal" iframe
:::

or

<!-- normal -->
<Demo src="pro-button/normal" />

<!-- iframe -->
<Demo src="pro-button/normal" iframe height="200" />

API

propdesctype
srcThe path is relative to the examples directory, omitting the .vue suffixstring
iframeuse ifame mode, default falseboolean
heightiframe height, such as '200'number
1.1.1

6 months ago

1.1.0

6 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.1.2

6 months ago

1.0.7

10 months ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago