Commit cc759bef authored by Steven's avatar Steven

fix: handle highlight unknown language error

parent d670adc1
...@@ -10,11 +10,18 @@ const renderer = (rawStr: string): string => { ...@@ -10,11 +10,18 @@ const renderer = (rawStr: string): string => {
} }
const language = escape(matchResult[1]) || "plaintext"; const language = escape(matchResult[1]) || "plaintext";
const highlightedCodes = hljs.highlight(matchResult[2], { let highlightedCode = hljs.highlightAuto(matchResult[2]).value;
language,
}).value;
return `<pre><code class="language-${language}">${highlightedCodes}</code></pre>${matchResult[3]}`; try {
const temp = hljs.highlight(matchResult[2], {
language,
}).value;
highlightedCode = temp;
} catch (error) {
// do nth
}
return `<pre><code class="language-${language}">${highlightedCode}</code></pre>${matchResult[3]}`;
}; };
export default { export default {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment