@adapttive/vue-markdown

中文文档
4.0.2发布于 2022/08/28MITTypeScriptCommonJS近 30 天下载 8209

A Powerful and High speed Markdown Parser for Vue

原始使用文档
文档目录6 节
  1. Browser globals
  2. NPM
  3. Yarn
  4. Migrating from vue-markdown 2.3
  5. CommonJS
  6. ES6 (Vue-CLI users)

vue-markdown

npm npm npm npm npm

If you want vue-markdown for vue1.X.X, please checkout vue-markdown1.X.X.

A Powerful and Highspeed Markdown Parser for Vue.

Quick start: <vue-markdown>i am a ~~tast~~ **test**.</vue-markdown>

Supported Markdown Syntax:

  • automatic table of contents
  • table & class customize
  • *SyntaxHighlighter
  • definition list
  • strikethrough
  • GFM task list
  • abbreviation
  • superscript
  • subscript
  • footnote
  • insert
  • emoji
  • mark
  • *katex

*SyntaxHighlighter work with Prism recommend

*katex need add katex css.

Example

simple

webpack-simple

Live Demo

Installation

Browser globals

The dist folder contains vue-markdown.js with the component exported in the window.VueMarkdown object.

<body>
  <vue-markdown>i am a ~~tast~~ **test**.</vue-markdown>
</body>
<script src="path/to/vue.js"></script>
<script src="path/to/vue-markdown.js"></script>
<script>
    Vue.use(VueMarkdown);
    var vm = new Vue({
        el: "body"
    });
</script>

NPM

$ npm install --save @adapttive/vue-markdown

Yarn

$ yarn add @adapttive/vue-markdown --save

Migrating from vue-markdown 2.3

  • You just need to replace the dependencies in package.json:
{
  "dependencies": {
-  "vue-markdown": "^2.2.4
+  "vue-markdown": "npm:@adapttive/vue-markdown@^X.X.X"
  }
}

CommonJS

var VueMarkdown = require('@adapttive/vue-markdown');

new Vue({
  components: {
    'vue-markdown': VueMarkdown
  }
})

ES6 (Vue-CLI users)

After installing via Yarn or NPM, use the following snippet in the script portion of the Vue component which you wish to render the Markdown.

import VueMarkdown from '@adapttive/vue-markdown'

new Vue({
  components: {
    VueMarkdown
  }
})

Slots

<vue-markdown>this is the default slot</vue-markdown>

After setting up the middleware in your vue component above, using the embedded markdown is as easy as writing it between the vue-markdown tags.

VueMarkdown has a default slot which is used to write the markdown source.

TIP: The default slot only renders once at the beginning, and it will overwrite the prop of source!

Props

PropTypeDefaultDescribe
watchesArray["source", "show", "toc"]HTML refresh automatically when the prop in this array changed
sourceStringnullthe markdown source code
showBooleantrueenable render to the default slot automatically
htmlBooleantrueenable HTML syntax in source
xhtml-outBooleantrue<br></br> => <br />
breaksBooleantrue\n => <br>
linkifyBooleantrueautoconvert URL-like text to link
emojiBooleantrue:) => 😃
typographerBooleantrueenable some language-neutral replacement and quotes beautification
update-prismBooleantrueif true, vue-markdown will automatically call a re-render of all code blocks through Prism.js (Using Prism.js)
lang-prefixStringlanguage-CSS language prefix for fenced blocks
quotesString“”‘’use “”‘’ for Chinese, „“‚‘ for German, «»„“ for Russian
table-classStringtablecustomize html class of the <table>
task-listsBooleantrueMakes GFM task lists mutable, false shows GFM as readonly checkboxes
tocBooleanfalseenable automatic table of contents
toc-idStringundefinedthe HTML id to render TOC
toc-classStringtablecustomize html class of the <ul> wrapping the TOC
toc-first-levelNumber2use 2 if you want to skip <h1> from the TOC
toc-last-levelNumber'toc-first-level' + 1use 5 if you want to skip <h6> from the TOC
toc-anchor-linkBooleantrueenable the automatic anchor link in the headings
toc-anchor-classStringtoc-anchorcustomize the anchor class name
toc-anchor-link-symbolString#customize the anchor link symbol
toc-anchor-link-spaceBooleantrueenable inserting a space between the anchor link and heading
toc-anchor-link-classStringtoc-anchor-linkcustomize the anchor link symbol class name
toc-anchor-link-beforeBooleantrueallows you to prepend/append the anchor link in the headings
anchorAttributesObject{}anchor tag attributes such as target: '_blank' or rel: 'nofollow'
prerenderFunction (String) Stringnullfilter function before markdown parse
postrenderFunction (String) Stringnullfilter function after markdown parse
inlineBooleanfalseresult will NOT be wrapped into <p> tags

Events

NameParam[Type]Describe
renderedoutHtml[String]dispatch when render finish
toc-renderedtocHtml[String]dispatch when TOC render finish, never dispatch if the toc[prop] is false

Using Prism.js

  1. Visit the download page
  2. Select all the options that apply for your project
  3. At the bottom of the page download both the JS and CSS
  4. Include them in your index.html MAKE SURE to include Prism before your app.js

Plugins

 <template>
   <div>
     <vue3-markdown-it :source='source' :plugins='plugins' />
   </div>
 </template>

 <script>
 import katex from 'markdown-it-katex';
 import tasklists from 'markdown-it-task-lists';
 import externalPreview from 'markdown-it-external-preview';
 import VueMarkdown from 'vue-markdown';

 export default {
   components: {
     VueMarkdown
   },
   data() {
     return {
       plugins: [
         {
           plugin: katex,
           options: { throwOnError: false, errorColor: ' #cc0000' }
         },
         {
           plugin: tasklists,
           options: { enabled: this.taskLists }
         },
         {
           plugin: externalPreview
         }
       ]
     }
   }
 }
 </script>
  • Make sure you add dependencies for plugins:
    • "highlight.js": "^10.4.0"
    • "markdown-it-external-preview": "^1.0.4"
    • "markdown-it-katex": "npm:@iktakahiro/markdown-it-katex@^4.0.1"

Thanks

Contributions

License

Copyright (c) 2016

版本与发布记录

@adapttive/vue-markdown 共发布 20 个版本,首次发布于 2020/12/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.2latest2022/08/284 年前
4.0.12021/03/075 年前
4.0.0alpha2021/02/165 年前
3.0.32020/12/265 年前
3.0.22020/12/265 年前
3.0.12020/12/265 年前

其他发布通道:beta → 3.0.0-beta.2,alpha → 4.0.0。

关于 @adapttive/vue-markdown 的常见问题

@adapttive/vue-markdown 是什么?

A Powerful and High speed Markdown Parser for Vue

如何安装 @adapttive/vue-markdown?

在项目目录运行 npm install @adapttive/vue-markdown,或使用 pnpm add / yarn add / bun add。

@adapttive/vue-markdown 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adapttive/vue-markdown 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adapttive/vue-markdown 可以商用吗?

@adapttive/vue-markdown 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adapttive/vue-markdown 的下载量有多少?

根据 npm 官方下载统计,@adapttive/vue-markdown 在 2026/10/05 – 2026/11/03 这 30 天内被下载 8,209 次,日均约 274 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adapttive/vue-markdown 还在维护吗?

最新版本 4.0.2 发布于 2022/08/28(4 年前);至今共发布 20 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/12/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。