add support for language override
This commit is contained in:
parent
95e4c40a30
commit
5373ae180b
3 changed files with 14 additions and 2 deletions
|
|
@ -385,6 +385,8 @@ The HTML output accepts a Javascript object with configuration. Possible options
|
||||||
For example: `{ "tag-file-changed": "<span class="d2h-tag d2h-changed d2h-changed-tag">MODIFIED</span>" }`
|
For example: `{ "tag-file-changed": "<span class="d2h-tag d2h-changed d2h-changed-tag">MODIFIED</span>" }`
|
||||||
> For more information regarding the possible templates look into
|
> For more information regarding the possible templates look into
|
||||||
> [src/templates](https://github.com/rtfpessoa/diff2html/tree/master/src/templates)
|
> [src/templates](https://github.com/rtfpessoa/diff2html/tree/master/src/templates)
|
||||||
|
- `highlightLanguages`: Map of extension to language name, used for highlighting. This overrides the default language
|
||||||
|
detection based on file extensions.
|
||||||
|
|
||||||
### Diff2Html Browser
|
### Diff2Html Browser
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ export interface Diff2HtmlUIConfig extends Diff2HtmlConfig {
|
||||||
highlight?: boolean;
|
highlight?: boolean;
|
||||||
fileListToggle?: boolean;
|
fileListToggle?: boolean;
|
||||||
fileListStartVisible?: boolean;
|
fileListStartVisible?: boolean;
|
||||||
|
highlightLanguages?: Map<string, string>;
|
||||||
/**
|
/**
|
||||||
* @deprecated since version 3.1.0
|
* @deprecated since version 3.1.0
|
||||||
* Smart selection is now enabled by default with vanilla CSS
|
* Smart selection is now enabled by default with vanilla CSS
|
||||||
|
|
@ -23,6 +24,7 @@ export const defaultDiff2HtmlUIConfig = {
|
||||||
highlight: true,
|
highlight: true,
|
||||||
fileListToggle: true,
|
fileListToggle: true,
|
||||||
fileListStartVisible: false,
|
fileListStartVisible: false,
|
||||||
|
highlightLanguages: new Map<string, string>(),
|
||||||
/**
|
/**
|
||||||
* @deprecated since version 3.1.0
|
* @deprecated since version 3.1.0
|
||||||
* Smart selection is now enabled by default with vanilla CSS
|
* Smart selection is now enabled by default with vanilla CSS
|
||||||
|
|
@ -141,8 +143,16 @@ export class Diff2HtmlUI {
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
// HACK: help Typescript know that `this.hljs` is defined since we already checked it
|
// HACK: help Typescript know that `this.hljs` is defined since we already checked it
|
||||||
if (this.hljs === null) return;
|
if (this.hljs === null) return;
|
||||||
|
|
||||||
const language = file.getAttribute('data-lang');
|
const language = file.getAttribute('data-lang');
|
||||||
const hljsLanguage = language ? getLanguage(language) : 'plaintext';
|
|
||||||
|
const 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';
|
||||||
|
|
||||||
// Collect all the code lines and execute the highlight on them
|
// Collect all the code lines and execute the highlight on them
|
||||||
const codeLines = file.querySelectorAll('.d2h-code-line-ctn');
|
const codeLines = file.querySelectorAll('.d2h-code-line-ctn');
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import './demo.css';
|
||||||
type URLParams = {
|
type URLParams = {
|
||||||
diff?: string;
|
diff?: string;
|
||||||
diffTooBigMessage?: string;
|
diffTooBigMessage?: string;
|
||||||
[key: string]: string | boolean | number | undefined;
|
[key: string]: string | boolean | number | Map<string, string> | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchParam = 'diff';
|
const searchParam = 'diff';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue