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

26 lines
928 B
JavaScript

const plantumlEncoder = require("plantuml-encoder");
function generateSourceDefault (umlCode, pluginOptions) {
var imageFormat = pluginOptions.imageFormat || 'img'
var diagramName = pluginOptions.diagramName || 'uml'
var server = pluginOptions.server || 'https://www.plantuml.com/plantuml'
var zippedCode = plantumlEncoder.encode(umlCode)
return server + '/' + imageFormat + '/' + zippedCode
}
export default (md, 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.indexOf('plantuml') != -1 ) {
const code = token.content.trim()
return `<img src="${generateSourceDefault(code, opts)}" alt="" />`
}
} catch (e) {
console.error(`Parse Diagram Error: `, e)
}
return temp(tokens, idx, options, env, slf)
}
}