Skip to content

Commit 9b79a72

Browse files
highlighter optimize
1 parent e6c7243 commit 9b79a72

22 files changed

Lines changed: 295 additions & 43 deletions

packages/core/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ declare class File$1 {
1818
syntaxFile: Record<number, SyntaxLine>;
1919
hasDoSyntax: boolean;
2020
syntaxLength?: number;
21-
highlighterName?: string;
21+
highlighterName?: DiffHighlighter["name"];
22+
highlighterType?: DiffHighlighter["type"];
2223
maxLineNumber: number;
2324
static createInstance(data: File$1): File$1;
2425
constructor(raw: string, lang: string, fileName?: string);
@@ -522,6 +523,7 @@ export interface UnifiedLineItem {
522523
export type DiffAST = ReturnType<typeof lowlight.highlight>;
523524
export type DiffHighlighter = {
524525
name: string;
526+
type: "class" | "style" | string;
525527
maxLineToIgnoreSyntax: number;
526528
setMaxLineToIgnoreSyntax: (v: number) => void;
527529
ignoreSyntaxHighlightList: (string | RegExp)[];

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/core",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.17",
6+
"version": "0.0.18",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -52,7 +52,7 @@
5252
"diff parse"
5353
],
5454
"dependencies": {
55-
"@git-diff-view/lowlight": "^0.0.17",
55+
"@git-diff-view/lowlight": "^0.0.18",
5656
"highlight.js": "^11.9.0",
5757
"lowlight": "^3.1.0",
5858
"fast-diff": "^1.3.0"

packages/core/src/file.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export class File {
4141

4242
syntaxLength?: number;
4343

44-
highlighterName?: string;
44+
highlighterName?: DiffHighlighter["name"];
45+
46+
highlighterType?: DiffHighlighter["type"];
4547

4648
maxLineNumber: number = 0;
4749

@@ -64,6 +66,8 @@ export class File {
6466

6567
file.highlighterName = data?.highlighterName;
6668

69+
file.highlighterType = data?.highlighterType;
70+
6771
file.maxLineNumber = data?.maxLineNumber;
6872

6973
return file;
@@ -110,6 +114,8 @@ export class File {
110114

111115
this.highlighterName = finalHighlighter.name;
112116

117+
this.highlighterType = finalHighlighter.type;
118+
113119
if (__DEV__) {
114120
this.#doCheck();
115121
}
@@ -181,7 +187,7 @@ export const getFile = (raw: string, lang: string, theme: "light" | "dark", file
181187
if (map.has(otherThemeKey)) {
182188
const cacheFile = map.get(otherThemeKey);
183189
// 基于className的ast不需要重新生成
184-
if (cacheFile.highlighterName === highlighter.name) {
190+
if (cacheFile.highlighterType === 'class') {
185191
return cacheFile;
186192
}
187193
}

packages/file/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ declare class File$1 {
1818
syntaxFile: Record<number, SyntaxLine>;
1919
hasDoSyntax: boolean;
2020
syntaxLength?: number;
21-
highlighterName?: string;
21+
highlighterName?: DiffHighlighter["name"];
22+
highlighterType?: DiffHighlighter["type"];
2223
maxLineNumber: number;
2324
static createInstance(data: File$1): File$1;
2425
constructor(raw: string, lang: string, fileName?: string);
@@ -521,6 +522,7 @@ export interface UnifiedLineItem {
521522
export type DiffAST = ReturnType<typeof lowlight.highlight>;
522523
export type DiffHighlighter = {
523524
name: string;
525+
type: "class" | "style" | string;
524526
maxLineToIgnoreSyntax: number;
525527
setMaxLineToIgnoreSyntax: (v: number) => void;
526528
ignoreSyntaxHighlightList: (string | RegExp)[];

packages/file/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/file",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.17",
6+
"version": "0.0.18",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -52,7 +52,7 @@
5252
"diff parse"
5353
],
5454
"dependencies": {
55-
"@git-diff-view/core": "^0.0.17",
55+
"@git-diff-view/core": "^0.0.18",
5656
"diff": "^5.2.0",
5757
"highlight.js": "^11.9.0",
5858
"lowlight": "^3.1.0",

packages/lowlight/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ declare const lowlight: {
4242
export type DiffAST = ReturnType<typeof lowlight.highlight>;
4343
export type DiffHighlighter = {
4444
name: string;
45+
type: "class" | "style" | string;
4546
maxLineToIgnoreSyntax: number;
4647
setMaxLineToIgnoreSyntax: (v: number) => void;
4748
ignoreSyntaxHighlightList: (string | RegExp)[];

packages/lowlight/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/lowlight",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.17",
6+
"version": "0.0.18",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

packages/lowlight/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export type DiffAST = ReturnType<typeof lowlight.highlight>;
5656

5757
export type DiffHighlighter = {
5858
name: string;
59+
type: "class" | "style" | string;
5960
maxLineToIgnoreSyntax: number;
6061
setMaxLineToIgnoreSyntax: (v: number) => void;
6162
ignoreSyntaxHighlightList: (string | RegExp)[];
@@ -135,6 +136,8 @@ Object.defineProperty(instance, "hasRegisteredCurrentLang", {
135136
},
136137
});
137138

139+
Object.defineProperty(instance, "type", { value: "class" });
140+
138141
export { processAST } from "./processAST";
139142

140143
export const versions = __VERSION__;

packages/react/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ declare class File$1 {
1818
syntaxFile: Record<number, SyntaxLine>;
1919
hasDoSyntax: boolean;
2020
syntaxLength?: number;
21-
highlighterName?: string;
21+
highlighterName?: DiffHighlighter["name"];
22+
highlighterType?: DiffHighlighter["type"];
2223
maxLineNumber: number;
2324
static createInstance(data: File$1): File$1;
2425
constructor(raw: string, lang: string, fileName?: string);
@@ -521,6 +522,7 @@ export interface UnifiedLineItem {
521522
export type DiffAST = ReturnType<typeof lowlight.highlight>;
522523
export type DiffHighlighter = {
523524
name: string;
525+
type: "class" | "style" | string;
524526
maxLineToIgnoreSyntax: number;
525527
setMaxLineToIgnoreSyntax: (v: number) => void;
526528
ignoreSyntaxHighlightList: (string | RegExp)[];

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/react",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.17",
6+
"version": "0.0.18",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -61,7 +61,7 @@
6161
"react diff component"
6262
],
6363
"dependencies": {
64-
"@git-diff-view/core": "^0.0.17",
64+
"@git-diff-view/core": "^0.0.18",
6565
"@types/hast": "^3.0.0",
6666
"fast-diff": "^1.3.0",
6767
"highlight.js": "^11.9.0",

0 commit comments

Comments
 (0)