You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
840 B
35 lines
840 B
import MarkdownIt from 'markdown-it'; |
|
import MarkdownItKaTeX from '@traptitech/markdown-it-katex'; |
|
import hljs from 'highlight.js'; |
|
import 'highlight.js/styles/atom-one-dark.css'; |
|
import './Markdown.css'; |
|
|
|
import 'katex/dist/katex.min.css'; |
|
|
|
let md = new MarkdownIt({ |
|
html: false, |
|
linkify: false, |
|
breaks: true, |
|
inline: true, |
|
highlight(str, lang) { |
|
if (lang && hljs.getLanguage(lang)) { |
|
try { |
|
return ( |
|
'<pre class="hljs"><code>' + |
|
hljs.highlight(lang, str, true).value + |
|
'</code></pre>' |
|
); |
|
} catch (__) {} |
|
} |
|
return ( |
|
'<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>' |
|
); |
|
}, |
|
}).use(MarkdownItKaTeX, { |
|
throwOnError: false, |
|
errorColor: '#aa0000', |
|
}); |
|
|
|
export default function renderMarkdown(text) { |
|
return md.render(text); |
|
}
|
|
|