Skip to content

Commit 93b9952

Browse files
auto fallback unsupport lang to highlight.js
1 parent e6e9371 commit 93b9952

File tree

12 files changed

+111
-73
lines changed

12 files changed

+111
-73
lines changed

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.22",
6+
"version": "0.0.23",
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.22",
55+
"@git-diff-view/lowlight": "^0.0.23",
5656
"highlight.js": "^11.10.0",
5757
"lowlight": "^3.2.0",
5858
"fast-diff": "^1.3.0"

packages/core/src/file.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,31 @@ export class File {
104104
return;
105105
}
106106

107-
this.ast = finalHighlighter.getAST(this.raw, this.fileName, this.lang, theme);
107+
// check current lang is support or not
108+
// if it's a unsupported lang, fallback to use lowlightHighlighter
109+
let supportEngin = finalHighlighter;
110+
111+
try {
112+
if (!finalHighlighter.hasRegisteredCurrentLang(this.lang)) {
113+
supportEngin = highlighter;
114+
}
115+
} catch {
116+
supportEngin = highlighter;
117+
}
118+
119+
this.ast = supportEngin.getAST(this.raw, this.fileName, this.lang, theme);
108120

109121
if (!this.ast) return;
110122

111-
const { syntaxFileObject, syntaxFileLineNumber } = finalHighlighter.processAST(this.ast);
123+
const { syntaxFileObject, syntaxFileLineNumber } = supportEngin.processAST(this.ast);
112124

113125
this.syntaxFile = syntaxFileObject;
114126

115127
this.syntaxLength = syntaxFileLineNumber;
116128

117-
this.highlighterName = finalHighlighter.name;
129+
this.highlighterName = supportEngin.name;
118130

119-
this.highlighterType = finalHighlighter.type;
131+
this.highlighterType = supportEngin.type;
120132

121133
if (__DEV__) {
122134
this.#doCheck();

packages/file/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Generated by dts-bundle-generator v9.5.1
22

3-
import { LinesOptions } from 'diff';
3+
import { PatchOptions } from 'diff';
44

55
declare class Cache$1<K, V> extends Map<K, V> {
66
name: string;
@@ -625,8 +625,8 @@ export type SyntaxNode = {
625625
};
626626
children?: SyntaxNode[];
627627
};
628-
export declare function generateDiffFile(oldFileName: string, oldFileContent: string, newFileName: string, newFileContent: string, oldFileLang: DiffHighlighterLang, newFileLang: DiffHighlighterLang, option?: LinesOptions, uuid?: string): DiffFile;
629-
export declare function generateDiffFile(oldFileName: string, oldFileContent: string, newFileName: string, newFileContent: string, oldFileLang: string, newFileLang: string, option?: LinesOptions, uuid?: string): DiffFile;
628+
export declare function generateDiffFile(oldFileName: string, oldFileContent: string, newFileName: string, newFileContent: string, oldFileLang: DiffHighlighterLang, newFileLang: DiffHighlighterLang, option?: PatchOptions, uuid?: string): DiffFile;
629+
export declare function generateDiffFile(oldFileName: string, oldFileContent: string, newFileName: string, newFileContent: string, oldFileLang: string, newFileLang: string, option?: PatchOptions, uuid?: string): DiffFile;
630630

631631
export {
632632
File$1 as File,

packages/file/package.json

Lines changed: 4 additions & 4 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.22",
6+
"version": "0.0.23",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -52,14 +52,14 @@
5252
"diff parse"
5353
],
5454
"dependencies": {
55-
"@git-diff-view/core": "^0.0.22",
56-
"diff": "^5.2.0",
55+
"@git-diff-view/core": "^0.0.23",
56+
"diff": "^7.0.0",
5757
"highlight.js": "^11.10.0",
5858
"lowlight": "^3.2.0",
5959
"fast-diff": "^1.3.0"
6060
},
6161
"devDependencies": {
62-
"@types/diff": "^5.2.2",
62+
"@types/diff": "^6.0.0",
6363
"@types/hast": "^3.0.0"
6464
}
6565
}

packages/file/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DiffFile, _cacheMap } from "@git-diff-view/core";
2-
import { createTwoFilesPatch, type LinesOptions } from "diff";
2+
import { createTwoFilesPatch, type PatchOptions } from "diff";
33

44
import type { DiffHighlighterLang } from "@git-diff-view/core";
55

@@ -12,7 +12,7 @@ export function generateDiffFile(
1212
newFileContent: string,
1313
oldFileLang: DiffHighlighterLang,
1414
newFileLang: DiffHighlighterLang,
15-
option?: LinesOptions,
15+
option?: PatchOptions,
1616
uuid?: string
1717
): DiffFile;
1818
export function generateDiffFile(
@@ -22,7 +22,7 @@ export function generateDiffFile(
2222
newFileContent: string,
2323
oldFileLang: string,
2424
newFileLang: string,
25-
option?: LinesOptions,
25+
option?: PatchOptions,
2626
uuid?: string
2727
): DiffFile;
2828
export function generateDiffFile(
@@ -32,7 +32,7 @@ export function generateDiffFile(
3232
newFileContent: string,
3333
oldFileLang: DiffHighlighterLang | string,
3434
newFileLang: DiffHighlighterLang | string,
35-
option?: LinesOptions,
35+
option?: PatchOptions,
3636
uuid?: string
3737
) {
3838
const diffString = createTwoFilesPatch(oldFileName, newFileName, oldFileContent, newFileContent, "", "", option);

packages/file/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"rootDir": "src",
4-
"target": "ES2015",
4+
"target": "ESNext",
55
"moduleResolution": "Bundler",
66
"stripInternal": true
77
},

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.22",
6+
"version": "0.0.23",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [

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.22",
6+
"version": "0.0.23",
77
"main": "index.js",
88
"types": "index.d.ts",
99
"files": [
@@ -63,7 +63,7 @@
6363
"react diff component"
6464
],
6565
"dependencies": {
66-
"@git-diff-view/core": "^0.0.22",
66+
"@git-diff-view/core": "^0.0.23",
6767
"@types/hast": "^3.0.0",
6868
"fast-diff": "^1.3.0",
6969
"highlight.js": "^11.10.0",

packages/shiki/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "@git-diff-view/shiki",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.22",
6+
"version": "0.0.23",
77
"types": "index.d.ts",
88
"type": "module",
99
"files": [
@@ -44,6 +44,7 @@
4444
"virtual dom highlight"
4545
],
4646
"dependencies": {
47-
"shiki": "^1.22.0"
47+
"@git-diff-view/lowlight": "^0.0.23",
48+
"shiki": "^1.24.0"
4849
}
4950
}

packages/vue/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/vue",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
6-
"version": "0.0.22",
6+
"version": "0.0.23",
77
"main": "index.js",
88
"type": "module",
99
"types": "index.d.ts",
@@ -49,7 +49,7 @@
4949
"vue diff component"
5050
],
5151
"dependencies": {
52-
"@git-diff-view/core": "^0.0.22",
52+
"@git-diff-view/core": "^0.0.23",
5353
"@types/hast": "^3.0.0",
5454
"highlight.js": "^11.10.0",
5555
"lowlight": "^3.2.0",

0 commit comments

Comments
 (0)