1 Star 0 Fork 26

sunzhouhui/markdown-it-vue

forked from ravenq/markdown-it-vue 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
markdown-it-plugin-mermaid.js 938 Bytes
一键复制 编辑 原始数据 按行查看 历史
ravenq 提交于 2020-10-02 09:36 . fix: #27 add mermaid options
import mermaid from 'mermaid'
const mermaidChart = (code) => {
try {
mermaid.parse(code)
return `<div class="mermaid">${code}</div>`
} catch ({ str, hash }) {
return `<pre>${str}</pre>`
}
}
const MermaidPlugin = (md, opts) => {
md.mermaid = mermaid
opts = opts || {
theme: 'default'
}
mermaid.initialize(opts)
const temp = md.renderer.rules.fence.bind(md.renderer.rules)
md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
const token = tokens[idx]
const code = token.content.trim()
if (token.info === 'mermaid') {
return mermaidChart(code)
}
const firstLine = code.split(/\n/)[0].trim()
if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) {
return mermaidChart(code)
}
return temp(tokens, idx, options, env, slf)
}
}
export default MermaidPlugin
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/sunzhouhui/markdown-it-vue.git
git@gitee.com:sunzhouhui/markdown-it-vue.git
sunzhouhui
markdown-it-vue
markdown-it-vue
master

搜索帮助