Skip to content

Commit f6f05db

Browse files
committed
fallback to plaintext when highlighting unloaded language
1 parent 41a9016 commit f6f05db

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/ui/js/diff2html-ui-base.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,19 @@ export class Diff2HtmlUI {
151151
this.config.highlightLanguages = new Map(Object.entries(this.config.highlightLanguages));
152152
}
153153

154-
const hljsLanguage =
154+
let hljsLanguage =
155155
language && this.config.highlightLanguages.has(language)
156156
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
157157
this.config.highlightLanguages.get(language)!
158158
: language
159159
? getLanguage(language)
160160
: 'plaintext';
161161

162+
// Fallback to plaintext in case language is not loaded
163+
if (hljs.getLanguage(hljsLanguage) === undefined) {
164+
hljsLanguage = 'plaintext';
165+
}
166+
162167
// Collect all the code lines and execute the highlight on them
163168
const codeLines = file.querySelectorAll('.d2h-code-line-ctn');
164169
codeLines.forEach(line => {

0 commit comments

Comments
 (0)