Rename former vite-plugin-vuedoc to vite-plugin-md-preview
Removed markdown parsing capability and used it in combination with vite-plugin-md.
Features
Markdown Vue code block preview
Custom preview component, custom display style
Hot update support
Use
Installation
npm i vite-plugin-md vite-plugin-md-preview -D
# or
yarn add vite-plugin-md vite-plugin-md-preview -D
vite.config.ts
importVuefrom'@vitejs/plugin-vue'importshikifrom'markdown-it-shiki'importMarkdownfrom'vite-plugin-md'importMarkdownPreview,{transformer}from'vite-plugin-md-preview'exportdefault{plugins: [Vue({include: [/\.vue$/,/\.md$/],// Need to include .md files}),Markdown({transforms: {before: transformer,// -> 1. add transformer to vite-plugin-md},markdownItSetup(md){md.use(shiki,{theme: 'github-light'})// Support code highlighting},}),MarkdownPreview(),// -> 2. Add plugins],}
Register the VueCode component
The plugin does not contain a concrete implementation of the preview component, developers need to implement VueCode and register it global.
This component have a slot and receives a prop named source
#This is a markdown file##Below is the code with preview capability```vue preview<template> <div> <button @click="click">button</button> </div></template><script setup>const click = () => { alert('a')}</script>```
Highlight
vite-plugin-md-preview has shiki built in to support code highlighting.
Note that this option does not handle other non-code highlighting in markdown, and can be made consistent by adding the markdown-it-shiki plugin to vite-plugin-md.
importVuefrom'@vitejs/plugin-vue'importshikifrom'markdown-it-shiki'importMarkdownfrom'vite-plugin-md'importMarkdownPreview,{transformer}from'vite-plugin-md-preview'exportdefault{plugins: [Vue({include: [/\.vue$/,/\.md$/],// Need to include .md files}),Markdown({transforms: {before: transformer,},markdownItUses: [[shiki,{theme: 'github-light'}]],// markdown code highlighting}),MarkdownPreview({shiki: {theme: 'github-light'},// Code highlighting}),],}
请发表评论