fix: Calling "getLanguage" manually causes highlighting to fail

This commit is contained in:
Nihility 2021-08-08 09:48:39 +08:00
parent 04b598599a
commit 95b093b938

View file

@ -142,7 +142,6 @@ export class Diff2HtmlUI {
// HACK: help Typescript know that `this.hljs` is defined since we already checked it
if (this.hljs === null) return;
const language = file.getAttribute('data-lang');
const hljsLanguage = language ? this.hljs.getLanguage(language) : undefined;
// Collect all the code lines and execute the highlight on them
const codeLines = file.querySelectorAll('.d2h-code-line-ctn');
@ -157,7 +156,7 @@ export class Diff2HtmlUI {
const result: HighlightResult = closeTags(
this.hljs.highlight(text, {
language: hljsLanguage?.name || 'plaintext',
language: language || 'plaintext',
ignoreIllegals: true,
}),
);