1
0
Fork 0
mirror of synced 2024-11-12 20:28:58 -05:00
ultimate-vim/sources_non_forked/markdown-preview.nvim/app/pages/dot.js
2022-05-19 20:12:11 +08:00

39 lines
1.1 KiB
JavaScript

let options = {}
const dot = (md, opts = {}) => {
options = opts
const temp = md.renderer.rules.fence.bind(md.renderer.rules)
md.renderer.rules.fence = (tokens, idx, options, env, slf) => {
const token = tokens[idx]
try {
if (token.info && (token.info.trim() === 'dot' || token.info.trim() === 'graphviz')) {
const code = token.content.trim()
return `<div class="dot">${code}</div>`
}
} catch (e) {
console.error(`Parse flowchart Error: `, e)
}
return temp(tokens, idx, options, env, slf)
}
}
export const renderDot = () => {
let list = document.querySelectorAll('.dot')
if (!list) {
return
}
var viz = new Viz();
list.forEach(item => {
viz.renderSVGElement(item.textContent).then(function (e) {
item.textContent = ''
item.appendChild(e)
})
.catch(e => {
var viz = new Viz();
console.error(`Parse dot Error: ${e}`)
})
})
list = null
}
export default dot