8000 bump: Update dependencies · cxyxc/diff2html@6572b68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6572b68

Browse files
committed
bump: Update dependencies
1 parent b8594e1 commit 6572b68

File tree

9 files changed

+2026
-2928
lines changed

9 files changed

+2026
-2928
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@ module.exports = {
5252
'sonarjs/no-duplicate-string': 'off',
5353
// Too verbose
5454
'sonarjs/cognitive-complexity': 'off',
55+
// Too verbose
56+
'sonarjs/no-nested-template-literals': 'off',
5557
},
5658
};

.husky/pre-commit

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
. "$(dirname "$0")/_/husky.sh"
33

44
npx lint-staged
5-

package.json

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -85,61 +85,60 @@
8585
"hogan.js": "3.0.2"
8686
},
8787
"optionalDependencies": {
88-
"highlight.js": "10.7.2"
88+
"highlight.js": "11.1.0"
8989
},
9090
"devDependencies": {
91-
"@types/clipboard": "2.0.1",
92-
"@types/copy-webpack-plugin": "6.4.1",
93-
"@types/diff": "5.0.0",
94-
"@types/hogan.js": "3.0.0",
95-
"@types/jest": "26.0.22",
96-
"@types/mini-css-extract-plugin": "^1.2.2",
97-
"@types/mkdirp": "1.0.1",
98-
"@types/node": "14.14.37",
91+
"@types/copy-webpack-plugin": "8.0.1",
92+
"@types/diff": "5.0.1",
93+
"@types/hogan.js": "3.0.1",
94+
"@types/jest": "26.0.24",
95+
"@types/mini-css-extract-plugin": "^2.0.1",
96+
"@types/mkdirp": "1.0.2",
97+
"@types/node": "16.4.1",
9998
"@types/nopt": "3.0.29",
100-
"@typescript-eslint/eslint-plugin": "4.21.0",
101-
"@typescript-eslint/parser": "4.21.0",
102-
"autoprefixer": "10.2.5",
99+
"@typescript-eslint/eslint-plugin": "4.28.4",
100+
"@typescript-eslint/parser": "4.28.4",
101+
"autoprefixer": "10.3.1",
103102
"bulma": "^0.9.2",
104103
"clipboard": "2.0.8",
105-
"copy-webpack-plugin": "8.1.1",
106-
"css-loader": "5.2.0",
107-
"cssnano": "4.1.11",
108-
"eslint": "7.23.0",
109-
"eslint-config-prettier": "8.1.0",
110-
"eslint-plugin-import": "2.22.1",
111-
"eslint-plugin-jest": "24.3.4",
112-
"eslint-plugin-json": "2.1.2",
104+
"copy-webpack-plugin": "9.0.1",
105+
"css-loader": "6.2.0",
106+
"cssnano": "5.0.7",
107+
"eslint": "7.31.0",
108+
"eslint-config-prettier": "8.3.0",
109+
"eslint-plugin-import": "2.23.4",
110+
"eslint-plugin-jest": "24.4.0",
111+
"eslint-plugin-json": "3.0.0",
113112
"eslint-plugin-node": "11.1.0",
114113
"eslint-plugin-optimize-regex": "1.2.0",
115-
"eslint-plugin-promise": "4.3.1",
116-
"eslint-plugin-sonarjs": "0.6.0",
114+
"eslint-plugin-promise": "5.1.0",
115+
"eslint-plugin-sonarjs": "0.9.1",
117116
"file-loader": "6.2.0",
118117
"handlebars": "4.7.7",
119118
"handlebars-loader": "1.7.1",
120-
"html-webpack-plugin": "5.3.1",
121-
"husky": "^6.0.0",
119+
"html-webpack-plugin": "5.3.2",
120+
"husky": "^7.0.1",
122121
"image-webpack-loader": "7.0.1",
123122
"is-ci-cli": "2.2.0",
124-
"jest": "26.6.3",
125-
"lint-staged": "10.5.4",
123+
"jest": "27.0.6",
124+
"lint-staged": "11.1.0",
126125
"markdown-toc": "^1.2.0",
127-
"mini-css-extract-plugin": "1.4.1",
126+
"mini-css-extract-plugin": "2.1.0",
128127
"mkdirp": "1.0.4",
129128
"nopt": "5.0.0",
130-
"postcss": "8.2.10",
129+
"postcss": "8.3.6",
131130
"postcss-cli": "8.3.1",
132-
"postcss-import": "14.0.1",
133-
"postcss-loader": "5.2.0",
131+
"postcss-import": "14.0.2",
132+
"postcss-loader": "6.1.1",
134133
"postcss-preset-env": "6.7.0",
135-
"prettier": "2.2.1",
136-
"ts-jest": "26.5.4",
137-
"ts-loader": "8.1.0",
138-
"ts-node": "9.1.1",
139-
"typescript": "4.2.4",
134+
"prettier": "2.3.2",
135+
"ts-jest": "27.0.4",
136+
"ts-loader": "9.2.3",
137+
"ts-node": "10.1.0",
138+
"typescript": "4.3.5",
140139
"url-loader": "4.1.1",
141-
"webpack": "5.31.0",
142-
"webpack-cli": "4.6.0",
140+
"webpack": "5.46.0",
141+
"webpack-cli": "4.7.2",
143142
"whatwg-fetch": "3.6.2"
144143
},
145144
"resolutions": {
@@ -149,8 +148,7 @@
149148
"autolinker": ">=3.14.1",
150149
"bl": ">=2.2.1",
151150
"decompress": ">=4.2.1",
152-
"node-forge": ">=0.10.0",
153-
"@types/webpack": ">=5.28.0"
151+
"node-forge": ">=0.10.0"
154152
},
155153
"license": "MIT",
156154
"files": [

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

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import * as HighlightJS from 'highlight.js/lib/core';
2-
// import { CompiledMode, HighlightResult, AutoHighlightResult } from 'highlight.js/lib/core.js';
3-
import { nodeStream, mergeStreams } from './highlight.js-helpers';
1+
import { closeTags, nodeStream, mergeStreams } from './highlight.js-helpers';
42

53
import { html, Diff2HtmlConfig, defaultDiff2HtmlConfig } from '../../diff2html';
64
import { DiffFile } from '../../types';
5+
import { HighlightResult, HLJSApi } from 'highlight.js';
76

87
export interface Diff2HtmlUIConfig extends Diff2HtmlConfig {
98
synchronisedScroll?: boolean;
@@ -36,16 +35,11 @@ export class Diff2HtmlUI {
3635
readonly config: typeof defaultDiff2HtmlUIConfig;
3736
readonly diffHtml: string;
3837
readonly targetElement: HTMLElement;
39-
readonly hljs: typeof HighlightJS | null = null;
38+
readonly hljs: HLJSApi | null = null;
4039

4140
currentSelectionColumnId = -1;
4241

43-
constructor(
44-
target: HTMLElement,
45-
diffInput?: string | DiffFile[],
46-
config: Diff2HtmlUIConfig = {},
47-
hljs?: typeof HighlightJS,
48-
) {
42+
constructor(target: HTMLElement, diffInput?: string | DiffFile[], config: Diff2HtmlUIConfig = {}, hljs?: HLJSApi) {
4943
this.config = { ...defaultDiff2HtmlUIConfig, ...config };
5044
this.diffHtml = diffInput !== undefined ? html(diffInput, this.config) : target.innerHTML;
5145
this.targetElement = target;
@@ -145,8 +139,10 @@ export class Diff2HtmlUI {
145139
// Collect all the diff files and execute the highlight on their lines
146140
const files = this.targetElement.querySelectorAll('.d2h-file-wrapper');
147141
files.forEach(file => {
148-
let oldLinesState: CompiledMode | Language | undefined;
149-
let newLinesState: CompiledMode | Language | undefined;
142+
// HACK: help Typescript know that `this.hljs` is defined since we already checked it
143+
if (this.hljs === null) return;
144+
const language = file.getAttribute('data-lang');
145+
const hljsLanguage = language ? this.hljs.getLanguage(language) : undefined;
150146

151147
// Collect all the code lines and execute the highlight on them
152148
const codeLines = file.querySelectorAll('.d2h-code-line-ctn');
@@ -159,24 +155,12 @@ export class Diff2HtmlUI {
159155

160156
if (text === null || lineParent === null || !this.isElement(lineParent)) return;
161157

162-
const lineState = lineParent.classList.contains('d2h-del') ? oldLinesState : newLinesState;
163-
164-
const language = file.getAttribute('data-lang');
165-
const result: HighlightResult =
166-
language && this.hljs.getLanguage(language)
167-
? this.hljs.highlight(language, text, true, lineState)
168-
: this.hljs.highlightAuto(text);
169-
170-
if (this.instanceOfHighlightResult(result)) {
171-
if (lineParent.classList.contains('d2h-del')) {
172-
oldLinesState = result.top;
173-
} else if (lineParent.classList.contains('d2h-ins')) {
174-
newLinesState = result.top;
175-
} else {
176-
oldLinesState = result.top;
177-
newLinesState = result.top;
178-
}
179-
}
158+
const result: HighlightResult = closeTags(
159+
this.hljs.highlight(text, {
160+
language: hljsLanguage?.name || 'plaintext',
161+
ignoreIllegals: true,
162+
}),
163+
);
180164

181165
const originalStream = nodeStream(line);
182166
if (originalStream.length) {
@@ -201,10 +185,6 @@ export class Diff2HtmlUI {
201185
console.warn('Smart selection is now enabled by default with CSS. No need to call this method anymore.');
202186
}
203187

204-
private instanceOfHighlightResult(object: HighlightResult | AutoHighlightResult): object is HighlightResult {
205-
return 'top' in object;
206-
}
207-
208188
private getHashTag(): string | null {
209189
const docUrl = document.URL;
210190
const hashTagIndex = docUrl.indexOf('#');

src/ui/js/highlight.js-helpers.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Used to highlight selected html elements using context
44
*/
55

6+
import { HighlightResult } from 'highlight.js';
7+
68
/* Utility functions */
79

810
function escapeHTML(value: string): string {
@@ -135,3 +137,24 @@ export function mergeStreams(original: NodeEvent[], highlighted: NodeEvent[], va
135137

136138
return result + escapeHTML(value.substr(processed));
137139
}
140+
141+
// https://github.com/hexojs/hexo-util/blob/979873b63a725377c2bd6ad834d790023496130d/lib/highlight.js#L123
142+
export function closeTags(res: HighlightResult): HighlightResult {
143+
const tokenStack = new Array<string>();
144+
145+
res.value = res.value
146+
.split('\n')
147+
.map(line => {
148+
const prepend = tokenStack.map(token => `<span class="${token}">`).join('');
149+
const matches = line.matchAll(/(<span class="(.*?)">|<\/span>)/g);
150+
Array.from(matches).forEach(match => {
151+
if (match[0] === '</span>') tokenStack.shift();
152+
else tokenStack.unshift(match[2]);
153+
});
154+
const append = '</span>'.repeat(tokenStack.length);
155+
return prepend + line + append;
156+
})
157+
.join('\n');
158+
159+
return res;
160+
}

src/ui/js/highlight.js-slim.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import highlightJS from 'highlight.js/lib/core';
1414
// import apache from 'highlight.js/lib/languages/apache';
1515
// import applescript from 'highlight.js/lib/languages/applescript';
1616
// import arcade from 'highlight.js/lib/languages/arcade';
17-
import cLike from 'highlight.js/lib/languages/c-like';
1817
import cpp from 'highlight.js/lib/languages/cpp';
1918
// import arduino from 'highlight.js/lib/languages/arduino';
2019
// import armasm from 'highlight.js/lib/languages/armasm';
@@ -209,7 +208,6 @@ import typescript from 'highlight.js/lib/languages/typescript';
209208
// highlightJS.registerLanguage('apache', apache);
210209
// highlightJS.registerLanguage('applescript', applescript);
211210
// highlightJS.registerLanguage('arcade', arcade);
212-
highlightJS.registerLanguage('c-like', cLike);
213211
highlightJS.registerLanguage('cpp', cpp);
214212
// highlightJS.registerLanguage('arduino', arduino);
215213
// highlightJS.registerLanguage('armasm', armasm);

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"target": "es5",
55
"module": "commonjs",
66
"moduleResolution": "node",
7-
"lib": ["es2015", "dom"],
7+
"lib": ["es2020", "dom"],
88
"allowJs": false,
99
"declaration": true,
1010
"declarationMap": true,

website/templates/pages/demo/demo.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ function prepareRequest(url: string): Request {
6565
let fetchUrl;
6666
const headers = new Headers();
6767

68-
const githubCommitUrl = /^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/;
68+
const githubCommitUrl =
69+
/^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/;
6970
const githubPrUrl = /^https?:\/\/(?:www\.)?github\.com\/(.*?)\/(.*?)\/pull\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/;
7071

71-
const gitlabCommitUrl = /^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/;
72-
const gitlabPrUrl = /^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/merge_requests\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/;
72+
const gitlabCommitUrl =
73+
/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/commit\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/;
74+
const gitlabPrUrl =
75+
/^https?:\/\/(?:www\.)?gitlab\.com\/(.*?)\/(.*?)\/merge_requests\/(.*?)(?:\.diff)?(?:\.patch)?(?:\/.*)?$/;
7376

7477
const bitbucketCommitUrl = /^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/commits\/(.*?)(?:\/raw)?(?:\/.*)?$/;
7578
const bitbucketPrUrl = /^https?:\/\/(?:www\.)?bitbucket\.org\/(.*?)\/(.*?)\/pull-requests\/(.*?)(?:\/.*)?$/;

0 commit comments

Comments
 (0)
0