@cobapen/markdown 0.4.2 → 0.5.1
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/lib/code/highlight-custom.d.ts +2 -0
- package/lib/code/highlight-custom.js +179 -0
- package/lib/code/highlight.js +1 -1
- package/lib/index.js +3 -0
- package/lib/math/mathjax.d.ts +91 -13
- package/lib/math/mathjax.js +123 -27
- package/lib/math/mdparser.d.ts +2 -2
- package/lib/utils/merge.d.ts +12 -0
- package/lib/utils/merge.js +50 -0
- package/package.json +15 -16
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import hljs from "highlight.js/lib/core";
|
|
2
|
+
import langaccesslog from "highlight.js/lib/languages/accesslog";
|
|
3
|
+
import langarduino from "highlight.js/lib/languages/arduino";
|
|
4
|
+
import langarmasm from "highlight.js/lib/languages/armasm";
|
|
5
|
+
import langasciidoc from "highlight.js/lib/languages/asciidoc";
|
|
6
|
+
import langavrasm from "highlight.js/lib/languages/avrasm";
|
|
7
|
+
import langawk from "highlight.js/lib/languages/awk";
|
|
8
|
+
import langbash from "highlight.js/lib/languages/bash";
|
|
9
|
+
import langbasic from "highlight.js/lib/languages/basic";
|
|
10
|
+
import langbnf from "highlight.js/lib/languages/bnf";
|
|
11
|
+
import langc from "highlight.js/lib/languages/c";
|
|
12
|
+
import langclojure from "highlight.js/lib/languages/clojure";
|
|
13
|
+
import langcmake from "highlight.js/lib/languages/cmake";
|
|
14
|
+
import langcoffeescript from "highlight.js/lib/languages/coffeescript";
|
|
15
|
+
import langcpp from "highlight.js/lib/languages/cpp";
|
|
16
|
+
import langcsharp from "highlight.js/lib/languages/csharp";
|
|
17
|
+
import langcss from "highlight.js/lib/languages/css";
|
|
18
|
+
import langd from "highlight.js/lib/languages/d";
|
|
19
|
+
import langdart from "highlight.js/lib/languages/dart";
|
|
20
|
+
import langdelphi from "highlight.js/lib/languages/delphi";
|
|
21
|
+
import langdiff from "highlight.js/lib/languages/diff";
|
|
22
|
+
import langdjango from "highlight.js/lib/languages/django";
|
|
23
|
+
import langdns from "highlight.js/lib/languages/dns";
|
|
24
|
+
import langdockerfile from "highlight.js/lib/languages/dockerfile";
|
|
25
|
+
import langdos from "highlight.js/lib/languages/dos";
|
|
26
|
+
import langebnf from "highlight.js/lib/languages/ebnf";
|
|
27
|
+
import langelixir from "highlight.js/lib/languages/elixir";
|
|
28
|
+
import langelm from "highlight.js/lib/languages/elm";
|
|
29
|
+
import langerb from "highlight.js/lib/languages/erb";
|
|
30
|
+
import langerlang from "highlight.js/lib/languages/erlang";
|
|
31
|
+
import langexcel from "highlight.js/lib/languages/excel";
|
|
32
|
+
import langfortran from "highlight.js/lib/languages/fortran";
|
|
33
|
+
import langglsl from "highlight.js/lib/languages/glsl";
|
|
34
|
+
import langgo from "highlight.js/lib/languages/go";
|
|
35
|
+
import langgradle from "highlight.js/lib/languages/gradle";
|
|
36
|
+
import langgraphql from "highlight.js/lib/languages/graphql";
|
|
37
|
+
import langhandlebars from "highlight.js/lib/languages/handlebars";
|
|
38
|
+
import langhaskell from "highlight.js/lib/languages/haskell";
|
|
39
|
+
import langhttp from "highlight.js/lib/languages/http";
|
|
40
|
+
import langini from "highlight.js/lib/languages/ini";
|
|
41
|
+
import langjava from "highlight.js/lib/languages/java";
|
|
42
|
+
import langjavascript from "highlight.js/lib/languages/javascript";
|
|
43
|
+
import langjson from "highlight.js/lib/languages/json";
|
|
44
|
+
import langjulia from "highlight.js/lib/languages/julia";
|
|
45
|
+
import langkotlin from "highlight.js/lib/languages/kotlin";
|
|
46
|
+
import langlatex from "highlight.js/lib/languages/latex";
|
|
47
|
+
import langlisp from "highlight.js/lib/languages/lisp";
|
|
48
|
+
import langllvm from "highlight.js/lib/languages/llvm";
|
|
49
|
+
import langlua from "highlight.js/lib/languages/lua";
|
|
50
|
+
import langmakefile from "highlight.js/lib/languages/makefile";
|
|
51
|
+
import langmarkdown from "highlight.js/lib/languages/markdown";
|
|
52
|
+
import langmatlab from "highlight.js/lib/languages/matlab";
|
|
53
|
+
import langmipsasm from "highlight.js/lib/languages/mipsasm";
|
|
54
|
+
import langnginx from "highlight.js/lib/languages/nginx";
|
|
55
|
+
import langnim from "highlight.js/lib/languages/nim";
|
|
56
|
+
import langnode from "highlight.js/lib/languages/node-repl";
|
|
57
|
+
import langobjectivec from "highlight.js/lib/languages/objectivec";
|
|
58
|
+
import langocaml from "highlight.js/lib/languages/ocaml";
|
|
59
|
+
import langperl from "highlight.js/lib/languages/perl";
|
|
60
|
+
import langphp from "highlight.js/lib/languages/php";
|
|
61
|
+
import langplaintext from "highlight.js/lib/languages/plaintext";
|
|
62
|
+
import langpowershell from "highlight.js/lib/languages/powershell";
|
|
63
|
+
import langprocessing from "highlight.js/lib/languages/processing";
|
|
64
|
+
import langprotobuf from "highlight.js/lib/languages/protobuf";
|
|
65
|
+
import langpython from "highlight.js/lib/languages/python";
|
|
66
|
+
import langqml from "highlight.js/lib/languages/qml";
|
|
67
|
+
import langr from "highlight.js/lib/languages/r";
|
|
68
|
+
import langruby from "highlight.js/lib/languages/ruby";
|
|
69
|
+
import langrust from "highlight.js/lib/languages/rust";
|
|
70
|
+
import langscala from "highlight.js/lib/languages/scala";
|
|
71
|
+
import langscheme from "highlight.js/lib/languages/scheme";
|
|
72
|
+
import langscss from "highlight.js/lib/languages/scss";
|
|
73
|
+
import langshell from "highlight.js/lib/languages/shell";
|
|
74
|
+
import langsmalltalk from "highlight.js/lib/languages/smalltalk";
|
|
75
|
+
import langsql from "highlight.js/lib/languages/sql";
|
|
76
|
+
import langswift from "highlight.js/lib/languages/swift";
|
|
77
|
+
import langtwig from "highlight.js/lib/languages/twig";
|
|
78
|
+
import langtypescript from "highlight.js/lib/languages/typescript";
|
|
79
|
+
import langvbnet from "highlight.js/lib/languages/vbnet";
|
|
80
|
+
import langvbscript from "highlight.js/lib/languages/vbscript";
|
|
81
|
+
import langverilog from "highlight.js/lib/languages/verilog";
|
|
82
|
+
import langvhdl from "highlight.js/lib/languages/vhdl";
|
|
83
|
+
import langvim from "highlight.js/lib/languages/vim";
|
|
84
|
+
import langwasm from "highlight.js/lib/languages/wasm";
|
|
85
|
+
import langx86asm from "highlight.js/lib/languages/x86asm";
|
|
86
|
+
import langxml from "highlight.js/lib/languages/xml";
|
|
87
|
+
import langyaml from "highlight.js/lib/languages/yaml";
|
|
88
|
+
const languages = [
|
|
89
|
+
["accesslog", langaccesslog],
|
|
90
|
+
["arduino", langarduino],
|
|
91
|
+
["armasm", langarmasm],
|
|
92
|
+
["asciidoc", langasciidoc],
|
|
93
|
+
["avrasm", langavrasm],
|
|
94
|
+
["awk", langawk],
|
|
95
|
+
["bash", langbash],
|
|
96
|
+
["basic", langbasic],
|
|
97
|
+
["bnf", langbnf],
|
|
98
|
+
["c", langc],
|
|
99
|
+
["clojure", langclojure],
|
|
100
|
+
["cmake", langcmake],
|
|
101
|
+
["coffeescript", langcoffeescript],
|
|
102
|
+
["cpp", langcpp],
|
|
103
|
+
["csharp", langcsharp],
|
|
104
|
+
["css", langcss],
|
|
105
|
+
["d", langd],
|
|
106
|
+
["dart", langdart],
|
|
107
|
+
["delphi", langdelphi],
|
|
108
|
+
["diff", langdiff],
|
|
109
|
+
["django", langdjango],
|
|
110
|
+
["dns", langdns],
|
|
111
|
+
["dockerfile", langdockerfile],
|
|
112
|
+
["dos", langdos],
|
|
113
|
+
["ebnf", langebnf],
|
|
114
|
+
["elixir", langelixir],
|
|
115
|
+
["elm", langelm],
|
|
116
|
+
["erb", langerb],
|
|
117
|
+
["erlang", langerlang],
|
|
118
|
+
["excel", langexcel],
|
|
119
|
+
["fortran", langfortran],
|
|
120
|
+
["glsl", langglsl],
|
|
121
|
+
["go", langgo],
|
|
122
|
+
["gradle", langgradle],
|
|
123
|
+
["graphql", langgraphql],
|
|
124
|
+
["handlebars", langhandlebars],
|
|
125
|
+
["haskell", langhaskell],
|
|
126
|
+
["http", langhttp],
|
|
127
|
+
["ini", langini],
|
|
128
|
+
["java", langjava],
|
|
129
|
+
["javascript", langjavascript],
|
|
130
|
+
["json", langjson],
|
|
131
|
+
["julia", langjulia],
|
|
132
|
+
["kotlin", langkotlin],
|
|
133
|
+
["latex", langlatex],
|
|
134
|
+
["lisp", langlisp],
|
|
135
|
+
["llvm", langllvm],
|
|
136
|
+
["lua", langlua],
|
|
137
|
+
["makefile", langmakefile],
|
|
138
|
+
["markdown", langmarkdown],
|
|
139
|
+
["matlab", langmatlab],
|
|
140
|
+
["mipsasm", langmipsasm],
|
|
141
|
+
["nginx", langnginx],
|
|
142
|
+
["nim", langnim],
|
|
143
|
+
["node-repl", langnode],
|
|
144
|
+
["objectivec", langobjectivec],
|
|
145
|
+
["ocaml", langocaml],
|
|
146
|
+
["perl", langperl],
|
|
147
|
+
["php", langphp],
|
|
148
|
+
["plaintext", langplaintext],
|
|
149
|
+
["powershell", langpowershell],
|
|
150
|
+
["processing", langprocessing],
|
|
151
|
+
["protobuf", langprotobuf],
|
|
152
|
+
["python", langpython],
|
|
153
|
+
["qml", langqml],
|
|
154
|
+
["r", langr],
|
|
155
|
+
["ruby", langruby],
|
|
156
|
+
["rust", langrust],
|
|
157
|
+
["scala", langscala],
|
|
158
|
+
["scheme", langscheme],
|
|
159
|
+
["scss", langscss],
|
|
160
|
+
["shell", langshell],
|
|
161
|
+
["smalltalk", langsmalltalk],
|
|
162
|
+
["sql", langsql],
|
|
163
|
+
["swift", langswift],
|
|
164
|
+
["twig", langtwig],
|
|
165
|
+
["typescript", langtypescript],
|
|
166
|
+
["vbnet", langvbnet],
|
|
167
|
+
["vbscript", langvbscript],
|
|
168
|
+
["verilog", langverilog],
|
|
169
|
+
["vhdl", langvhdl],
|
|
170
|
+
["vim", langvim],
|
|
171
|
+
["wasm", langwasm],
|
|
172
|
+
["x86asm", langx86asm],
|
|
173
|
+
["xml", langxml],
|
|
174
|
+
["yaml", langyaml],
|
|
175
|
+
];
|
|
176
|
+
for (const [name, language] of languages) {
|
|
177
|
+
hljs.registerLanguage(name, language);
|
|
178
|
+
}
|
|
179
|
+
export default hljs;
|
package/lib/code/highlight.js
CHANGED
package/lib/index.js
CHANGED
package/lib/math/mathjax.d.ts
CHANGED
|
@@ -1,17 +1,80 @@
|
|
|
1
|
-
import { type LiteDocument } from "mathjax
|
|
2
|
-
import { LiteElement } from "mathjax
|
|
3
|
-
import { type LiteText } from "mathjax
|
|
4
|
-
import { type LiteAdaptor } from "mathjax
|
|
5
|
-
import { type MathDocument } from "mathjax
|
|
6
|
-
import { TeX } from "mathjax
|
|
7
|
-
import { CHTML } from "mathjax
|
|
1
|
+
import { type LiteDocument } from "@mathjax/src/js/adaptors/lite/Document.js";
|
|
2
|
+
import { LiteElement } from "@mathjax/src/js/adaptors/lite/Element.js";
|
|
3
|
+
import { type LiteText } from "@mathjax/src/js/adaptors/lite/Text.js";
|
|
4
|
+
import { type LiteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
|
|
5
|
+
import { type MathDocument } from "@mathjax/src/js/core/MathDocument.js";
|
|
6
|
+
import { TeX } from "@mathjax/src/js/input/tex.js";
|
|
7
|
+
import { CHTML } from "@mathjax/src/js/output/chtml.js";
|
|
8
|
+
import { type DeepPartial } from "../utils/merge.js";
|
|
9
|
+
import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
|
|
10
|
+
import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
|
|
11
|
+
import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
|
|
12
|
+
import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
|
|
13
|
+
import "@mathjax/src/js/input/tex/action/ActionConfiguration.js";
|
|
14
|
+
import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
|
|
15
|
+
import "@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js";
|
|
16
|
+
import "@mathjax/src/js/input/tex/autoload/AutoloadConfiguration.js";
|
|
17
|
+
import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
|
|
18
|
+
import "@mathjax/src/js/input/tex/bbm/BbmConfiguration.js";
|
|
19
|
+
import "@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js";
|
|
20
|
+
import "@mathjax/src/js/input/tex/bbox/BboxConfiguration.js";
|
|
21
|
+
import "@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js";
|
|
22
|
+
import "@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js";
|
|
23
|
+
import "@mathjax/src/js/input/tex/braket/BraketConfiguration.js";
|
|
24
|
+
import "@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js";
|
|
25
|
+
import "@mathjax/src/js/input/tex/cancel/CancelConfiguration.js";
|
|
26
|
+
import "@mathjax/src/js/input/tex/cases/CasesConfiguration.js";
|
|
27
|
+
import "@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js";
|
|
28
|
+
import "@mathjax/src/js/input/tex/color/ColorConfiguration.js";
|
|
29
|
+
import "@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js";
|
|
30
|
+
import "@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js";
|
|
31
|
+
import "@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js";
|
|
32
|
+
import "@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js";
|
|
33
|
+
import "@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js";
|
|
34
|
+
import "@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js";
|
|
35
|
+
import "@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js";
|
|
36
|
+
import "@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js";
|
|
37
|
+
import "@mathjax/src/js/input/tex/html/HtmlConfiguration.js";
|
|
38
|
+
import "@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js";
|
|
39
|
+
import "@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js";
|
|
40
|
+
import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
|
|
41
|
+
import "@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js";
|
|
42
|
+
import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
|
|
43
|
+
import "@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js";
|
|
44
|
+
import "@mathjax/src/js/input/tex/require/RequireConfiguration.js";
|
|
45
|
+
import "@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js";
|
|
46
|
+
import "@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js";
|
|
47
|
+
import "@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js";
|
|
48
|
+
import "@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js";
|
|
49
|
+
import "@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js";
|
|
50
|
+
import "@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js";
|
|
51
|
+
import "@mathjax/src/js/input/tex/units/UnitsConfiguration.js";
|
|
52
|
+
import "@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js";
|
|
53
|
+
import "@mathjax/src/js/input/tex/verb/VerbConfiguration.js";
|
|
8
54
|
type N = LiteElement;
|
|
9
55
|
type T = LiteText;
|
|
10
56
|
type D = LiteDocument;
|
|
57
|
+
declare const fontNames: readonly ["mathjax-newcm", "mathjax-stix2"];
|
|
58
|
+
type FontName = typeof fontNames[number];
|
|
11
59
|
interface AnyObject {
|
|
12
60
|
[x: string]: any;
|
|
13
61
|
}
|
|
14
|
-
interface
|
|
62
|
+
export interface Options {
|
|
63
|
+
loader?: DeepPartial<LoaderOptions>;
|
|
64
|
+
tex?: DeepPartial<TexInputOptions>;
|
|
65
|
+
output?: DeepPartial<OutputOptions>;
|
|
66
|
+
chtml?: DeepPartial<CHTMLOptions>;
|
|
67
|
+
}
|
|
68
|
+
interface LoaderOptions {
|
|
69
|
+
load: string[];
|
|
70
|
+
paths: {
|
|
71
|
+
mathjax?: {
|
|
72
|
+
[x: string]: string;
|
|
73
|
+
};
|
|
74
|
+
fonts?: string;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
interface TexInputOptions {
|
|
15
78
|
packages: string | [string] | AnyObject;
|
|
16
79
|
inlineMath: [[string, string]];
|
|
17
80
|
displayMath: [[string, string]];
|
|
@@ -30,7 +93,7 @@ interface TexConfig {
|
|
|
30
93
|
formatError: (jax: object, err: Error) => void;
|
|
31
94
|
macros: AnyObject;
|
|
32
95
|
}
|
|
33
|
-
interface
|
|
96
|
+
interface OutputOptions {
|
|
34
97
|
scale: number;
|
|
35
98
|
minScale: number;
|
|
36
99
|
matchFontHeight: boolean;
|
|
@@ -43,16 +106,31 @@ interface CHTMLConfig {
|
|
|
43
106
|
exFactor: number;
|
|
44
107
|
displayAlign: string;
|
|
45
108
|
displayIndent: number | string;
|
|
109
|
+
linebreaks: {
|
|
110
|
+
inline: boolean;
|
|
111
|
+
width: number | string;
|
|
112
|
+
lineleading: number;
|
|
113
|
+
};
|
|
114
|
+
font: FontName;
|
|
115
|
+
fontPath: string;
|
|
116
|
+
fontExtensions: string[];
|
|
117
|
+
htmlHDW: "auto" | "use" | "force" | "ignore";
|
|
118
|
+
preFilters: string[];
|
|
119
|
+
postFilters: string[];
|
|
120
|
+
fontData: object;
|
|
121
|
+
[x: string]: any;
|
|
122
|
+
}
|
|
123
|
+
interface CHTMLOptions {
|
|
124
|
+
matchFontHeight: boolean;
|
|
46
125
|
fontURL: string;
|
|
126
|
+
dynamicPrefix: string;
|
|
47
127
|
adaptiveCSS: boolean;
|
|
48
128
|
}
|
|
49
|
-
export interface
|
|
129
|
+
export interface ConvertOptions {
|
|
50
130
|
inline: boolean;
|
|
51
131
|
em: number;
|
|
52
132
|
ex: number;
|
|
53
133
|
width: number;
|
|
54
|
-
tex?: Partial<TexConfig>;
|
|
55
|
-
chtml?: Partial<CHTMLConfig>;
|
|
56
134
|
}
|
|
57
135
|
export declare class MathjaxEngine {
|
|
58
136
|
option: Options;
|
|
@@ -61,7 +139,7 @@ export declare class MathjaxEngine {
|
|
|
61
139
|
chtml: CHTML<N, T, D>;
|
|
62
140
|
html: MathDocument<N, T, D>;
|
|
63
141
|
constructor(option?: Partial<Options>);
|
|
64
|
-
convert(tex: string, override?: Partial<
|
|
142
|
+
convert(tex: string, override?: Partial<ConvertOptions>): string;
|
|
65
143
|
stylesheet(): string;
|
|
66
144
|
}
|
|
67
145
|
export {};
|
package/lib/math/mathjax.js
CHANGED
|
@@ -1,27 +1,99 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { MathJaxNewcmFont } from "@mathjax/mathjax-newcm-font/mjs/chtml.js";
|
|
2
|
+
import { MathJaxStix2Font } from "@mathjax/mathjax-stix2-font/mjs/chtml.js";
|
|
3
|
+
import { source as mjsource } from "@mathjax/src/components/mjs/source.js";
|
|
4
|
+
import { LiteElement } from "@mathjax/src/js/adaptors/lite/Element.js";
|
|
5
|
+
import { liteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
|
|
6
|
+
import { RegisterHTMLHandler } from "@mathjax/src/js/handlers/html.js";
|
|
7
|
+
import { TeX } from "@mathjax/src/js/input/tex.js";
|
|
8
|
+
import { mathjax } from "@mathjax/src/js/mathjax.js";
|
|
9
|
+
import { CHTML } from "@mathjax/src/js/output/chtml.js";
|
|
10
|
+
import { merge } from "../utils/merge.js";
|
|
11
|
+
import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
|
|
12
|
+
import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
|
|
13
|
+
import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
|
|
14
|
+
import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
|
|
15
|
+
import "@mathjax/src/js/input/tex/action/ActionConfiguration.js";
|
|
16
|
+
import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
|
|
17
|
+
import "@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js";
|
|
18
|
+
import "@mathjax/src/js/input/tex/autoload/AutoloadConfiguration.js";
|
|
19
|
+
import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
|
|
20
|
+
import "@mathjax/src/js/input/tex/bbm/BbmConfiguration.js";
|
|
21
|
+
import "@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js";
|
|
22
|
+
import "@mathjax/src/js/input/tex/bbox/BboxConfiguration.js";
|
|
23
|
+
import "@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js";
|
|
24
|
+
import "@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js";
|
|
25
|
+
import "@mathjax/src/js/input/tex/braket/BraketConfiguration.js";
|
|
26
|
+
import "@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js";
|
|
27
|
+
import "@mathjax/src/js/input/tex/cancel/CancelConfiguration.js";
|
|
28
|
+
import "@mathjax/src/js/input/tex/cases/CasesConfiguration.js";
|
|
29
|
+
import "@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js";
|
|
30
|
+
import "@mathjax/src/js/input/tex/color/ColorConfiguration.js";
|
|
31
|
+
import "@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js";
|
|
32
|
+
import "@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js";
|
|
33
|
+
import "@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js";
|
|
34
|
+
import "@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js";
|
|
35
|
+
import "@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js";
|
|
36
|
+
import "@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js";
|
|
37
|
+
import "@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js";
|
|
38
|
+
import "@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js";
|
|
39
|
+
import "@mathjax/src/js/input/tex/html/HtmlConfiguration.js";
|
|
40
|
+
import "@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js";
|
|
41
|
+
import "@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js";
|
|
42
|
+
import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
|
|
43
|
+
import "@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js";
|
|
44
|
+
import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
|
|
45
|
+
import "@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js";
|
|
46
|
+
import "@mathjax/src/js/input/tex/require/RequireConfiguration.js";
|
|
47
|
+
import "@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js";
|
|
48
|
+
import "@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js";
|
|
49
|
+
import "@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js";
|
|
50
|
+
import "@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js";
|
|
51
|
+
import "@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js";
|
|
52
|
+
import "@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js";
|
|
53
|
+
import "@mathjax/src/js/input/tex/units/UnitsConfiguration.js";
|
|
54
|
+
import "@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js";
|
|
55
|
+
import "@mathjax/src/js/input/tex/verb/VerbConfiguration.js";
|
|
56
|
+
const fontNames = [
|
|
57
|
+
"mathjax-newcm",
|
|
58
|
+
"mathjax-stix2"
|
|
59
|
+
];
|
|
60
|
+
function isFontName(name) {
|
|
61
|
+
return fontNames.includes(name);
|
|
62
|
+
}
|
|
63
|
+
const fontDataMap = {
|
|
64
|
+
"mathjax-newcm": MathJaxNewcmFont,
|
|
65
|
+
"mathjax-stix2": MathJaxStix2Font,
|
|
66
|
+
};
|
|
67
|
+
const texExtensions = Object.keys(mjsource)
|
|
68
|
+
.filter(name => name.substring(0, 6) === "[tex]/")
|
|
69
|
+
.map(name => name.substring(6))
|
|
70
|
+
.sort();
|
|
71
|
+
const packageList = [
|
|
72
|
+
"base",
|
|
73
|
+
"ams",
|
|
74
|
+
"newcommand",
|
|
75
|
+
"noundefined",
|
|
76
|
+
].concat(texExtensions);
|
|
77
|
+
const MATHJAX_DEFAULT_FONT_URL = (name) => `https://cdn.jsdelivr.net/npm/@mathjax/${name}-font@4/chtml/woff2`;
|
|
78
|
+
const defaultMathOption = {
|
|
15
79
|
tex: {
|
|
16
|
-
packages:
|
|
80
|
+
packages: packageList,
|
|
17
81
|
},
|
|
18
|
-
|
|
82
|
+
output: {
|
|
19
83
|
scale: 1.21,
|
|
20
|
-
fontURL: MATHJAX_DEFAULT_FONT_URL,
|
|
21
|
-
adaptiveCSS: true,
|
|
22
84
|
exFactor: 5,
|
|
85
|
+
font: "mathjax-newcm",
|
|
86
|
+
},
|
|
87
|
+
chtml: {
|
|
88
|
+
adaptiveCSS: true,
|
|
23
89
|
},
|
|
24
90
|
};
|
|
91
|
+
const defaultConvertOption = {
|
|
92
|
+
inline: false,
|
|
93
|
+
em: 16,
|
|
94
|
+
ex: 8,
|
|
95
|
+
width: 80 * 16,
|
|
96
|
+
};
|
|
25
97
|
export class MathjaxEngine {
|
|
26
98
|
option;
|
|
27
99
|
adaptor;
|
|
@@ -29,14 +101,14 @@ export class MathjaxEngine {
|
|
|
29
101
|
chtml;
|
|
30
102
|
html;
|
|
31
103
|
constructor(option) {
|
|
32
|
-
this.option =
|
|
33
|
-
if (typeof this.option.tex?.packages === "string") {
|
|
34
|
-
this.option.tex.packages = this.option.tex.packages.split(/\s*,\s*/);
|
|
35
|
-
}
|
|
104
|
+
this.option = initOption(option);
|
|
36
105
|
this.adaptor = liteAdaptor();
|
|
37
106
|
RegisterHTMLHandler(this.adaptor);
|
|
38
107
|
const tex = new TeX(this.option.tex);
|
|
39
|
-
const chtml = new CHTML(
|
|
108
|
+
const chtml = new CHTML({
|
|
109
|
+
...this.option.output,
|
|
110
|
+
...this.option.chtml,
|
|
111
|
+
});
|
|
40
112
|
const html = mathjax.document("", {
|
|
41
113
|
InputJax: tex,
|
|
42
114
|
OutputJax: chtml,
|
|
@@ -60,10 +132,10 @@ export class MathjaxEngine {
|
|
|
60
132
|
}
|
|
61
133
|
convert(tex, override) {
|
|
62
134
|
const node = this.html.convert(tex, {
|
|
63
|
-
display: !(override?.inline ??
|
|
64
|
-
em: override?.em ??
|
|
65
|
-
ex: override?.ex ??
|
|
66
|
-
containerWidth: override?.width ??
|
|
135
|
+
display: !(override?.inline ?? defaultConvertOption.inline),
|
|
136
|
+
em: override?.em ?? defaultConvertOption.em,
|
|
137
|
+
ex: override?.ex ?? defaultConvertOption.ex,
|
|
138
|
+
containerWidth: override?.width ?? defaultConvertOption.width,
|
|
67
139
|
scale: 1.0,
|
|
68
140
|
});
|
|
69
141
|
if (node instanceof LiteElement) {
|
|
@@ -77,3 +149,27 @@ export class MathjaxEngine {
|
|
|
77
149
|
return this.adaptor.textContent(this.chtml.styleSheet(this.html));
|
|
78
150
|
}
|
|
79
151
|
}
|
|
152
|
+
function initOption(opt) {
|
|
153
|
+
const option = merge(defaultMathOption, opt);
|
|
154
|
+
const packages = option?.tex?.packages;
|
|
155
|
+
if (typeof packages === "string") {
|
|
156
|
+
option.tex = option.tex ?? {};
|
|
157
|
+
option.tex.packages = packages.split(/\s*,\s*/);
|
|
158
|
+
}
|
|
159
|
+
if (option.output?.font !== undefined && typeof option.output.font === "string") {
|
|
160
|
+
let name = option.output.font.trim();
|
|
161
|
+
if (name === "default") {
|
|
162
|
+
name = "mathjax-newcm";
|
|
163
|
+
}
|
|
164
|
+
if (isFontName(name)) {
|
|
165
|
+
if (option.output.fontData === undefined) {
|
|
166
|
+
option.output.fontData = fontDataMap[name];
|
|
167
|
+
}
|
|
168
|
+
if (option.chtml?.fontURL === undefined) {
|
|
169
|
+
option.chtml = option.chtml ?? {};
|
|
170
|
+
option.chtml.fontURL = MATHJAX_DEFAULT_FONT_URL(name);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return option;
|
|
175
|
+
}
|
package/lib/math/mdparser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import StateBlock from "markdown-it/lib/rules_block/state_block.mjs";
|
|
2
|
-
import StateInline from "markdown-it/lib/rules_inline/state_inline.mjs";
|
|
1
|
+
import type StateBlock from "markdown-it/lib/rules_block/state_block.mjs";
|
|
2
|
+
import type StateInline from "markdown-it/lib/rules_inline/state_inline.mjs";
|
|
3
3
|
export declare function math_inline(state: StateInline, silent: boolean): boolean;
|
|
4
4
|
export declare function math_block(state: StateBlock, start: number, end: number, silent: boolean): boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Primitive = string | number | boolean | symbol | BigInt | null | undefined;
|
|
2
|
+
export type DeepPartial<T> = {
|
|
3
|
+
[P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends object ? T[P] extends Function ? T[P] : DeepPartial<T[P]> : T[P];
|
|
4
|
+
};
|
|
5
|
+
type IsPlainObject<T> = T extends object ? T extends Function ? false : T extends any[] ? false : true : false;
|
|
6
|
+
type DeepMerged<T, U> = {
|
|
7
|
+
[K in keyof T | keyof U]: K extends keyof T ? K extends keyof U ? U[K] extends undefined ? T[K] : IsPlainObject<T[K]> extends true ? IsPlainObject<U[K]> extends true ? DeepMerged<T[K], U[K]> : U[K] : U[K] : T[K] : never;
|
|
8
|
+
};
|
|
9
|
+
export declare function isPrimitive(value: unknown): value is Primitive;
|
|
10
|
+
export declare function isFunction(value: unknown): value is Function;
|
|
11
|
+
export declare function merge<T, U>(target: Partial<T>, source?: Partial<U>): DeepMerged<T, U>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export function isPrimitive(value) {
|
|
2
|
+
return (value === null
|
|
3
|
+
|| typeof value === "string"
|
|
4
|
+
|| typeof value === "number"
|
|
5
|
+
|| typeof value === "boolean"
|
|
6
|
+
|| typeof value === "symbol"
|
|
7
|
+
|| typeof value === "bigint"
|
|
8
|
+
|| typeof value === "undefined");
|
|
9
|
+
}
|
|
10
|
+
export function isFunction(value) {
|
|
11
|
+
return typeof value === "function";
|
|
12
|
+
}
|
|
13
|
+
export function merge(target, source) {
|
|
14
|
+
const seen = new WeakMap();
|
|
15
|
+
function _merge(target, source) {
|
|
16
|
+
if (seen.has(source)) {
|
|
17
|
+
return seen.get(source);
|
|
18
|
+
}
|
|
19
|
+
else if (isPrimitive(source) || isFunction(source)) {
|
|
20
|
+
return source;
|
|
21
|
+
}
|
|
22
|
+
else if (Array.isArray(source)) {
|
|
23
|
+
const result = source.map(item => _merge(undefined, item));
|
|
24
|
+
seen.set(source, result);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
else if (typeof source === "object") {
|
|
28
|
+
const result = { ...target };
|
|
29
|
+
seen.set(source, result);
|
|
30
|
+
for (const key of Object.keys(source)) {
|
|
31
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const value = source[key];
|
|
35
|
+
const merged = _merge(result[key], value);
|
|
36
|
+
if (merged !== undefined) {
|
|
37
|
+
result[key] = merged;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const merged = _merge(target, source);
|
|
47
|
+
return merged === undefined
|
|
48
|
+
? target
|
|
49
|
+
: merged;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobapen/markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "A markdown converter for cobapen website",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown"
|
|
@@ -35,29 +35,28 @@
|
|
|
35
35
|
"lint:fix": "eslint src --fix"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
+
"@mathjax/mathjax-stix2-font": "^4.1.0",
|
|
39
|
+
"@mathjax/src": "^4.1.0",
|
|
38
40
|
"highlight.js": "^11.11.1",
|
|
39
|
-
"katex": "^0.16.
|
|
40
|
-
"lodash-es": "^4.17.21",
|
|
41
|
+
"katex": "^0.16.27",
|
|
41
42
|
"markdown-it": "^14.1.0",
|
|
42
|
-
"markdown-it-adv-table": "^0.1.
|
|
43
|
+
"markdown-it-adv-table": "^0.1.2",
|
|
43
44
|
"markdown-it-anchor": "^9.2.0",
|
|
44
|
-
"markdown-it-cjk-breaks": "
|
|
45
|
+
"markdown-it-cjk-breaks": "file:src/cjk-break",
|
|
45
46
|
"markdown-it-deflist": "^3.0.0",
|
|
46
47
|
"markdown-it-footnote": "^4.0.0",
|
|
47
|
-
"markdown-it-table-of-contents": "^
|
|
48
|
-
"mathjax-full": "^3.2.2"
|
|
48
|
+
"markdown-it-table-of-contents": "^1.1.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@cobapen/eslint-config": "^0.
|
|
52
|
-
"@types/katex": "^0.16.
|
|
53
|
-
"@types/lodash-es": "^4.17.12",
|
|
51
|
+
"@cobapen/eslint-config": "^0.5.0",
|
|
52
|
+
"@types/katex": "^0.16.8",
|
|
54
53
|
"@types/markdown-it": "^14.1.2",
|
|
55
|
-
"@types/mustache": "^4.2.
|
|
56
|
-
"@types/node": "^
|
|
57
|
-
"@vitest/coverage-v8": "^
|
|
58
|
-
"eslint": "^9.
|
|
54
|
+
"@types/mustache": "^4.2.6",
|
|
55
|
+
"@types/node": "^25.0.10",
|
|
56
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
57
|
+
"eslint": "^9.39.2",
|
|
59
58
|
"mustache": "^4.2.0",
|
|
60
|
-
"typescript": "^5.
|
|
61
|
-
"vitest": "^
|
|
59
|
+
"typescript": "^5.9.3",
|
|
60
|
+
"vitest": "^4.0.17"
|
|
62
61
|
}
|
|
63
62
|
}
|