Skip to content

Commit 15dacf3

Browse files
committed
add fallback for unrecognised prism language
1 parent 6030d06 commit 15dacf3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

remark/utils.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ module.exports.addExport = function addExport(tree, name, value) {
2929
module.exports.highlightCode = function highlightCode(code, prismLanguage) {
3030
const isDiff = prismLanguage.startsWith('diff-')
3131
const language = isDiff ? prismLanguage.substr(5) : prismLanguage
32-
let highlighted = Prism.highlight(
33-
code,
34-
Prism.languages[isDiff ? 'diff' : language],
35-
prismLanguage
36-
)
32+
const grammar = Prism.languages[isDiff ? 'diff' : language]
33+
if (!grammar) {
34+
console.warn(`Unrecognised language: ${prismLanguage}`)
35+
return Prism.util.encode(code)
36+
}
37+
let highlighted = Prism.highlight(code, grammar, prismLanguage)
3738

3839
return language === 'html'
3940
? highlighted.replace(

0 commit comments

Comments
 (0)