4.0.2 โ€ข Published 2 years ago

@adapttive/vue-markdown v4.0.2

Weekly downloads
332
License
MIT
Repository
github
Last release
2 years ago

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

NameParamTypeDescribe
renderedoutHtmlStringdispatch when render finish
toc-renderedtocHtmlStringdispatch when TOC render finish, never dispatch if the tocprop 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