import markdownit from 'markdown-it' import emoji from 'markdown-it-emoji' import math from '@rokt33r/markdown-it-math' import hljs from 'highlight.js' const katex = window.katex function createGutter (str) { let lc = (str.match(/\n/g) || []).length let lines = [] for (let i = 1; i <= lc; i++) { lines.push('' + i + '') } return '' + lines.join('') + '' } var md = markdownit({ typographer: true, linkify: true, html: true, xhtmlOut: true, highlight: function (str, lang) { if (lang && hljs.getLanguage(lang)) { try { return '
' +
        createGutter(str) +
        '' +
        hljs.highlight(lang, str).value +
        '
' } catch (e) {} } return '
' +
    createGutter(str) +
    '' +
    str.replace(/\&/g, '&').replace(/\/g, '>').replace(/\"/g, '"') +
    '
' } }) md.use(emoji, { shortcuts: {} }) md.use(math, { inlineRenderer: function (str) { let output = '' try { output = katex.renderToString(str.trim()) } catch (err) { output = `${err.message}` } return output }, blockRenderer: function (str) { let output = '' try { output = katex.renderToString(str.trim(), {displayMode: true}) } catch (err) { output = `
${err.message}
` } return output } }) md.use(require('markdown-it-footnote')) window.md = md export default function markdown (content) { if (content == null) content = '' content = content.toString() .split('\n') .map((line, index) => { if (line.trim().length === 0) return '' return line + '' }) .join('\n') return md.render(content) }