Merge pull request #506 from rtfpessoa/fix-error-unloaded-lang
fallback to plaintext when highlighting unloaded language
This commit is contained in:
commit
61d90c1c41
1 changed files with 6 additions and 1 deletions
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue