11 Star 99 Fork 24

ravenq / markdown-it-vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

markdown-it-vue

Build Status

Markdown Vue 组件库.

markdown-it-vue 是一个丰富的 markdown Vue 组件,markdown-it-vue 使用 markdown-it 作为 Markdown 数据解析引擎,整合多种 markdown-it 插件,并内置了一些自己的功能性插件,支持 GFM TOC、GFM style、emoji 等通用特性,还支持 mermaid charts、Echarts、flowchart.js 等多种图表,支持 AsciiMath、Latex 等数学公式渲染,支持 errro | warning | info 个性化提示。

在线示例

http://www.aqcoder.com/markdown

由于众所周知的原因,可能需要 fan qiang。

安装

npm install markdown-it-vue

特性

  • 图片大小控制及图片预览
  • Official markdown syntax.
  • GFM TOC
  • GFM style
  • emoji
  • mermaid charts
  • Echarts
  • Flowcharts.js
  • Subscript/Superscript
  • AsciiMath
  • info | error | warning message tip

使用的插件

  • markdown-it
  • markdown-it-emoji
  • markdown-it-sub
  • markdown-it-sup
  • markdown-it-footnote
  • markdown-it-deflist
  • markdown-it-abbr
  • markdown-it-ins
  • markdown-it-mark
  • markdown-it-katex
  • markdown-it-task-lists
  • markdown-it-icons
  • markdown-it-highlight
  • markdown-it-latex
  • markdown-it-container
  • markdown-it-github-toc
  • markdown-it-source-map
  • markdown-it-link-attributes

内置插件:

  • markdown-it-image
  • markdown-it-font-awsome
  • markdown-it-link-attributes
  • markdown-it-highlight
  • markdown-it-plugin-echarts
  • markdown-it-plugin-mermaid
  • markdown-it-plugin-flowchart

markdown-it 及个插件选项

使用 options 指定 markdow-it 和个插件的选项。

<markdown-it-vue class="md-body" :content="content" :options="options" />
options: {
  markdownIt: {
    linkify: true
  },
  linkAttributes: {
    attrs: {
      target: '_blank',
      rel: 'noopener'
    }
  }
}

更多 markdown-it 选项见官方文档:https://markdown-it.github.io/markdown-it/

插件默认选项如下:

{
  linkAttributes: {
    attrs: {
      target: '_blank',
      rel: 'noopener'
    }
  },
  katex: {
    throwOnError: false,
    errorColor: '#cc0000'
  },
  icons: 'font-awesome',
  githubToc: {
    tocFirstLevel: 2,
    tocLastLevel: 3,
    tocClassName: 'toc',
    anchorLinkSymbol: '',
    anchorLinkSpace: false,
    anchorClassName: 'anchor',
    anchorLinkSymbolClassName: 'octicon octicon-link'
  },
  mermaid: {
    theme: 'default'
  },
  image: {
    hAlign: 'left',
    viewer: true
  }
}

个插件详细说明见个插件官方文档。

自定义插件

it can add your plugin to markdown-it-vue by the use method.

this.$refs.myMarkdownItVue.use(MyMarkdownItPlugin)

支持高亮的语言

语言高亮使用 hilight.js 打包过大,因此只引用了常用的语言。

如果这里没有你需要的语言,欢迎提 PR。

  • html
  • json
  • css
  • shell
  • bash
  • C
  • Java
  • Python
  • C++
  • C#
  • PHP
  • SQL
  • R
  • Swift
  • Go
  • MATLAB
  • Ruby
  • Perl
  • Objective-C
  • Rust
  • Dart
  • Delphi
  • D
  • Kotlin
  • Scala
  • SAS
  • Lisp
  • Lua
  • Ada
  • Fortran
  • PowerShell
  • VBScript
  • VBscript-html
  • Groovy
  • Julia
  • Julia-repl
  • LabVIEW
  • Haskell
  • ActionScript
  • Scheme
  • TypeScript
  • F#
  • Prolog
  • Erlang

图片大小控制语法

![image size](https://http://www.aqcoder.com/ravenq-qr.png =50x50)
![image size](https://http://www.aqcoder.com/ravenq-qr.png =x50)
![image size](https://http://www.aqcoder.com/ravenq-qr.png =50x)

关于 echarts

为了减少包的大小,只引用 echarts.simple。

精简版 markdown-it-vue-light

https://github.com/ravenq/markdown-it-vue/issues/24

为了进一步缩小打包的大小,移除了 mermaid chart。这包直接引用了整个 lodash, 他本身也很大。

如果平时用不到的话,就用精简版吧。

使用示例

<template>
  <div>
    <markdown-it-vue class="md-body" :content="content" />
  </div>
</template>

<script>
import MarkdownItVue from 'markdown-it-vue'
import 'markdown-it-vue/dist/markdown-it-vue.css'
export default {
  components: {
    MarkdownItVue
  },
  data() {
    return {
      content: '# your markdown content'
    }
  }
}
</script>

使用精简版

<template>
  <div>
    <markdown-it-vue-light class="md-body" :content="content" />
  </div>
</template>

<script>
import MarkdownItVueLight from 'markdown-it-vue/dist/markdown-it-vue-light.umd.min.js'
import 'markdown-it-vue/dist/markdown-it-vue-light.css'
export default {
  components: {
    MarkdownItVueLight
  },
  data() {
    return {
      content: '# your markdown content'
    }
  }
}
</script>

示例截图

markdown-it-vue

License

MIT

MIT License Copyright (c) 2018 fanliwen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

markdown-it-vue 是一个丰富的 markdown Vue 组件,markdown-it-vue 使用 markdown-it 作为 Markdown 数据解析引擎,整合多种 markdown-it 插件,并内置了一些自己的功能性插件,支持 GFM TOC、GFM style、emoji等通用特性,还支持 mermaid charts、Echarts、flowchart.js 等多种图表,支持 AsciiMath、Latex 等数学公式 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/ravenq/markdown-it-vue.git
git@gitee.com:ravenq/markdown-it-vue.git
ravenq
markdown-it-vue
markdown-it-vue
master

搜索帮助