@readme/syntax-highlighter 14.0.0 → 15.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +27753 -2
- package/dist/index.node.js +393 -1
- package/dist-utils/canonical.d.ts +60 -0
- package/dist-utils/canonical.js +66 -0
- package/dist-utils/index.d.ts +89 -0
- package/dist-utils/index.js +9 -0
- package/dist-utils/modes.d.ts +82 -0
- package/dist-utils/modes.js +105 -0
- package/dist-utils/uppercase.d.ts +1 -0
- package/dist-utils/uppercase.js +114 -0
- package/knip.ts +12 -0
- package/package.json +34 -18
- package/src/codeEditor/{cm.options.js → cm.options.ts} +4 -2
- package/src/codeEditor/{index.jsx → index.tsx} +22 -29
- package/src/codeMirror/index.jsx +1 -1
- package/src/index.js +4 -4
- package/src/utils/{canonical.js → canonical.ts} +4 -2
- package/src/utils/index.ts +5 -0
- package/src/utils/{modes.js → modes.ts} +6 -8
- package/src/utils/{uppercase.js → uppercase.ts} +4 -4
- package/tsconfig.json +12 -0
- package/webpack.config.js +14 -7
- package/dist/index.js.LICENSE.txt +0 -9
- /package/src/{index.node.js → index.node.ts} +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export declare const modes: {
|
|
2
|
+
readonly asp: "clike";
|
|
3
|
+
readonly aspx: "clike";
|
|
4
|
+
readonly bash: "shell";
|
|
5
|
+
readonly c: "clike";
|
|
6
|
+
readonly 'c#': readonly ["clike", "text/x-csharp"];
|
|
7
|
+
readonly 'c++': readonly ["clike", "text/x-c++src"];
|
|
8
|
+
readonly clj: "clojure";
|
|
9
|
+
readonly cljc: "clojure";
|
|
10
|
+
readonly cljx: "clojure";
|
|
11
|
+
readonly coffeescript: "javascript";
|
|
12
|
+
readonly cplusplus: readonly ["clike", "text/x-c++src"];
|
|
13
|
+
readonly cpp: readonly ["clike", "text/x-c++src"];
|
|
14
|
+
readonly cql: readonly ["sql", "text/x-cassandra"];
|
|
15
|
+
readonly cs: readonly ["clike", "text/x-csharp"];
|
|
16
|
+
readonly csharp: readonly ["clike", "text/x-csharp"];
|
|
17
|
+
readonly curl: "shell";
|
|
18
|
+
readonly d: "d";
|
|
19
|
+
readonly diff: "diff";
|
|
20
|
+
readonly ecmascript: "javascript";
|
|
21
|
+
readonly erl: "erlang";
|
|
22
|
+
readonly go: readonly ["go", "text/x-go"];
|
|
23
|
+
readonly gradle: "groovy";
|
|
24
|
+
readonly gql: "graphql";
|
|
25
|
+
readonly handlebars: "htmlmixed";
|
|
26
|
+
readonly hbs: "htmlmixed";
|
|
27
|
+
readonly html: "htmlmixed";
|
|
28
|
+
readonly java: readonly ["clike", "text/x-java"];
|
|
29
|
+
readonly jl: "julia";
|
|
30
|
+
readonly js: "javascript";
|
|
31
|
+
readonly jsx: "jsx";
|
|
32
|
+
readonly json: readonly ["javascript", "application/ld+json"];
|
|
33
|
+
readonly jruby: "ruby";
|
|
34
|
+
readonly kotlin: readonly ["clike", "text/x-kotlin"];
|
|
35
|
+
readonly kt: readonly ["clike", "text/x-kotlin"];
|
|
36
|
+
readonly less: "css";
|
|
37
|
+
readonly liquid: "htmlmixed";
|
|
38
|
+
readonly lua: "lua";
|
|
39
|
+
readonly node: "javascript";
|
|
40
|
+
readonly macruby: "ruby";
|
|
41
|
+
readonly markdown: "gfm";
|
|
42
|
+
readonly ml: readonly ["mllike", "text/x-ocaml"];
|
|
43
|
+
readonly mssql: readonly ["sql", "text/x-mssql"];
|
|
44
|
+
readonly mysql: readonly ["sql", "text/x-mysql"];
|
|
45
|
+
readonly objc: readonly ["clike", "text/x-objectivec"];
|
|
46
|
+
readonly 'objc++': readonly ["clike", "text/x-objectivec++"];
|
|
47
|
+
readonly objcpp: readonly ["clike", "text/x-objectivec++"];
|
|
48
|
+
readonly objectivec: readonly ["clike", "text/x-objectivec"];
|
|
49
|
+
readonly objectivecpp: readonly ["clike", "text/x-objectivec++"];
|
|
50
|
+
readonly objectivecplusplus: readonly ["clike", "text/x-objectivec++"];
|
|
51
|
+
readonly ocaml: readonly ["mllike", "text/x-ocaml"];
|
|
52
|
+
readonly php: readonly ["php", "text/x-php"];
|
|
53
|
+
readonly pgsql: readonly ["sql", "text/x-pgsql"];
|
|
54
|
+
readonly pl: "perl";
|
|
55
|
+
readonly plsql: readonly ["sql", "text/x-plsql"];
|
|
56
|
+
readonly postgres: readonly ["sql", "text/x-pgsql"];
|
|
57
|
+
readonly postgresql: readonly ["sql", "text/x-pgsql"];
|
|
58
|
+
readonly ps1: "powershell";
|
|
59
|
+
readonly py: "python";
|
|
60
|
+
readonly r: "r";
|
|
61
|
+
readonly rake: "ruby";
|
|
62
|
+
readonly rb: "ruby";
|
|
63
|
+
readonly rbx: "ruby";
|
|
64
|
+
readonly rs: "rust";
|
|
65
|
+
readonly sass: "css";
|
|
66
|
+
readonly scala: readonly ["clike", "text/x-scala"];
|
|
67
|
+
readonly scss: "css";
|
|
68
|
+
readonly sh: "shell";
|
|
69
|
+
readonly sol: "solidity";
|
|
70
|
+
readonly solidity: "solidity";
|
|
71
|
+
readonly sql: readonly ["sql", "text/x-sql"];
|
|
72
|
+
readonly sqlite: readonly ["sql", "text/x-sqlite"];
|
|
73
|
+
readonly styl: "css";
|
|
74
|
+
readonly stylus: "css";
|
|
75
|
+
readonly text: readonly ["null", "text/plain"];
|
|
76
|
+
readonly ts: readonly ["javascript", "text/typescript"];
|
|
77
|
+
readonly typescript: readonly ["javascript", "text/typescript"];
|
|
78
|
+
readonly xhtml: "htmlmixed";
|
|
79
|
+
readonly yml: "yaml";
|
|
80
|
+
readonly zsh: "shell";
|
|
81
|
+
};
|
|
82
|
+
export declare function getMode(lang: string): string;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.modes = void 0;
|
|
4
|
+
exports.getMode = getMode;
|
|
5
|
+
// This is a mapping of languages that we support, but aren't directly loading the mode extension
|
|
6
|
+
// Within `/src/codeMirror/index.jsx` and /src/codeEditor.index.jsx
|
|
7
|
+
//
|
|
8
|
+
// This list also includes a number of language aliases, as because of the way we're using
|
|
9
|
+
// `CodeMirror.runMode` we can't take advantage of its known aliases in the mode extensions that
|
|
10
|
+
// we're loading.
|
|
11
|
+
//
|
|
12
|
+
// There are 2 types of lookup, single and array. e.g. `html` needs to be rendered using
|
|
13
|
+
// `htmlmixed`, but `java`, needs to be rendered using the `clike` mode.
|
|
14
|
+
//
|
|
15
|
+
exports.modes = {
|
|
16
|
+
asp: 'clike',
|
|
17
|
+
aspx: 'clike',
|
|
18
|
+
bash: 'shell',
|
|
19
|
+
c: 'clike',
|
|
20
|
+
'c#': ['clike', 'text/x-csharp'],
|
|
21
|
+
'c++': ['clike', 'text/x-c++src'],
|
|
22
|
+
clj: 'clojure',
|
|
23
|
+
cljc: 'clojure',
|
|
24
|
+
cljx: 'clojure',
|
|
25
|
+
coffeescript: 'javascript',
|
|
26
|
+
cplusplus: ['clike', 'text/x-c++src'],
|
|
27
|
+
cpp: ['clike', 'text/x-c++src'],
|
|
28
|
+
cql: ['sql', 'text/x-cassandra'],
|
|
29
|
+
cs: ['clike', 'text/x-csharp'],
|
|
30
|
+
csharp: ['clike', 'text/x-csharp'],
|
|
31
|
+
curl: 'shell',
|
|
32
|
+
d: 'd',
|
|
33
|
+
diff: 'diff',
|
|
34
|
+
ecmascript: 'javascript',
|
|
35
|
+
erl: 'erlang',
|
|
36
|
+
go: ['go', 'text/x-go'],
|
|
37
|
+
gradle: 'groovy',
|
|
38
|
+
gql: 'graphql',
|
|
39
|
+
handlebars: 'htmlmixed',
|
|
40
|
+
hbs: 'htmlmixed',
|
|
41
|
+
html: 'htmlmixed',
|
|
42
|
+
java: ['clike', 'text/x-java'],
|
|
43
|
+
jl: 'julia',
|
|
44
|
+
js: 'javascript',
|
|
45
|
+
jsx: 'jsx',
|
|
46
|
+
json: ['javascript', 'application/ld+json'],
|
|
47
|
+
jruby: 'ruby',
|
|
48
|
+
kotlin: ['clike', 'text/x-kotlin'],
|
|
49
|
+
kt: ['clike', 'text/x-kotlin'],
|
|
50
|
+
less: 'css',
|
|
51
|
+
liquid: 'htmlmixed',
|
|
52
|
+
lua: 'lua',
|
|
53
|
+
node: 'javascript',
|
|
54
|
+
macruby: 'ruby',
|
|
55
|
+
markdown: 'gfm',
|
|
56
|
+
ml: ['mllike', 'text/x-ocaml'],
|
|
57
|
+
mssql: ['sql', 'text/x-mssql'],
|
|
58
|
+
mysql: ['sql', 'text/x-mysql'],
|
|
59
|
+
objc: ['clike', 'text/x-objectivec'],
|
|
60
|
+
'objc++': ['clike', 'text/x-objectivec++'],
|
|
61
|
+
objcpp: ['clike', 'text/x-objectivec++'],
|
|
62
|
+
objectivec: ['clike', 'text/x-objectivec'],
|
|
63
|
+
objectivecpp: ['clike', 'text/x-objectivec++'],
|
|
64
|
+
objectivecplusplus: ['clike', 'text/x-objectivec++'],
|
|
65
|
+
ocaml: ['mllike', 'text/x-ocaml'],
|
|
66
|
+
php: ['php', 'text/x-php'],
|
|
67
|
+
pgsql: ['sql', 'text/x-pgsql'],
|
|
68
|
+
pl: 'perl',
|
|
69
|
+
plsql: ['sql', 'text/x-plsql'],
|
|
70
|
+
postgres: ['sql', 'text/x-pgsql'],
|
|
71
|
+
postgresql: ['sql', 'text/x-pgsql'],
|
|
72
|
+
ps1: 'powershell',
|
|
73
|
+
py: 'python',
|
|
74
|
+
r: 'r',
|
|
75
|
+
rake: 'ruby',
|
|
76
|
+
rb: 'ruby',
|
|
77
|
+
rbx: 'ruby',
|
|
78
|
+
rs: 'rust',
|
|
79
|
+
sass: 'css',
|
|
80
|
+
scala: ['clike', 'text/x-scala'],
|
|
81
|
+
scss: 'css',
|
|
82
|
+
sh: 'shell',
|
|
83
|
+
sol: 'solidity',
|
|
84
|
+
solidity: 'solidity',
|
|
85
|
+
sql: ['sql', 'text/x-sql'],
|
|
86
|
+
sqlite: ['sql', 'text/x-sqlite'],
|
|
87
|
+
styl: 'css',
|
|
88
|
+
stylus: 'css',
|
|
89
|
+
text: ['null', 'text/plain'],
|
|
90
|
+
ts: ['javascript', 'text/typescript'],
|
|
91
|
+
typescript: ['javascript', 'text/typescript'],
|
|
92
|
+
xhtml: 'htmlmixed',
|
|
93
|
+
yml: 'yaml',
|
|
94
|
+
zsh: 'shell',
|
|
95
|
+
};
|
|
96
|
+
function getMode(lang) {
|
|
97
|
+
let mode = lang;
|
|
98
|
+
if (mode in exports.modes) {
|
|
99
|
+
mode = exports.modes[mode];
|
|
100
|
+
if (Array.isArray(mode)) {
|
|
101
|
+
[, mode] = mode;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return mode;
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function uppercase(language: string): string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = uppercase;
|
|
4
|
+
const codeTypes = {
|
|
5
|
+
asp: 'ASP.NET',
|
|
6
|
+
aspx: 'ASP.NET',
|
|
7
|
+
bash: 'Bash',
|
|
8
|
+
c: 'C',
|
|
9
|
+
'c#': 'C#',
|
|
10
|
+
'c++': 'C++',
|
|
11
|
+
coffeescript: 'CoffeeScript',
|
|
12
|
+
clj: 'Clojure',
|
|
13
|
+
cljc: 'Clojure',
|
|
14
|
+
cljx: 'Clojure',
|
|
15
|
+
clojure: 'Clojure',
|
|
16
|
+
cplusplus: 'C++',
|
|
17
|
+
cpp: 'C++',
|
|
18
|
+
cql: 'Cassandra',
|
|
19
|
+
cs: 'C#',
|
|
20
|
+
csharp: 'C#',
|
|
21
|
+
css: 'CSS',
|
|
22
|
+
curl: 'cURL',
|
|
23
|
+
d: 'D',
|
|
24
|
+
dart: 'Dart',
|
|
25
|
+
diff: 'Diff',
|
|
26
|
+
dockerfile: 'Dockerfile',
|
|
27
|
+
ecmascript: 'ECMAScript',
|
|
28
|
+
erl: 'Erlang',
|
|
29
|
+
erlang: 'Erlang',
|
|
30
|
+
go: 'Go',
|
|
31
|
+
gql: 'GraphQL',
|
|
32
|
+
gradle: 'Gradle',
|
|
33
|
+
graphql: 'GraphQL',
|
|
34
|
+
groovy: 'Groovy',
|
|
35
|
+
handlebars: 'Handlebars',
|
|
36
|
+
hbs: 'Handlebars',
|
|
37
|
+
haml: 'HAML',
|
|
38
|
+
haxe: 'Haxe',
|
|
39
|
+
html: 'HTML',
|
|
40
|
+
http: 'HTTP',
|
|
41
|
+
java: 'Java',
|
|
42
|
+
javascript: 'JavaScript',
|
|
43
|
+
jinja2: 'Jinja2',
|
|
44
|
+
jl: 'Julia',
|
|
45
|
+
jruby: 'JRuby',
|
|
46
|
+
js: 'JavaScript',
|
|
47
|
+
json: 'JSON',
|
|
48
|
+
jsx: 'JSX',
|
|
49
|
+
julia: 'Julia',
|
|
50
|
+
kotlin: 'Kotlin',
|
|
51
|
+
kt: 'Kotlin',
|
|
52
|
+
less: 'LESS',
|
|
53
|
+
liquid: 'Liquid',
|
|
54
|
+
lua: 'Lua',
|
|
55
|
+
macruby: 'MacRuby',
|
|
56
|
+
markdown: 'Markdown',
|
|
57
|
+
md: 'Markdown',
|
|
58
|
+
mermaid: 'Mermaid', // syntax highlighting not supported yet
|
|
59
|
+
ml: 'OCaml',
|
|
60
|
+
mssql: 'SQL Server',
|
|
61
|
+
mysql: 'MySQL',
|
|
62
|
+
node: 'Node',
|
|
63
|
+
objc: 'Objective-C',
|
|
64
|
+
'objc++': 'Objective-C++',
|
|
65
|
+
objcpp: 'Objective-C++',
|
|
66
|
+
objectivec: 'Objective-C',
|
|
67
|
+
objectivecpp: 'Objective-C++',
|
|
68
|
+
objectivecplusplus: 'Objective-C++',
|
|
69
|
+
ocaml: 'OCaml',
|
|
70
|
+
perl: 'Perl',
|
|
71
|
+
php: 'PHP',
|
|
72
|
+
pl: 'Perl',
|
|
73
|
+
pgsql: 'PL/pgSQL',
|
|
74
|
+
plsql: 'PL/SQL',
|
|
75
|
+
postgres: 'PostgreSQL',
|
|
76
|
+
postgresql: 'PostgreSQL',
|
|
77
|
+
powershell: 'PowerShell',
|
|
78
|
+
ps1: 'PowerShell',
|
|
79
|
+
python: 'Python',
|
|
80
|
+
py: 'Python',
|
|
81
|
+
r: 'R',
|
|
82
|
+
rake: 'Rake',
|
|
83
|
+
rb: 'Ruby',
|
|
84
|
+
rbx: 'Rubinius',
|
|
85
|
+
rs: 'Rust',
|
|
86
|
+
ruby: 'Ruby',
|
|
87
|
+
rust: 'Rust',
|
|
88
|
+
sass: 'Sass',
|
|
89
|
+
scala: 'Scala',
|
|
90
|
+
scss: 'SCSS',
|
|
91
|
+
sh: 'Shell',
|
|
92
|
+
shell: 'Shell',
|
|
93
|
+
smarty: 'Smarty',
|
|
94
|
+
solidity: 'Solidity',
|
|
95
|
+
sql: 'SQL',
|
|
96
|
+
sqlite: 'SQLite',
|
|
97
|
+
stylus: 'Stylus',
|
|
98
|
+
styl: 'Stylus',
|
|
99
|
+
swift: 'Swift',
|
|
100
|
+
text: 'Text',
|
|
101
|
+
toml: 'TOML',
|
|
102
|
+
twig: 'Twig',
|
|
103
|
+
typescript: 'TypeScript',
|
|
104
|
+
xhtml: 'XHTML',
|
|
105
|
+
xml: 'XML',
|
|
106
|
+
yaml: 'YAML',
|
|
107
|
+
yml: 'YAML',
|
|
108
|
+
zsh: 'Zsh',
|
|
109
|
+
};
|
|
110
|
+
function uppercase(language) {
|
|
111
|
+
if (language in codeTypes)
|
|
112
|
+
return codeTypes[language];
|
|
113
|
+
return language;
|
|
114
|
+
}
|
package/knip.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { KnipConfig } from 'knip';
|
|
2
|
+
|
|
3
|
+
const config: KnipConfig = {
|
|
4
|
+
entry: ['src/utils/index.ts', 'public/index.js', 'public/index.legacy.js'],
|
|
5
|
+
ignore: ['__tests__/__fixtures__/**'],
|
|
6
|
+
ignoreDependencies: [
|
|
7
|
+
'@csstools/css-parser-algorithms', // required in order to get vitest/jsdom running in CI
|
|
8
|
+
'jsdom', // this is installed via vitest
|
|
9
|
+
],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readme/syntax-highlighter",
|
|
3
3
|
"description": "ReadMe's React-based syntax highlighter",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "15.0.0-beta.0",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
7
7
|
"license": "ISC",
|
|
@@ -11,16 +11,34 @@
|
|
|
11
11
|
},
|
|
12
12
|
"homepage": "https://readmeio.github.io/syntax-highlighter/",
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=22"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"browser": "./dist/index.js",
|
|
19
|
+
"require": "./dist/index.node.js",
|
|
20
|
+
"node": "./dist/index.node.js"
|
|
21
|
+
},
|
|
22
|
+
"./browser": {
|
|
23
|
+
"browser": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./utils": {
|
|
27
|
+
"require": "./dist-utils/index.js",
|
|
28
|
+
"default": "./dist-utils/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
15
31
|
},
|
|
16
32
|
"scripts": {
|
|
17
|
-
"build": "webpack --progress",
|
|
18
|
-
"
|
|
33
|
+
"build": "webpack --progress && tsc",
|
|
34
|
+
"format": "prettier --write . && eslint . --fix --ext .js,.jsx,.ts,.tsx",
|
|
35
|
+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
36
|
+
"prebuild": "rm -rf dist && rm -rf dist-utils",
|
|
19
37
|
"prepack": "npm run build",
|
|
20
|
-
"pretest": "npm run lint && npm run prettier",
|
|
21
|
-
"prettier": "prettier --
|
|
38
|
+
"pretest": "npm run lint && npm run prettier && tsc --noEmit && knip",
|
|
39
|
+
"prettier": "prettier --check .",
|
|
22
40
|
"start": "webpack serve --open --config ./webpack.config.dev.js",
|
|
23
|
-
"test": "
|
|
41
|
+
"test": "vitest run --coverage",
|
|
24
42
|
"watch": "webpack -w --progress"
|
|
25
43
|
},
|
|
26
44
|
"dependencies": {
|
|
@@ -30,33 +48,31 @@
|
|
|
30
48
|
"react-codemirror2": "^8.0.0"
|
|
31
49
|
},
|
|
32
50
|
"peerDependencies": {
|
|
33
|
-
"@readme/variable": "^
|
|
51
|
+
"@readme/variable": "^18.0.0",
|
|
34
52
|
"react": "18.x",
|
|
35
53
|
"react-dom": "18.x"
|
|
36
54
|
},
|
|
37
55
|
"devDependencies": {
|
|
38
56
|
"@babel/preset-env": "^7.24.4",
|
|
39
57
|
"@babel/preset-react": "^7.24.1",
|
|
40
|
-
"@
|
|
58
|
+
"@csstools/css-parser-algorithms": "^3.0.5",
|
|
59
|
+
"@readme/eslint-config": "^14.8.1",
|
|
41
60
|
"@testing-library/jest-dom": "^6.4.2",
|
|
42
61
|
"@testing-library/react": "^16.3.0",
|
|
43
|
-
"
|
|
62
|
+
"@types/node": "^24.10.1",
|
|
63
|
+
"@vitest/coverage-v8": "^4.0.8",
|
|
44
64
|
"babel-loader": "^10.0.0",
|
|
45
|
-
"core-js": "^3.36.1",
|
|
46
65
|
"css-loader": "^7.1.1",
|
|
47
66
|
"eslint": "^8.57.0",
|
|
48
|
-
"glob": "^11.0.0",
|
|
49
67
|
"html-webpack-plugin": "^5.6.0",
|
|
50
|
-
"
|
|
51
|
-
"jest": "^29.7.0",
|
|
52
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
68
|
+
"knip": "^5.69.0",
|
|
53
69
|
"prettier": "^3.2.5",
|
|
54
|
-
"prettier-2": "npm:prettier@^2.8.8",
|
|
55
|
-
"regenerator-runtime": "^0.14.1",
|
|
56
70
|
"sass": "^1.89.2",
|
|
57
71
|
"sass-loader": "^13.3.2",
|
|
58
72
|
"style-loader": "^4.0.0",
|
|
59
|
-
"
|
|
73
|
+
"ts-loader": "^9.5.4",
|
|
74
|
+
"typescript": "^5.9.3",
|
|
75
|
+
"vitest": "^4.0.8",
|
|
60
76
|
"webpack": "^5.91.0",
|
|
61
77
|
"webpack-cli": "^6.0.1",
|
|
62
78
|
"webpack-dev-server": "^5.0.4"
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* Full list of config options here:
|
|
3
3
|
* https://codemirror.net/doc/manual.html#config
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
const codeMirrorOptions = {
|
|
6
6
|
theme: 'material-palenight',
|
|
7
7
|
tabSize: 2,
|
|
8
8
|
lineNumbers: true,
|
|
9
|
-
};
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export default codeMirrorOptions;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ICodeMirror } from 'react-codemirror2';
|
|
2
|
+
|
|
2
3
|
import React, { useEffect, useState } from 'react';
|
|
3
4
|
import { Controlled as CodeMirror } from 'react-codemirror2';
|
|
4
5
|
|
|
@@ -8,9 +9,25 @@ import { getMode } from '../utils/modes';
|
|
|
8
9
|
import defaults from './cm.options';
|
|
9
10
|
import './style.scss';
|
|
10
11
|
|
|
11
|
-
const CodeEditor
|
|
12
|
+
const CodeEditor: React.FC<{
|
|
13
|
+
children?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
code?: string;
|
|
16
|
+
lang?: string;
|
|
17
|
+
options?: ICodeMirror['options'];
|
|
18
|
+
theme?: 'material-palenight' | 'neo' | 'tomorrow-night';
|
|
19
|
+
}> = ({
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
+
className = '', // unused, I think on purpose? but not sure
|
|
22
|
+
code = '',
|
|
23
|
+
lang,
|
|
24
|
+
options = {},
|
|
25
|
+
children,
|
|
26
|
+
theme = 'material-palenight',
|
|
27
|
+
...attr
|
|
28
|
+
}) => {
|
|
12
29
|
const [value, setValue] = useState(children && typeof children === 'string' ? children : code);
|
|
13
|
-
const [mode, setMode] = useState(getMode(lang));
|
|
30
|
+
const [mode, setMode] = useState(getMode(lang as string));
|
|
14
31
|
|
|
15
32
|
useEffect(() => {
|
|
16
33
|
const incValue = children && typeof children === 'string' ? children : code;
|
|
@@ -19,7 +36,7 @@ const CodeEditor = ({ className, code, lang, options, children, theme, ...attr }
|
|
|
19
36
|
|
|
20
37
|
useEffect(() => {
|
|
21
38
|
setMode(prevMode => {
|
|
22
|
-
const newMode = getMode(lang);
|
|
39
|
+
const newMode = getMode(lang as string);
|
|
23
40
|
if (newMode !== prevMode) return newMode;
|
|
24
41
|
return prevMode;
|
|
25
42
|
});
|
|
@@ -31,33 +48,9 @@ const CodeEditor = ({ className, code, lang, options, children, theme, ...attr }
|
|
|
31
48
|
className="CodeEditor"
|
|
32
49
|
onBeforeChange={(editor, data, updatedCode) => setValue(updatedCode)}
|
|
33
50
|
options={{ ...defaults, ...options, mode, theme }}
|
|
34
|
-
value={value}
|
|
51
|
+
value={value as string}
|
|
35
52
|
/>
|
|
36
53
|
);
|
|
37
54
|
};
|
|
38
55
|
|
|
39
|
-
CodeEditor.propTypes = {
|
|
40
|
-
children: PropTypes.string,
|
|
41
|
-
className: PropTypes.string,
|
|
42
|
-
/** Code to show in the editor.
|
|
43
|
-
*/
|
|
44
|
-
code: PropTypes.string,
|
|
45
|
-
/** CodeMirror language mode to use.
|
|
46
|
-
*/
|
|
47
|
-
lang: PropTypes.string,
|
|
48
|
-
/** Custom CodeMirror configuration.
|
|
49
|
-
*/
|
|
50
|
-
options: PropTypes.object,
|
|
51
|
-
/** Syntax highlighting theme.
|
|
52
|
-
*/
|
|
53
|
-
theme: PropTypes.oneOf(['neo', 'material-palenight', 'tomorrow-night']),
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
CodeEditor.defaultProps = {
|
|
57
|
-
className: '',
|
|
58
|
-
code: '',
|
|
59
|
-
options: {},
|
|
60
|
-
theme: 'material-palenight',
|
|
61
|
-
};
|
|
62
|
-
|
|
63
56
|
export default CodeEditor;
|
package/src/codeMirror/index.jsx
CHANGED
package/src/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import codeEditor from './codeEditor';
|
|
3
|
+
import codeEditor from './codeEditor/index.tsx';
|
|
4
4
|
import codemirror, { VariablesContext as cmVariableContext } from './codeMirror';
|
|
5
|
-
import canonical from './utils/canonical';
|
|
6
|
-
import { modes } from './utils/modes';
|
|
7
|
-
import uppercase from './utils/uppercase';
|
|
5
|
+
import canonical from './utils/canonical.ts';
|
|
6
|
+
import { modes } from './utils/modes.ts';
|
|
7
|
+
import uppercase from './utils/uppercase.ts';
|
|
8
8
|
|
|
9
9
|
const SyntaxHighlighter = (
|
|
10
10
|
code,
|
|
@@ -55,9 +55,11 @@ const modeAliases = {
|
|
|
55
55
|
xhtml: 'html',
|
|
56
56
|
yml: 'yaml',
|
|
57
57
|
zsh: 'shell',
|
|
58
|
-
};
|
|
58
|
+
} as const;
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
const canonical = (language: keyof typeof modeAliases) => {
|
|
61
61
|
if (language in modeAliases) return modeAliases[language];
|
|
62
62
|
return language;
|
|
63
63
|
};
|
|
64
|
+
|
|
65
|
+
export default canonical;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// There are 2 types of lookup, single and array. e.g. `html` needs to be rendered using
|
|
9
9
|
// `htmlmixed`, but `java`, needs to be rendered using the `clike` mode.
|
|
10
10
|
//
|
|
11
|
-
const modes = {
|
|
11
|
+
export const modes = {
|
|
12
12
|
asp: 'clike',
|
|
13
13
|
aspx: 'clike',
|
|
14
14
|
bash: 'shell',
|
|
@@ -88,18 +88,16 @@ const modes = {
|
|
|
88
88
|
xhtml: 'htmlmixed',
|
|
89
89
|
yml: 'yaml',
|
|
90
90
|
zsh: 'shell',
|
|
91
|
-
};
|
|
91
|
+
} as const;
|
|
92
92
|
|
|
93
|
-
function getMode(lang) {
|
|
94
|
-
let mode = lang;
|
|
93
|
+
export function getMode(lang: string): string {
|
|
94
|
+
let mode: string | readonly [string, string] = lang;
|
|
95
95
|
if (mode in modes) {
|
|
96
|
-
mode = modes[mode];
|
|
96
|
+
mode = modes[mode as keyof typeof modes];
|
|
97
97
|
if (Array.isArray(mode)) {
|
|
98
98
|
[, mode] = mode;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
return mode;
|
|
102
|
+
return mode as string;
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
module.exports = { modes, getMode };
|
|
@@ -103,9 +103,9 @@ const codeTypes = {
|
|
|
103
103
|
yaml: 'YAML',
|
|
104
104
|
yml: 'YAML',
|
|
105
105
|
zsh: 'Zsh',
|
|
106
|
-
};
|
|
106
|
+
} as const;
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
if (language in codeTypes) return codeTypes[language];
|
|
108
|
+
export default function uppercase(language: string) {
|
|
109
|
+
if (language in codeTypes) return codeTypes[language as keyof typeof codeTypes];
|
|
110
110
|
return language;
|
|
111
|
-
}
|
|
111
|
+
}
|
package/tsconfig.json
ADDED
package/webpack.config.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
|
|
3
|
-
const TerserPlugin = require('terser-webpack-plugin');
|
|
4
|
-
|
|
5
3
|
const base = {
|
|
6
4
|
mode: 'production',
|
|
7
5
|
module: {
|
|
8
6
|
rules: [
|
|
9
7
|
{
|
|
10
|
-
test: /\.
|
|
8
|
+
test: /\.(j|t)s(x?)$/,
|
|
11
9
|
use: {
|
|
12
10
|
loader: 'babel-loader',
|
|
13
11
|
options: {
|
|
@@ -15,6 +13,16 @@ const base = {
|
|
|
15
13
|
},
|
|
16
14
|
},
|
|
17
15
|
},
|
|
16
|
+
{
|
|
17
|
+
test: /\.tsx?$/,
|
|
18
|
+
use: {
|
|
19
|
+
loader: 'ts-loader',
|
|
20
|
+
options: {
|
|
21
|
+
transpileOnly: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
exclude: /node_modules/,
|
|
25
|
+
},
|
|
18
26
|
{
|
|
19
27
|
test: /\.s?css$/,
|
|
20
28
|
use: ['style-loader', 'css-loader', 'sass-loader'],
|
|
@@ -22,8 +30,7 @@ const base = {
|
|
|
22
30
|
],
|
|
23
31
|
},
|
|
24
32
|
optimization: {
|
|
25
|
-
minimize:
|
|
26
|
-
minimizer: [new TerserPlugin()],
|
|
33
|
+
minimize: false,
|
|
27
34
|
},
|
|
28
35
|
externals: {
|
|
29
36
|
react: {
|
|
@@ -43,14 +50,14 @@ const base = {
|
|
|
43
50
|
'@readme/variable': '@readme/variable',
|
|
44
51
|
},
|
|
45
52
|
resolve: {
|
|
46
|
-
extensions: ['.js', '.jsx'],
|
|
53
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
47
54
|
},
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
const serverConfig = {
|
|
51
58
|
...base,
|
|
52
59
|
target: 'node',
|
|
53
|
-
entry: ['./src/index.node.
|
|
60
|
+
entry: ['./src/index.node.ts'],
|
|
54
61
|
output: {
|
|
55
62
|
path: path.resolve(__dirname, 'dist'),
|
|
56
63
|
filename: 'index.node.js',
|