import Chart from 'chart.js' function render () { document.querySelectorAll('.chartjs').forEach(element => { try { // eslint-disable-next-line no-new new Chart(element, JSON.parse(element.textContent)) } catch (e) { element.outerHTML = `
Chart.js complains: "${e}"` } }) } const chartPlugin = (md) => { const temp = md.renderer.rules.fence.bind(md.renderer.rules) md.renderer.rules.fence = (tokens, idx, options, env, slf) => { const token = tokens[idx] if (token.info && token.info.trim() === 'chart') { const code = token.content.trim() try { const json = JSON.parse(code) return `` } catch (e) { // JSON.parse exception return `
${e}` } } return temp(tokens, idx, options, env, slf) } } export default { render, chartPlugin }