diff --git a/src/__tests__/diff2html-tests.ts b/src/__tests__/diff2html-tests.ts
index dbf78ab..7bc16f7 100644
--- a/src/__tests__/diff2html-tests.ts
+++ b/src/__tests__/diff2html-tests.ts
@@ -1,7 +1,7 @@
import fs from 'fs';
import { parse, html } from '../diff2html';
-import { DiffFile, LineType, OutputFormatType } from '../types';
+import { ColorSchemeType, DiffFile, LineType, OutputFormatType } from '../types';
const diffExample1 =
'diff --git a/sample b/sample\n' +
@@ -1258,5 +1258,67 @@ describe('Diff2Html', () => {
`);
/* eslint-enable no-irregular-whitespace */
});
+
+ describe('with dark mode flag', () => {
+ it('should return a html diff with dark mode', () => {
+ const result = html(diffExample1, {
+ drawFileList: false,
+ colorScheme: ColorSchemeType.DARK,
+ });
+ expect(result).toMatchInlineSnapshot(`
+ "
+
+
+
+
+
+
+
+ |
+
+ @@ -1 +1 @@
+ |
+
+ |
+ 1
+
+ |
+
+
+ -
+ test
+
+ |
+
+ |
+
+ 1
+ |
+
+
+ +
+ test1
+
+ |
+
+
+
+
+
+
+
"
+ `);
+ });
+ });
});
});
diff --git a/src/line-by-line-renderer.ts b/src/line-by-line-renderer.ts
index c3a3805..430d026 100644
--- a/src/line-by-line-renderer.ts
+++ b/src/line-by-line-renderer.ts
@@ -52,7 +52,10 @@ export default class LineByLineRenderer {
})
.join('\n');
- return this.hoganUtils.render(genericTemplatesPath, 'wrapper', { content: diffsHtml });
+ return this.hoganUtils.render(genericTemplatesPath, 'wrapper', {
+ colorScheme: renderUtils.colorSchemeToCss(this.config.colorScheme),
+ content: diffsHtml,
+ });
}
makeFileDiffHtml(file: DiffFile, diffs: string): string {
diff --git a/src/render-utils.ts b/src/render-utils.ts
index 830628e..6723c3f 100644
--- a/src/render-utils.ts
+++ b/src/render-utils.ts
@@ -2,7 +2,15 @@ import * as jsDiff from 'diff';
import { unifyPath, hashCode } from './utils';
import * as rematch from './rematch';
-import { LineMatchingType, DiffStyleType, LineType, DiffLineParts, DiffFile, DiffFileName } from './types';
+import {
+ ColorSchemeType,
+ DiffFile,
+ DiffFileName,
+ DiffLineParts,
+ DiffStyleType,
+ LineMatchingType,
+ LineType,
+} from './types';
export type CSSLineClass =
| 'd2h-ins'
@@ -37,6 +45,7 @@ export interface RenderConfig {
matchWordsThreshold?: number;
maxLineLengthHighlight?: number;
diffStyle?: DiffStyleType;
+ colorScheme?: ColorSchemeType;
}
export const defaultRenderConfig = {
@@ -44,6 +53,7 @@ export const defaultRenderConfig = {
matchWordsThreshold: 0.25,
maxLineLengthHighlight: 10000,
diffStyle: DiffStyleType.WORD,
+ colorScheme: ColorSchemeType.LIGHT,
};
const separator = '/';
@@ -76,6 +86,17 @@ export function toCSSClass(lineType: LineType): CSSLineClass {
}
}
+export function colorSchemeToCss(colorScheme: ColorSchemeType): string {
+ switch (colorScheme) {
+ case ColorSchemeType.DARK:
+ return ' dark';
+ case ColorSchemeType.AUTO:
+ return ' auto-color-scheme';
+ default:
+ return '';
+ }
+}
+
/**
* Prefix length of the hunk lines in the diff
*/
diff --git a/src/side-by-side-renderer.ts b/src/side-by-side-renderer.ts
index 9a0fb6b..e63893a 100644
--- a/src/side-by-side-renderer.ts
+++ b/src/side-by-side-renderer.ts
@@ -52,7 +52,10 @@ export default class SideBySideRenderer {
})
.join('\n');
- return this.hoganUtils.render(genericTemplatesPath, 'wrapper', { content: diffsHtml });
+ return this.hoganUtils.render(genericTemplatesPath, 'wrapper', {
+ colorScheme: renderUtils.colorSchemeToCss(this.config.colorScheme),
+ content: diffsHtml,
+ });
}
makeFileDiffHtml(file: DiffFile, diffs: FileHtml): string {
diff --git a/src/templates/generic-wrapper.mustache b/src/templates/generic-wrapper.mustache
index be5096a..613723b 100644
--- a/src/templates/generic-wrapper.mustache
+++ b/src/templates/generic-wrapper.mustache
@@ -1,3 +1,3 @@
-
+
{{{content}}}
diff --git a/src/types.ts b/src/types.ts
index ea28b49..d226286 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -91,3 +91,9 @@ export const DiffStyleType: { [_: string]: DiffStyleType } = {
WORD: 'word',
CHAR: 'char',
};
+
+export enum ColorSchemeType {
+ AUTO = 'auto',
+ DARK = 'dark',
+ LIGHT = 'light',
+}