2.1.1 โ€ข Published 2 years ago

vue-markdown-plus v2.1.1

Weekly downloads
2,076
License
MIT
Repository
github
Last release
2 years ago

vue-markdown-plus

npm npm npm

This package only supports vue2.X.X.

A powerful and highspeed Markdown component for Vue.

This is an extension to miaolz123's vue-markdown. The last update to vue-markdow code was in 2017, and is not actively maintained (dependencies contain security vulnerabilities). This package intends to be a safe, up-to-date alternative to vue-markdown.

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

Supported Markdown Syntax:

  • automatic table of contents
  • table & class customize
  • *SyntaxHighlighter
  • definition list
  • strikethrough
  • GFM task list
  • abbreviation
  • custom attributes (class, id, etc.)
  • superscript
  • subscript
  • footnote
  • insert
  • *katex
  • emoji
  • mark

*SyntaxHighlighter work with Prism

*katex needs katex css.

Example

simple

webpack-simple

Live Demo

Installation

NPM

$ npm install --save vue-markdown-plus

Yarn

$ yarn add vue-markdown-plus --save

Browser globals (NOT RECOMMENDED)

This is not recommended for user inputs, as it will cause XSS vulnerabilities. Please use npm or yarn if possible.

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

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

CommonJS

var VueMarkdownPlus = require("vue-markdown-plus");

new Vue({
  components: {
    "vue-markdown-plus": VueMarkdownPlus,
  },
});

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 VueMarkdownPlus from "vue-markdown-plus";

new Vue({
  components: {
    VueMarkdownPlus,
  },
});

Slots

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

After setting up the middleware in your vue component above, using the embedded markdown is as easy as writing it between the vue-markdown-plus 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 use with caution, do not enable on user inputs to prevent XSS attacks
xhtml-outBooleantrue<br></br> => <br />
breaksBooleantrue\n => <br>
linkifyBooleantrueautoconvert URL-like text to link
emojiBooleantrue:) => ๐Ÿ˜ƒ
typographerBooleantrueenable some language-neutral replacement and quotes beautification
lang-prefixStringlanguage-CSS language prefix for fenced blocks
quotesStringโ€œโ€โ€˜โ€™use โ€œโ€โ€˜โ€™ for Chinese, โ€žโ€œโ€šโ€˜ for German, ยซยปโ€žโ€œ for Russian
table-classStringtablecustomize html class of the <table>
task-listsBooleantrueenable GFM task list
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
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

Events

NameParamTypeDescribe
renderedoutHtmlStringdispatch when render finish
toc-renderedtocHtmlStringdispatch when TOC render finish, never dispatch if the tocprop is false

Thanks

Contributions

License

Copyright (c) 2020 6etacat by MIT