@mdit/plugin-mathjax-slim 0.11.0 → 0.13.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/lib/index.d.ts +7 -6
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
|
@@ -193,6 +193,7 @@ interface MathjaxSVGOutputOptions extends MathjaxCommonOutputOptions {
|
|
|
193
193
|
titleID?: number;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
+
type TeXTransformer = (content: string, displayMode: boolean) => string;
|
|
196
197
|
interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInlineWithSpace" | "mathFence"> {
|
|
197
198
|
/**
|
|
198
199
|
* Output syntax
|
|
@@ -229,11 +230,11 @@ interface MarkdownItMathjaxOptions extends Pick<MarkdownItTexOptions, "allowInli
|
|
|
229
230
|
*/
|
|
230
231
|
svg?: MathjaxSVGOutputOptions;
|
|
231
232
|
/**
|
|
232
|
-
*
|
|
233
|
+
* transformer on output content
|
|
233
234
|
*
|
|
234
|
-
*
|
|
235
|
+
* 输出内容的转换器
|
|
235
236
|
*/
|
|
236
|
-
|
|
237
|
+
transformer?: TeXTransformer;
|
|
237
238
|
}
|
|
238
239
|
|
|
239
240
|
/**
|
|
@@ -273,11 +274,11 @@ interface MathjaxInstance extends Required<Pick<MarkdownItMathjaxOptions, "allow
|
|
|
273
274
|
*/
|
|
274
275
|
reset: () => void;
|
|
275
276
|
/**
|
|
276
|
-
*
|
|
277
|
+
* Output content transformer
|
|
277
278
|
*/
|
|
278
|
-
|
|
279
|
+
transformer: TeXTransformer | null;
|
|
279
280
|
}
|
|
280
281
|
declare const createMathjaxInstance: (options?: MarkdownItMathjaxOptions) => MathjaxInstance | null;
|
|
281
282
|
declare const mathjax: PluginWithOptions<MathjaxInstance>;
|
|
282
283
|
|
|
283
|
-
export { type DocumentOptions, type MarkdownItMathjaxOptions, type MathJaxTexInputOptions, type MathjaxCommonHTMLOutputOptions, type MathjaxCommonOutputOptions, type MathjaxInstance, type MathjaxSVGOutputOptions, createMathjaxInstance, getDocumentOptions, mathjax };
|
|
284
|
+
export { type DocumentOptions, type MarkdownItMathjaxOptions, type MathJaxTexInputOptions, type MathjaxCommonHTMLOutputOptions, type MathjaxCommonOutputOptions, type MathjaxInstance, type MathjaxSVGOutputOptions, type TeXTransformer, createMathjaxInstance, getDocumentOptions, mathjax };
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createRequire as
|
|
1
|
+
import{createRequire as v}from"node:module";import{tex as y}from"@mdit/plugin-tex";import I from"upath";const g=v(import.meta.url);let h=!0,s,f,w,p,d,x,S,M;try{({mathjax:s}=await import("mathjax-full/js/mathjax.js")),{AllPackages:f}=await import("mathjax-full/js/input/tex/AllPackages.js"),{TeX:w}=await import("mathjax-full/js/input/tex.js"),{CHTML:p}=await import("mathjax-full/js/output/chtml.js"),{SVG:d}=await import("mathjax-full/js/output/svg.js"),{liteAdaptor:x}=await import("mathjax-full/js/adaptors/liteAdaptor.js"),{RegisterHTMLHandler:S}=await import("mathjax-full/js/handlers/html.js"),{AssistiveMmlHandler:M}=await import("mathjax-full/js/a11y/assistive-mml.js")}catch{h=!1}const j=t=>h?{InputJax:new w({packages:f,...t.tex}),OutputJax:t.output==="chtml"?new p({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:l}=e,n=x(),m=S(n);t.a11y!==!1&&M(m);const o=()=>{a instanceof p&&a.clearCache()},r=()=>{l.reset()},i=()=>{const c=n.innerHTML(a.styleSheet(s.document("",e)));return o(),c};return{adaptor:n,documentOptions:e,allowInlineWithSpace:t.allowInlineWithSpace??!1,mathFence:t.mathFence??!1,clearStyle:o,reset:r,outputStyle:i,transformer:t.transformer??null}},L=(t,e)=>{const{allowInlineWithSpace:a,adaptor:l,documentOptions:n,mathFence:m,transformer:o}=e;t.use(y,{allowInlineWithSpace:a,mathFence:m,render:(r,i)=>{const c=s.document(r,n).convert(r,{display:i}),u=l.outerHTML(c);return o?.(u,i)??u}})};export{H as createMathjaxInstance,j as getDocumentOptions,L as mathjax};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +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
|
|
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, TeXTransformer } 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 {\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 * Output content transformer\n */\n transformer: TeXTransformer | null;\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 transformer: options.transformer ?? null,\n };\n};\n\nexport const mathjax: PluginWithOptions<MathjaxInstance> = (md, instance) => {\n const {\n allowInlineWithSpace,\n adaptor,\n documentOptions,\n mathFence,\n transformer,\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 transformer?.(result, displayMode) ?? 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","transformer","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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,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,IAAcK,EAAQF,CAAW,GAAKE,CAC/C,CACF,CAAC,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit/plugin-mathjax-slim",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "mathjax plugin for MarkdownIt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"lib"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@types/markdown-it": "^14.1.
|
|
39
|
+
"@types/markdown-it": "^14.1.2",
|
|
40
40
|
"upath": "^2.0.1",
|
|
41
|
-
"@mdit/plugin-tex": "0.
|
|
41
|
+
"@mdit/plugin-tex": "0.13.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"mathjax-full": "3.2.2"
|