fallback to plaintext when highlighting unloaded language

This commit is contained in:
Rodrigo Fernandes 2023-08-27 21:37:39 +01:00
parent 41a901694d
commit f6f05db2f6
No known key found for this signature in database

View file

@ -151,7 +151,7 @@ export class Diff2HtmlUI {
this.config.highlightLanguages = new Map(Object.entries(this.config.highlightLanguages));
}
const hljsLanguage =
let hljsLanguage =
language && this.config.highlightLanguages.has(language)
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.config.highlightLanguages.get(language)!
@ -159,6 +159,11 @@ export class Diff2HtmlUI {
? getLanguage(language)
: 'plaintext';
// Fallback to plaintext in case language is not loaded
if (hljs.getLanguage(hljsLanguage) === undefined) {
hljsLanguage = 'plaintext';
}
// Collect all the code lines and execute the highlight on them
const codeLines = file.querySelectorAll('.d2h-code-line-ctn');
codeLines.forEach(line => {