Giter Club home page Giter Club logo

vite-plugin-vuedoc's Introduction

Version Version

vite-plugin-vuedoc

  • Use Markdown as Vue components
  • Use Markdown Code Block as Preview components
  • Support vite 2

Feature

  • markdown components
    • matter
    • toc
    • plugins
  • vue code block
    • vue preview
    • code import
    • customizing the preview component
    • sourcemap
  • code highlight
    • theme
  • playground
  • hmr
  • tests

Used

Install

yarn add vite-plugin-vuedoc
// vite.config.ts
import vitePluginVuedoc, { vueDocFiles } from 'vite-plugin-vuedoc'
import vue from '@vitejs/plugin-vue'

const config: UserConfig = {
  plugins: [
    vitePluginVuedoc(), // 1. Must be loaded before @vitejs/plugin-vue
    vue({
      include: [...vueDocFiles] // 2. Must include .md | .vd files
    })
  ]
}

export default config

import style

import 'vite-plugin-vuedoc/style.css'

VueDocPluginOptions

  • wrapperClass: string

    The classname of the wrapped markdown component

  • previewClass: string

    The classname of the wrapped preview component

  • previewComponent: string

    The name of the custom preview component you want to use

  • markdownIt:
    • plugins: any[]

      markdownIt plugins

  • highlight:
    • theme: 'one-dark' | 'one-light' | string

      highlight theme. defalut: one-dark

import markdown

import MdComp from './docs/Button.zh-CN.md'
export const router = createRouter({
  routes: [
    { path: '/home', redirect: '/' },
    {
      path: '/button',
      name: 'button',
      component: MdComp
    }
  ]
})

VueBlock preview

when the vue code block has a demo tag, it can preview the component

```vue demo

```

code block import

in code block support import file like this:

```vue demo src="./test.vue"

```

```typescript src="./test.ts"

```

Frontmatter & Toc

// Button.zh-CN.md
---
wrapperClass: '' // wrapperClass will wrapped current md file
title: 'title'
desc: 'desc'
---
import MdComp from './docs/Button.zh-CN.md'

const { matter, toc } = MdComp.$vd
console.log(matter)
console.log(toc)
// matter: {wrapperClass, title, desc}
// toc: [{content: string; anchor: string; level: number},{content: string; anchor: string; level: number}]

Custom Preview Component

// vite.config.ts
import vitePluginVuedoc from 'vite-plugin-vuedoc'

const config: UserConfig = {
  plugins: [
    vitePluginVuedoc({
      previewComponent: 'myDemoPreview'
    })
  ]
}

export default config

register your components in you vite app

app.component('myDemoPreview', myDemoPreview)

myDemoPreview

<template>
  <slot /> <!-- Demo Component -->
  <slot name="code" /> <!-- code block html -->
</template>
<script>
export defalut {
  props:{
    lang: String,
    theme: String
  }
}
</script>

Markdown Screenshots

markdown doc

Preview Screenshots

markdown doc

vue javascript

markdown doc

vite-plugin-vuedoc's People

Contributors

hawkeye64 avatar jaskang avatar neufman avatar xxholly32 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.