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

md-enhance-vue

v1.0.4

Published

一个支持在 markdown 中写 Vue 的 webpack loader~

Downloads

12

Readme

md-enhance-vue

一个支持在 markdown 中写 Vue 的 webpack loader~

支持特性 ✨✨✨:

  1. 支持 .md 文件渲染
  2. 支持在 markdown 中 Vue 模板渲染
  3. 支持在 Vue 模板中使用 import
  4. 支持代码高亮(使用 prismjs)
  5. 支持传递 vue-loader 的所有特性(需要项目配置支持)

安装

yarn add md-enhance-vue -D
# OR
npm install md-enhance-vue -D

webpack 使用

支持在 webpack 中配置使用。

// webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.md$/,
        use: [
          {
            loader: "vue-loader",
            options: {
              compilerOptions: {
                preserveWhitespace: false,
              },
            },
          },
          {
            loader: "md-enhance-vue",
            options: {
              // ... 见下文
            },
          },
        ],
      },
    ],
  },
};

vue-cli 使用

支持在 vue-cli 脚手架中配置使用。

// vue.config.js

module.exports = {
  chainWebpack: (config) => {
    config.module
      .rule("md-loader")
      .test(/\.md$/)
      .use("vue-loader")
      .loader("vue-loader")
      .options({
        compilerOptions: {
          preserveWhitespace: false,
        },
      })
      .end()
      .use("md-enhance-vue")
      .loader("md-enhance-vue")
      .options({
        // ... 见下文
      })
      .end();
  },
};

eslint ignore

如果配置了 eslint,则需要在 .eslintignore 文件中添加忽略,避免格式化问题。

*.md

options 扩展选项

{
  lineNumbers: true, // 是否启用行号,默认启用
  // markdown-it-table-of-contents options see: https://github.com/martinlissmyr/markdown-it-table-of-contents
  toc: {},
  // markdown-it-anchor options see: https://github.com/valeriangalliat/markdown-it-anchor
  anchor: {
    permalink: true,
    permalinkBefore: true,
    permalinkSymbol: "$"
  }
}

用法

使用时需要将 vue 模板写在以 :::demo 开头,::: 结束 的标签中,能识别以 vue、html 包裹的代码块。支持配置的所有以 .vue 单文件支持的写法

# 支持标题

我是一段文字

:::demo

```vue
<script>
export default {
  template: `<div>
    支持内联组件(需要配合 Vue 的 runtimeCompiler 模式)
  </div>`,
};
</script>
```

:::

:::demo

```vue
<script>
export default {
  render() {
    return <div>支持 render 函数</div>;
  },
};
</script>
```

:::

:::demo

```vue
<div>
  支持无 template 包裹
</div>
<script>
export default {};
</script>
```

:::

:::demo

```vue
<div>
  支持多根元素1
</div>
<div>
  支持多根元素2
</div>

<script>
export default {};
</script>
```

:::

:::demo

```vue
<span class="text">{{ data.msg }}</span>

<script>
import data from "./data.json";
console.log("data ======> ", data);

export default {
  data() {
    return {
      data,
    };
  },
};
</script>
<style>
.text {
  color: #f00;
}
</style>
```

:::

:::demo

```vue
<template>
  <div>
    <span class="text">支持 scss 样式</span>
  </div>
</template>

<script>
export default {};
</script>
<style lang="scss">
div {
  .text {
    color: #f00;
  }
}
</style>
```

:::

完整示例

需要注意的是文档挂载在全局组件 demo-block 下,所以你需要创建并使用组件 demo-block,另外还需要引入 markdown 支持的样式文件。

<template>
  <div class="demo-block">
    <slot name="source"></slot>
  </div>
</template>

<script>
export default {
  name: "DemoBlock",
};
</script>
// main.js
import DemoBlock from "./components/demo-block";
Vue.component("demo-block", DemoBlock);

更多使用可参考 https://github.com/luchx/ECHI_UI

原理

请参考文章 ✨ 在 Markdown 中 使用 Vue