Skip to content

Commit

Permalink
Merge pull request #402 from rtfpessoa/add-language-mappings
Browse files Browse the repository at this point in the history
fix: Add language mappings for highlight.js
  • Loading branch information
rtfpessoa authored Sep 3, 2021
2 parents cfe56ad + e44b4b1 commit 6ce9292
Show file tree
Hide file tree
Showing 2 changed files with 498 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/ui/js/diff2html-ui-base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { closeTags, nodeStream, mergeStreams } from './highlight.js-helpers';
import { closeTags, nodeStream, mergeStreams, getLanguage } from './highlight.js-helpers';

import { html, Diff2HtmlConfig, defaultDiff2HtmlConfig } from '../../diff2html';
import { DiffFile } from '../../types';
Expand Down Expand Up @@ -142,7 +142,7 @@ 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;
const hljsLanguage = language ? getLanguage(language) : 'plaintext';

// Collect all the code lines and execute the highlight on them
const codeLines = file.querySelectorAll('.d2h-code-line-ctn');
Expand All @@ -157,7 +157,7 @@ export class Diff2HtmlUI {

const result: HighlightResult = closeTags(
this.hljs.highlight(text, {
language: hljsLanguage?.name || 'plaintext',
language: hljsLanguage,
ignoreIllegals: true,
}),
);
Expand Down
Loading

0 comments on commit 6ce9292

Please sign in to comment.