UNPKG

markdown-it-pikchr

Version:
29 lines 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const pikchr_1 = require("pikchr"); function default_render(result) { const output = result.output.replace('svg', `svg width="${result.width}" height="${result.height}"`); return `<div style="width: 100px;">${output}</div>`; } const PikchrPlugin = (md, opts) => { const tempFence = md.renderer.rules.fence.bind(md.renderer.rules); md.renderer.rules.fence = (tokens, idx, options, env, slf) => { const token = tokens[idx]; const chunks = (token.info || ``).match(/^(\S+)(\s+(.+))?/); if (!chunks || !chunks.length) { return tempFence(tokens, idx, options, env, slf); } const lang = chunks[1]; const code = token.content.trim(); const dark_mode = lang === "pikchr-darkmode"; const pikchr = lang === "pikchr"; if (pikchr || dark_mode) { const render_f = opts ? (opts.render_f || default_render) : default_render; const result = pikchr_1.pikchrex(code, { dark_mode }); return render_f(result); } return tempFence(tokens, idx, options, env, slf); }; }; exports.default = PikchrPlugin; //# sourceMappingURL=markdown-it-plugin-pikchr.js.map