Skip to content

Commit

Permalink
fallback to plaintext when highlighting unloaded language
Browse files Browse the repository at this point in the history
  • Loading branch information
rtfpessoa committed Aug 27, 2023
1 parent 41a9016 commit f6f05db
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ui/js/diff2html-ui-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,19 @@ 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)!
: language
? 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 => {
Expand Down

0 comments on commit f6f05db

Please sign in to comment.