1 parent 12d1d7d commit ad42303Copy full SHA for ad42303
1 file changed
src/parser/highlight.ts
@@ -2,15 +2,16 @@ import hljs from 'highlight.js';
2
3
export default function highlight(str: string, lang: string) {
4
let content = str;
5
- if (lang) {
6
- if (hljs.getLanguage(lang)) {
7
- try {
8
- content = hljs.highlight(content, {
9
- language: lang,
10
- ignoreIllegals: true,
11
- }).value;
12
- } catch {}
13
- }
+ if (!lang) {
+ lang = 'text';
+ }
+ if (hljs.getLanguage(lang)) {
+ try {
+ content = hljs.highlight(content, {
+ language: lang,
+ ignoreIllegals: true,
+ }).value;
14
+ } catch {}
15
}
16
return `<pre class="language-${lang}"><code>${content}</code></pre>`;
17
0 commit comments