1
0
Fork 0
mirror of synced 2024-11-15 21:48:57 -05:00
ultimate-vim/sources_non_forked/markdown-preview.nvim/app/pages/plantuml.js

27 lines
928 B
JavaScript
Raw Normal View History

2022-05-19 08:12:11 -04:00
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)
}
}