import markdownitMentions from '@quartzy/markdown-it-mentions'; import hljs from 'highlight.js'; import katex from 'katex'; import MarkdownIt from 'markdown-it'; import imgSizePlugin from 'markdown-it-imsize'; import taskLists from 'markdown-it-task-lists'; import markdownMath from 'markdown-it-texmath'; import centerText from '../third/markdown-it-center-text'; import videoPlugin from '../utils/markdown-it/videoPlugin'; const mdParser = new MarkdownIt({ html: true, linkify: true, typographer: true, highlight(str: string, lang: string) { if (lang && hljs.getLanguage(lang)) { try { return hljs.highlight(lang, str).value; } catch (__) { console.warn(`Unable to highlight ${lang}: ${str}`); } } return ''; }, }); mdParser.use(videoPlugin); mdParser.use(imgSizePlugin); mdParser.use(centerText); mdParser.use(taskLists, { enabled: true }); mdParser.use(markdownitMentions); mdParser.use(markdownMath, { engine: katex, delimiters: 'dollars', katexOptions: { macros: { '\\RR': '\\mathbb{R}' } }, }); function renderHTML(text: string) { return mdParser.render(text); } export { renderHTML }; export default mdParser;