npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xuanmo/vite-plugin-md-preview

v0.0.13

Published

<p> <a href="https://www.npmjs.com/package/vite-plugin-md-preview" target="_blank"> <img alt="Version" src="https://img.shields.io/npm/v/vite-plugin-md-preview.svg"> </a> <a href="https://www.npmjs.com/package/vite-plugin-md-preview" target="_bl

Downloads

23

Readme

vite-plugin-md-preview

Markdown code block preview plugin, write component demo in markdown using ```.

This plugin needs to be used in combination with vite-plugin-md to provide vue block preview capability for markdown.

Example: https://vite-plugin-md-preview.vercel.app

中文文档

Breaking Change

Rename former vite-plugin-vuedoc to vite-plugin-md-preview Removed markdown parsing capability and used it in combination with vite-plugin-md.

Features

  • [x] Markdown Vue code block preview
  • [x] Custom preview component, custom display style
  • [x] 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

import Vue from '@vitejs/plugin-vue'
import shiki from 'markdown-it-shiki'
import Markdown from 'vite-plugin-md'
import MarkdownPreview, { transformer } from 'vite-plugin-md-preview'

export default {
  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

Example:

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  props: {
    source: { type: String, default: '' },
  },
})
</script>
<template>
  <div class="demo">
    <div class="demo__preview">
      <slot></slot>
    </div>
    <div class="demo__source" v-html="decodeURIComponent(source)"></div>
  </div>
</template>

Register as a global component

const app = createApp(App)

app.component('VueCode', VueCode) // 必须的
app.mount('#app')

import the markdown file

<template>
  <HelloWorld />
</template>

<script>
import HelloWorld from './README.md'

export default {
  components: {
    HelloWorld,
  },
}
</script>

Using code blocks in markdown files

带有 preview 标记的 vue 代码块支持实时预览

# 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.

import Vue from '@vitejs/plugin-vue'
import shiki from 'markdown-it-shiki'
import Markdown from 'vite-plugin-md'
import MarkdownPreview, { transformer } from 'vite-plugin-md-preview'

export default {
  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
    }),
  ],
}

License

MIT License © 2020-PRESENT Jaskang