Merge pull request #506 from rtfpessoa/fix-error-unloaded-lang

fallback to plaintext when highlighting unloaded language
This commit is contained in:
Rodrigo Fernandes 2023-08-27 21:40:19 +01:00 committed by GitHub
commit 61d90c1c41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 => {