8000 Merge pull request #402 from rtfpessoa/add-language-mappings · cxyxc/diff2html@6ce9292 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ce9292

Browse files
authored
Merge pull request rtfpessoa#402 from rtfpessoa/add-language-mappings
fix: Add language mappings for highlight.js
2 parents cfe56ad + e44b4b1 commit 6ce9292

File tree

2 files changed

+498
-3
lines changed

2 files changed

+498
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { closeTags, nodeStream, mergeStreams } from './highlight.js-helpers';
1+
import { closeTags, nodeStream, mergeStreams, getLanguage } from './highlight.js-helpers';
22

33
import { html, Diff2HtmlConfig, defaultDiff2HtmlConfig } from '../../diff2html';
44
import { DiffFile } from '../../types';
@@ -142,7 +142,7 @@ export class Diff2HtmlUI {
142142
// HACK: help Typescript know that `this.hljs` is defined since we already checked it
143143
if (this.hljs === null) return;
144144
const language = file.getAttribute('data-lang');
145-
const hljsLanguage = language ? this.hljs.getLanguage(language) : undefined;
145+
const hljsLanguage = language ? getLanguage(language) : 'plaintext';
146146

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

158158
const result: HighlightResult = closeTags(
159159
this.hljs.highlight(text, {
160-
language: hljsLanguage?.name || 'plaintext',
160+
language: hljsLanguage,
161161
ignoreIllegals: true,
162162
}),
163163
);

0 commit comments

Comments
 (0)
0