fix: handle crash issue on hljs highlighting (#859)

This commit is contained in:
Louis 2023-12-05 16:30:47 +07:00 committed by GitHub
parent 5b76862a10
commit 848bdbc148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,7 +29,11 @@ const marked = new Marked(
if (lang === undefined || lang === '') { if (lang === undefined || lang === '') {
return hljs.highlightAuto(code).value return hljs.highlightAuto(code).value
} }
return hljs.highlight(code, { language: lang }).value try {
return hljs.highlight(code, { language: lang }).value
} catch (err) {
return hljs.highlight(code, { language: 'javascript' }).value
}
}, },
}), }),
{ {