@mdit/plugin-mathjax-slim 0.10.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/LICENSE +22 -0
- package/README.md +18 -0
- package/lib/index.d.ts +283 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Waylon Flinn
|
|
4
|
+
Copyright (C) 2022 - PRESENT by MrHope
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @mdit/plugin-mathjax
|
|
2
|
+
|
|
3
|
+
[  ](https://www.npmjs.com/package/@mdit/plugin-mathjax)
|
|
4
|
+
|
|
5
|
+
mathjax plugin for MarkdownIt.
|
|
6
|
+
|
|
7
|
+
## [Docs](https://mdit-plugins.github.io/mathjax.html) | [文档](https://mdit-plugins.github.io/zh/mathjax.html)
|
|
8
|
+
|
|
9
|
+
## Install / 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# pnpm
|
|
13
|
+
pnpm add -D @mdit/plugin-mathjax
|
|
14
|
+
# npm
|
|
15
|
+
npm i -D @mdit/plugin-mathjax
|
|
16
|
+
# yarn
|
|
17
|
+
yarn add -D @mdit/plugin-mathjax
|
|
18
|
+
```
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { MmlNode } from 'mathjax-full/js/core/MmlTree/MmlNode.js';
|
|
2
|
+
import TexError from 'mathjax-full/js/input/tex/TexError.js';
|
|
3
|
+
import { TeX } from 'mathjax-full/js/input/tex.js';
|
|
4
|
+
import { MarkdownItTexOptions } from '@mdit/plugin-tex';
|
|
5
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
6
|
+
import { LiteElement } from 'mathjax-full/js/adaptors/lite/Element.js';
|
|
7
|
+
import { LiteAdaptor } from 'mathjax-full/js/adaptors/liteAdaptor.js';
|
|
8
|
+
import { CHTML } from 'mathjax-full/js/output/chtml.js';
|
|
9
|
+
import { SVG } from 'mathjax-full/js/output/svg.js';
|
|
10
|
+
|
|
11
|
+
interface MathJaxTexInputOptions {
|
|
12
|
+
/**
|
|
13
|
+
* extensions to use
|
|
14
|
+
*
|
|
15
|
+
* @default [
|
|
16
|
+
* 'base',
|
|
17
|
+
* 'action',
|
|
18
|
+
* 'ams',
|
|
19
|
+
* 'amscd',
|
|
20
|
+
* 'bbox',
|
|
21
|
+
* 'boldsymbol',
|
|
22
|
+
* 'braket',
|
|
23
|
+
* 'bussproofs',
|
|
24
|
+
* 'cancel',
|
|
25
|
+
* 'cases',
|
|
26
|
+
* 'centernot',
|
|
27
|
+
* 'color',
|
|
28
|
+
* 'colortbl',
|
|
29
|
+
* 'empheq',
|
|
30
|
+
* 'enclose',
|
|
31
|
+
* 'extpfeil',
|
|
32
|
+
* 'gensymb',
|
|
33
|
+
* 'html',
|
|
34
|
+
* 'mathtools',
|
|
35
|
+
* 'mhchem',
|
|
36
|
+
* 'newcommand',
|
|
37
|
+
* 'noerrors',
|
|
38
|
+
* 'noundefined',
|
|
39
|
+
* 'upgreek',
|
|
40
|
+
* 'unicode',
|
|
41
|
+
* 'verb',
|
|
42
|
+
* 'configmacros',
|
|
43
|
+
* 'tagformat',
|
|
44
|
+
* 'textcomp',
|
|
45
|
+
* 'textmacros'
|
|
46
|
+
* ]
|
|
47
|
+
*/
|
|
48
|
+
packages?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* pattern for recognizing numbers
|
|
51
|
+
*
|
|
52
|
+
* @default /^(?:[0-9]+(?:\{,\}[0-9]{3})*(?:\.[0-9]*)?|\.[0-9]+)/
|
|
53
|
+
*/
|
|
54
|
+
digits?: RegExp;
|
|
55
|
+
tags?: "ams" | "all" | "none";
|
|
56
|
+
/**
|
|
57
|
+
* side for `\tag` macros
|
|
58
|
+
*/
|
|
59
|
+
tagSide?: "left" | "right";
|
|
60
|
+
/**
|
|
61
|
+
* amount to indent tags
|
|
62
|
+
*
|
|
63
|
+
* @default "0.8em"
|
|
64
|
+
*/
|
|
65
|
+
tagIndent?: "0.8em";
|
|
66
|
+
/**
|
|
67
|
+
* use label name rather than tag for ids
|
|
68
|
+
*
|
|
69
|
+
* @default true;
|
|
70
|
+
*/
|
|
71
|
+
useLabelIds?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* maximum number of macro substitutions per expression
|
|
74
|
+
*
|
|
75
|
+
* @default 1000
|
|
76
|
+
*/
|
|
77
|
+
maxMacros?: number;
|
|
78
|
+
/**
|
|
79
|
+
* maximum size for the internal TeX string (in bytes)
|
|
80
|
+
*
|
|
81
|
+
* @default 5120
|
|
82
|
+
*/
|
|
83
|
+
maxBuffer?: number;
|
|
84
|
+
formatError?: (jax: TeX<unknown, unknown, unknown>, error: typeof TexError) => MmlNode;
|
|
85
|
+
}
|
|
86
|
+
interface MathjaxCommonOutputOptions {
|
|
87
|
+
/**
|
|
88
|
+
* Global scaling factor for all expressions
|
|
89
|
+
*
|
|
90
|
+
* @default 1
|
|
91
|
+
*/
|
|
92
|
+
scale?: number;
|
|
93
|
+
/**
|
|
94
|
+
* smallest scaling factor to use
|
|
95
|
+
*
|
|
96
|
+
* @default 0.5
|
|
97
|
+
*/
|
|
98
|
+
minScale?: number;
|
|
99
|
+
/**
|
|
100
|
+
* make mtext elements use surrounding font
|
|
101
|
+
*
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
mtextInheritFont?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* make merror text use surrounding font
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
merrorInheritFont?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* font to use for mtext, if not inheriting (empty means use MathJax fonts)
|
|
113
|
+
*
|
|
114
|
+
* @default ""
|
|
115
|
+
*/
|
|
116
|
+
mtextFont?: string;
|
|
117
|
+
/**
|
|
118
|
+
* font to use for merror, if not inheriting (empty means use MathJax fonts)
|
|
119
|
+
*
|
|
120
|
+
* @default "serif"
|
|
121
|
+
*/
|
|
122
|
+
merrorFont?: string;
|
|
123
|
+
/**
|
|
124
|
+
* font to use for character that aren’t in MathJax's fonts
|
|
125
|
+
*
|
|
126
|
+
* @default "serif"
|
|
127
|
+
*/
|
|
128
|
+
unknownFamily?: string;
|
|
129
|
+
/**
|
|
130
|
+
* @default "center"
|
|
131
|
+
*/
|
|
132
|
+
displayAlign?: "left" | "center" | "right";
|
|
133
|
+
/**
|
|
134
|
+
* @default 0
|
|
135
|
+
*/
|
|
136
|
+
displayIndent?: string;
|
|
137
|
+
/**
|
|
138
|
+
* - `true` for MathML spacing rules
|
|
139
|
+
* - `false` for TeX rules
|
|
140
|
+
*
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
mathmlSpacing?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* RFDa and other attributes NOT to copy to the output
|
|
146
|
+
*/
|
|
147
|
+
skipAttributes?: Record<string, boolean>;
|
|
148
|
+
/**
|
|
149
|
+
* default size of ex in em units
|
|
150
|
+
*
|
|
151
|
+
* @default 0.5
|
|
152
|
+
*/
|
|
153
|
+
exFactor?: number;
|
|
154
|
+
}
|
|
155
|
+
interface MathjaxCommonHTMLOutputOptions extends MathjaxCommonOutputOptions {
|
|
156
|
+
/**
|
|
157
|
+
* Whether match ex-height of surrounding font
|
|
158
|
+
*
|
|
159
|
+
* @default true
|
|
160
|
+
*/
|
|
161
|
+
matchFontHeight?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* The URL where the fonts are found
|
|
164
|
+
*
|
|
165
|
+
* @default local form mathjax-full
|
|
166
|
+
*/
|
|
167
|
+
fontURL?: string;
|
|
168
|
+
/**
|
|
169
|
+
* Whether only produce CSS that is used in the processed equations
|
|
170
|
+
*
|
|
171
|
+
* @default true
|
|
172
|
+
*/
|
|
173
|
+
adaptiveCSS?: boolean;
|
|
174
|
+
}
|
|
175
|
+
interface MathjaxSVGOutputOptions extends MathjaxCommonOutputOptions {
|
|
176
|
+
/**
|
|
177
|
+
* @default "none"
|
|
178
|
+
*/
|
|
179
|
+
fontCache?: "local" | "global" | "none";
|
|
180
|
+
/**
|
|
181
|
+
* ID to use for local font cache (for single equation processing)
|
|
182
|
+
*/
|
|
183
|
+
localID?: string | null;
|
|
184
|
+
/**
|
|
185
|
+
* insert <title> tags with speech content
|
|
186
|
+
*
|
|
187
|
+
* @default true
|
|
188
|
+
*/
|
|
189
|
+
internalSpeechTitles?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* initial id number to use for aria-labeledby titles
|
|
192
|
+
*/
|
|
193
|
+
titleID?: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInlineWithSpace" | "mathFence"> {
|
|
197
|
+
/**
|
|
198
|
+
* Output syntax
|
|
199
|
+
*
|
|
200
|
+
* 输出格式
|
|
201
|
+
*
|
|
202
|
+
* @default 'svg'
|
|
203
|
+
*/
|
|
204
|
+
output?: "chtml" | "svg";
|
|
205
|
+
/**
|
|
206
|
+
* Enable A11y
|
|
207
|
+
*
|
|
208
|
+
* 是否启用无障碍
|
|
209
|
+
*
|
|
210
|
+
* @default true
|
|
211
|
+
*/
|
|
212
|
+
a11y?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* TeX input options
|
|
215
|
+
*
|
|
216
|
+
* TeX 输入选项
|
|
217
|
+
*/
|
|
218
|
+
tex?: MathJaxTexInputOptions;
|
|
219
|
+
/**
|
|
220
|
+
* Common HTML output options
|
|
221
|
+
*
|
|
222
|
+
* 通用 HTML 输出选项
|
|
223
|
+
*/
|
|
224
|
+
chtml?: MathjaxCommonHTMLOutputOptions;
|
|
225
|
+
/**
|
|
226
|
+
* SVG output options
|
|
227
|
+
*
|
|
228
|
+
* SVG 输出选项
|
|
229
|
+
*/
|
|
230
|
+
svg?: MathjaxSVGOutputOptions;
|
|
231
|
+
/**
|
|
232
|
+
* @private This is an undocumented option, use at your own risk
|
|
233
|
+
*
|
|
234
|
+
* @default false
|
|
235
|
+
*/
|
|
236
|
+
vPre?: boolean;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Forked from https://github.com/tani/markdown-it-mathjax3/blob/master/index.ts
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
interface DocumentOptions {
|
|
244
|
+
InputJax: TeX<LiteElement, string, HTMLElement>;
|
|
245
|
+
OutputJax: CHTML<LiteElement, string, HTMLElement> | SVG<LiteElement, string, HTMLElement>;
|
|
246
|
+
enableAssistiveMml: boolean;
|
|
247
|
+
}
|
|
248
|
+
declare const getDocumentOptions: (options: MarkdownItMathjaxOptions) => DocumentOptions | null;
|
|
249
|
+
/**
|
|
250
|
+
* Mathjax instance
|
|
251
|
+
*/
|
|
252
|
+
interface MathjaxInstance extends Required<Pick<MarkdownItMathjaxOptions, "allowInlineWithSpace" | "mathFence">> {
|
|
253
|
+
/**
|
|
254
|
+
* Mathjax adaptor
|
|
255
|
+
*/
|
|
256
|
+
adaptor: LiteAdaptor;
|
|
257
|
+
/**
|
|
258
|
+
* Mathjax document options
|
|
259
|
+
*/
|
|
260
|
+
documentOptions: DocumentOptions;
|
|
261
|
+
/**
|
|
262
|
+
* Clear style cache
|
|
263
|
+
*/
|
|
264
|
+
clearStyle: () => void;
|
|
265
|
+
/**
|
|
266
|
+
* Output style for rendered content and clears it
|
|
267
|
+
*
|
|
268
|
+
* @returns style
|
|
269
|
+
*/
|
|
270
|
+
outputStyle: () => string;
|
|
271
|
+
/**
|
|
272
|
+
* Reset tex (including labels)
|
|
273
|
+
*/
|
|
274
|
+
reset: () => void;
|
|
275
|
+
/**
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
vPre: boolean;
|
|
279
|
+
}
|
|
280
|
+
declare const createMathjaxInstance: (options?: MarkdownItMathjaxOptions) => MathjaxInstance | null;
|
|
281
|
+
declare const mathjax: PluginWithOptions<MathjaxInstance>;
|
|
282
|
+
|
|
283
|
+
export { type DocumentOptions, type MarkdownItMathjaxOptions, type MathJaxTexInputOptions, type MathjaxCommonHTMLOutputOptions, type MathjaxCommonOutputOptions, type MathjaxInstance, type MathjaxSVGOutputOptions, createMathjaxInstance, getDocumentOptions, mathjax };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createRequire as M}from"node:module";import{tex as y}from"@mdit/plugin-tex";import I from"upath";const g=M(import.meta.url);let h=!0,p,w,x,s,d,f,v,S;try{({mathjax:p}=await import("mathjax-full/js/mathjax.js")),{AllPackages:w}=await import("mathjax-full/js/input/tex/AllPackages.js"),{TeX:x}=await import("mathjax-full/js/input/tex.js"),{CHTML:s}=await import("mathjax-full/js/output/chtml.js"),{SVG:d}=await import("mathjax-full/js/output/svg.js"),{liteAdaptor:f}=await import("mathjax-full/js/adaptors/liteAdaptor.js"),{RegisterHTMLHandler:v}=await import("mathjax-full/js/handlers/html.js"),{AssistiveMmlHandler:S}=await import("mathjax-full/js/a11y/assistive-mml.js")}catch{h=!1}const j=t=>h?{InputJax:new x({packages:w,...t.tex}),OutputJax:t.output==="chtml"?new s({fontURL:I.dirname(g.resolve("mathjax-full/es5/output/chtml/fonts/woff-v2/MathJax_Zero.woff")),adaptiveCSS:!0,...t.chtml}):new d({fontCache:"none",...t.svg}),enableAssistiveMml:t.a11y!==!1}:(console.error('[@mdit/mathjax] "mathjax-full" is not installed!'),null),H=(t={})=>{const e=j(t);if(!e)return null;const{OutputJax:a,InputJax:i}=e,n=f(),l=v(n);t.a11y!==!1&&S(l);const o=()=>{a instanceof s&&a.clearCache()},r=()=>{i.reset()},c=()=>{const m=n.innerHTML(a.styleSheet(p.document("",e)));return o(),m};return{adaptor:n,documentOptions:e,allowInlineWithSpace:t.allowInlineWithSpace??!1,mathFence:t.mathFence??!1,clearStyle:o,reset:r,outputStyle:c,vPre:t.vPre??!1}},J=(t,e)=>{const{allowInlineWithSpace:a,adaptor:i,documentOptions:n,mathFence:l,vPre:o}=e;t.use(y,{allowInlineWithSpace:a,mathFence:l,render:(r,c)=>{const m=p.document(r,n).convert(r,{display:c}),u=i.outerHTML(m);return o?u.replace(/^<mjx-container/,"<mjx-container v-pre"):u}})};export{H as createMathjaxInstance,j as getDocumentOptions,J as mathjax};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/plugin.ts"],"sourcesContent":["/**\n * Forked from https://github.com/tani/markdown-it-mathjax3/blob/master/index.ts\n */\n\n/* eslint-disable @typescript-eslint/consistent-type-imports */\nimport { createRequire } from \"node:module\";\n\nimport { tex } from \"@mdit/plugin-tex\";\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type { LiteDocument } from \"mathjax-full/js/adaptors/lite/Document.js\";\nimport type {\n LiteElement,\n LiteNode,\n} from \"mathjax-full/js/adaptors/lite/Element.js\";\nimport type { LiteText } from \"mathjax-full/js/adaptors/lite/Text.js\";\nimport type { LiteAdaptor } from \"mathjax-full/js/adaptors/liteAdaptor.js\";\nimport type { MathDocument } from \"mathjax-full/js/core/MathDocument.js\";\nimport type { TeX as TeXType } from \"mathjax-full/js/input/tex.js\";\nimport type { CHTML as CHTMLType } from \"mathjax-full/js/output/chtml.js\";\nimport type { SVG as SVGType } from \"mathjax-full/js/output/svg.js\";\nimport path from \"upath\";\n\nimport type { MarkdownItMathjaxOptions } from \"./options.js\";\n\nconst require = createRequire(import.meta.url);\n\nlet isMathJaxFullInstalled = true;\nlet mathjaxLib: typeof import(\"mathjax-full/js/mathjax.js\").mathjax;\nlet AllPackages: typeof import(\"mathjax-full/js/input/tex/AllPackages.js\").AllPackages;\nlet TeX: typeof import(\"mathjax-full/js/input/tex.js\").TeX;\nlet CHTML: typeof import(\"mathjax-full/js/output/chtml.js\").CHTML;\nlet SVG: typeof import(\"mathjax-full/js/output/svg.js\").SVG;\nlet liteAdaptor: typeof import(\"mathjax-full/js/adaptors/liteAdaptor.js\").liteAdaptor;\nlet RegisterHTMLHandler: typeof import(\"mathjax-full/js/handlers/html.js\").RegisterHTMLHandler;\nlet AssistiveMmlHandler: typeof import(\"mathjax-full/js/a11y/assistive-mml.js\").AssistiveMmlHandler;\n\ntry {\n ({ mathjax: mathjaxLib } = await import(\"mathjax-full/js/mathjax.js\"));\n ({ AllPackages } = await import(\"mathjax-full/js/input/tex/AllPackages.js\"));\n ({ TeX } = await import(\"mathjax-full/js/input/tex.js\"));\n ({ CHTML } = await import(\"mathjax-full/js/output/chtml.js\"));\n ({ SVG } = await import(\"mathjax-full/js/output/svg.js\"));\n ({ liteAdaptor } = await import(\"mathjax-full/js/adaptors/liteAdaptor.js\"));\n ({ RegisterHTMLHandler } = await import(\"mathjax-full/js/handlers/html.js\"));\n ({ AssistiveMmlHandler } = await import(\n \"mathjax-full/js/a11y/assistive-mml.js\"\n ));\n} catch (err) {\n isMathJaxFullInstalled = false;\n}\n\nexport interface DocumentOptions {\n InputJax: TeXType<LiteElement, string, HTMLElement>;\n OutputJax:\n | CHTMLType<LiteElement, string, HTMLElement>\n | SVGType<LiteElement, string, HTMLElement>;\n enableAssistiveMml: boolean;\n}\n\nexport const getDocumentOptions = (\n options: MarkdownItMathjaxOptions,\n): DocumentOptions | null => {\n if (!isMathJaxFullInstalled) {\n console.error('[@mdit/mathjax] \"mathjax-full\" is not installed!');\n\n return null;\n }\n\n return {\n InputJax: new TeX<LiteElement, string, HTMLElement>({\n packages: AllPackages,\n ...options.tex,\n }),\n OutputJax:\n options.output === \"chtml\"\n ? new CHTML<LiteElement, string, HTMLElement>({\n fontURL: path.dirname(\n require.resolve(\n \"mathjax-full/es5/output/chtml/fonts/woff-v2/MathJax_Zero.woff\",\n ),\n ),\n adaptiveCSS: true,\n ...options.chtml,\n })\n : new SVG<LiteElement, string, HTMLElement>({\n fontCache: \"none\",\n ...options.svg,\n }),\n enableAssistiveMml: options.a11y !== false,\n };\n};\n\n/**\n * Mathjax instance\n */\nexport interface MathjaxInstance\n extends Required<\n Pick<MarkdownItMathjaxOptions, \"allowInlineWithSpace\" | \"mathFence\">\n > {\n /**\n * Mathjax adaptor\n */\n adaptor: LiteAdaptor;\n\n /**\n * Mathjax document options\n */\n documentOptions: DocumentOptions;\n\n /**\n * Clear style cache\n */\n clearStyle: () => void;\n\n /**\n * Output style for rendered content and clears it\n *\n * @returns style\n */\n outputStyle: () => string;\n\n /**\n * Reset tex (including labels)\n */\n reset: () => void;\n\n /**\n * @private\n */\n vPre: boolean;\n}\n\nexport const createMathjaxInstance = (\n options: MarkdownItMathjaxOptions = {},\n): MathjaxInstance | null => {\n const documentOptions = getDocumentOptions(options);\n\n if (!documentOptions) return null;\n\n const { OutputJax, InputJax } = documentOptions;\n\n const adaptor = liteAdaptor();\n const handler = RegisterHTMLHandler(adaptor);\n\n if (options.a11y !== false)\n AssistiveMmlHandler<LiteNode, LiteText, LiteDocument>(handler);\n\n const clearStyle = (): void => {\n // clear style cache\n if (OutputJax instanceof CHTML) OutputJax.clearCache();\n };\n\n const reset = (): void => {\n InputJax.reset();\n };\n\n const outputStyle = (): string => {\n const style = adaptor.innerHTML(\n OutputJax.styleSheet(\n mathjaxLib.document(\"\", documentOptions) as MathDocument<\n LiteElement,\n string,\n HTMLElement\n >,\n ),\n );\n\n clearStyle();\n\n return style;\n };\n\n return {\n adaptor,\n documentOptions,\n allowInlineWithSpace: options.allowInlineWithSpace ?? false,\n mathFence: options.mathFence ?? false,\n clearStyle,\n reset,\n outputStyle,\n vPre: options.vPre ?? false,\n };\n};\n\nexport const mathjax: PluginWithOptions<MathjaxInstance> = (md, instance) => {\n const { allowInlineWithSpace, adaptor, documentOptions, mathFence, vPre } =\n instance!;\n\n md.use(tex, {\n allowInlineWithSpace,\n mathFence,\n render: (content, displayMode) => {\n const mathDocument = mathjaxLib\n .document(content, documentOptions)\n .convert(content, {\n display: displayMode,\n }) as LiteElement;\n\n const result = adaptor.outerHTML(mathDocument);\n\n return vPre\n ? result.replace(/^<mjx-container/, \"<mjx-container v-pre\")\n : result;\n },\n });\n};\n"],"names":["require","createRequire","isMathJaxFullInstalled","mathjaxLib","AllPackages","TeX","CHTML","SVG","liteAdaptor","RegisterHTMLHandler","AssistiveMmlHandler","getDocumentOptions","options","path","createMathjaxInstance","documentOptions","OutputJax","InputJax","adaptor","handler","clearStyle","reset","outputStyle","style","mathjax","md","instance","allowInlineWithSpace","mathFence","vPre","tex","content","displayMode","mathDocument","result"],"mappings":"wGAwBA,MAAMA,EAAUC,EAAc,YAAY,GAAG,EAE7C,IAAIC,EAAyB,GACzBC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAI,EACD,CAAE,QAASP,CAAW,EAAI,KAAM,QAAO,4BAA4B,GACnE,CAAE,YAAAC,CAAY,EAAI,KAAM,QAAO,0CAA0C,EACzE,CAAE,IAAAC,CAAI,EAAI,aAAa,8BAA8B,EACrD,CAAE,MAAAC,CAAM,EAAI,KAAa,QAAA,iCAAiC,EAC1D,CAAE,IAAAC,CAAI,EAAI,KAAa,QAAA,+BAA+B,EACtD,CAAE,YAAAC,CAAY,EAAI,KAAM,QAAO,yCAAyC,EACxE,CAAE,oBAAAC,CAAoB,EAAI,KAAM,QAAO,kCAAkC,EACzE,CAAE,oBAAAC,CAAoB,EAAI,aACzB,uCACF,CACF,MAAc,CACZR,EAAyB,EAC3B,CAUa,MAAAS,EACXC,GAEKV,EAME,CACL,SAAU,IAAIG,EAAsC,CAClD,SAAUD,EACV,GAAGQ,EAAQ,GACb,CAAC,EACD,UACEA,EAAQ,SAAW,QACf,IAAIN,EAAwC,CAC1C,QAASO,EAAK,QACZb,EAAQ,QACN,+DACF,CACF,EACA,YAAa,GACb,GAAGY,EAAQ,KACb,CAAC,EACD,IAAIL,EAAsC,CACxC,UAAW,OACX,GAAGK,EAAQ,GACb,CAAC,EACP,mBAAoBA,EAAQ,OAAS,EACvC,GA1BE,QAAQ,MAAM,kDAAkD,EAEzD,MAmEEE,EAAwB,CACnCF,EAAoC,CAAC,IACV,CAC3B,MAAMG,EAAkBJ,EAAmBC,CAAO,EAElD,GAAI,CAACG,EAAiB,OAAO,KAE7B,KAAM,CAAE,UAAAC,EAAW,SAAAC,CAAS,EAAIF,EAE1BG,EAAUV,IACVW,EAAUV,EAAoBS,CAAO,EAEvCN,EAAQ,OAAS,IACnBF,EAAsDS,CAAO,EAE/D,MAAMC,EAAa,IAAY,CAEzBJ,aAAqBV,GAAOU,EAAU,WAC5C,CAAA,EAEMK,EAAQ,IAAY,CACxBJ,EAAS,MACX,CAAA,EAEMK,EAAc,IAAc,CAChC,MAAMC,EAAQL,EAAQ,UACpBF,EAAU,WACRb,EAAW,SAAS,GAAIY,CAAe,CAKzC,CACF,EAEA,OAAAK,EAAW,EAEJG,CACT,EAEA,MAAO,CACL,QAAAL,EACA,gBAAAH,EACA,qBAAsBH,EAAQ,sBAAwB,GACtD,UAAWA,EAAQ,WAAa,GAChC,WAAAQ,EACA,MAAAC,EACA,YAAAC,EACA,KAAMV,EAAQ,MAAQ,EACxB,CACF,EAEaY,EAA8C,CAACC,EAAIC,IAAa,CAC3E,KAAM,CAAE,qBAAAC,EAAsB,QAAAT,EAAS,gBAAAH,EAAiB,UAAAa,EAAW,KAAAC,CAAK,EACtEH,EAEFD,EAAG,IAAIK,EAAK,CACV,qBAAAH,EACA,UAAAC,EACA,OAAQ,CAACG,EAASC,IAAgB,CAChC,MAAMC,EAAe9B,EAClB,SAAS4B,EAAShB,CAAe,EACjC,QAAQgB,EAAS,CAChB,QAASC,CACX,CAAC,EAEGE,EAAShB,EAAQ,UAAUe,CAAY,EAE7C,OAAOJ,EACHK,EAAO,QAAQ,kBAAmB,sBAAsB,EACxDA,CACN,CACF,CAAC,CACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdit/plugin-mathjax-slim",
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "mathjax plugin for MarkdownIt",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdown-it",
|
|
7
|
+
"markdown-it-plugin",
|
|
8
|
+
"mathjax"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://mdit-plugins.github.io/mathjax.html",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://mdit-plugins/mdit-plugins/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/mdit-plugins/mdit-plugins.git",
|
|
17
|
+
"directory": "packages/mathjax"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "Mr.Hope",
|
|
22
|
+
"email": "mister-hope@outlook.com",
|
|
23
|
+
"url": "https://mister-hope.com"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"type": "./lib/index.ts",
|
|
29
|
+
"default": "./lib/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"main": "lib/index.js",
|
|
34
|
+
"types": "lib/index.d.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"lib"
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@types/markdown-it": "^14.0.1",
|
|
40
|
+
"upath": "^2.0.1",
|
|
41
|
+
"@mdit/plugin-tex": "0.10.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"mathjax-full": "3.2.2"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"markdown-it": "^14.1.0",
|
|
48
|
+
"mathjax-full": "^3.2.2"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"markdown-it": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"mathjax-full": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">= 18"
|
|
60
|
+
},
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"access": "public"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "rollup -c rollup.config.ts --configPlugin esbuild",
|
|
66
|
+
"clean": "rimraf ./lib"
|
|
67
|
+
}
|
|
68
|
+
}
|