wujingjing
2024-09-19 2ad14a103d93ce48e2ffdd970569ea9eb1524f27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import highlight from 'highlight.js';
import Markdown from 'markdown-it';
 
const mdOptions: Markdown.Options = {
    linkify: true,
    typographer: true,
    breaks: true,
    langPrefix: 'language-',
    // 代码高亮
    highlight(str, lang) {
        if (lang && highlight.getLanguage(lang)) {
            try {
                return '<pre class="hljs"><code>' + highlight.highlight(lang, str, true).value + '</code></pre>';
            } catch (__) {
      }
        }
        return '';
    },
};
 
export const md = new Markdown(mdOptions);