Skip to content

Commit ad42303

Browse files
committed
fix(#234): Default hightlight lang to plaintext
1 parent 12d1d7d commit ad42303

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/parser/highlight.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import hljs from 'highlight.js';
22

33
export default function highlight(str: string, lang: string) {
44
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-
}
5+
if (!lang) {
6+
lang = 'text';
7+
}
8+
if (hljs.getLanguage(lang)) {
9+
try {
10+
content = hljs.highlight(content, {
11+
language: lang,
12+
ignoreIllegals: true,
13+
}).value;
14+
} catch {}
1415
}
1516
return `<pre class="language-${lang}"><code>${content}</code></pre>`;
1617
}

0 commit comments

Comments
 (0)