@mdit/plugin-mathjax-slim 0.19.0 → 0.20.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 +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -246,7 +246,7 @@ interface DocumentOptions {
|
|
|
246
246
|
OutputJax: CHTML<LiteElement, string, HTMLElement> | SVG<LiteElement, string, HTMLElement>;
|
|
247
247
|
enableAssistiveMml: boolean;
|
|
248
248
|
}
|
|
249
|
-
declare const getDocumentOptions: (options: MarkdownItMathjaxOptions) => DocumentOptions
|
|
249
|
+
declare const getDocumentOptions: (options: MarkdownItMathjaxOptions) => DocumentOptions;
|
|
250
250
|
/**
|
|
251
251
|
* Mathjax instance
|
|
252
252
|
*/
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createRequire as j}from"node:module";import{tex as v}from"@mdit/plugin-tex";import y from"upath";const I=j(import.meta.url);let u=!0,c,f,
|
|
1
|
+
import{createRequire as j}from"node:module";import{tex as v}from"@mdit/plugin-tex";import y from"upath";const I=j(import.meta.url);let u=!0,c,h,f,p,w,d,x,S;try{({mathjax:c}=await import("mathjax-full/js/mathjax.js")),{AllPackages:h}=await import("mathjax-full/js/input/tex/AllPackages.js"),{TeX:f}=await import("mathjax-full/js/input/tex.js"),{CHTML:p}=await import("mathjax-full/js/output/chtml.js"),{SVG:w}=await import("mathjax-full/js/output/svg.js"),{liteAdaptor:d}=await import("mathjax-full/js/adaptors/liteAdaptor.js"),{RegisterHTMLHandler:x}=await import("mathjax-full/js/handlers/html.js"),{AssistiveMmlHandler:S}=await import("mathjax-full/js/a11y/assistive-mml.js")}catch{/* istanbul ignore next -- @preserve */u=!1}const M=t=>{/* istanbul ignore if -- @preserve */if(!u)throw new Error('[@mdit/mathjax] "mathjax-full" is not installed!');return{InputJax:new f({packages:h,...t.tex}),OutputJax:t.output==="chtml"?new p({fontURL:y.dirname(I.resolve("mathjax-full/es5/output/chtml/fonts/woff-v2/MathJax_Zero.woff")),adaptiveCSS:!0,...t.chtml}):new w({fontCache:"none",...t.svg}),enableAssistiveMml:t.a11y!==!1}},H=(t={})=>{const e=M(t),{OutputJax:a,InputJax:l}=e,r=d(),m=x(r);t.a11y!==!1&&S(m);const n=()=>{a instanceof p&&a.clearCache()},o=()=>{l.reset()},s=()=>{const i=r.innerHTML(a.styleSheet(c.document("",e)));return n(),i};return{adaptor:r,documentOptions:e,allowInlineWithSpace:t.allowInlineWithSpace??!1,mathFence:t.mathFence??!1,clearStyle:n,reset:o,outputStyle:s,transformer:t.transformer??null}},T=(t,{allowInlineWithSpace:e,adaptor:a,documentOptions:l,mathFence:r,transformer:m})=>{t.use(v,{allowInlineWithSpace:e,mathFence:r,render:(n,o)=>{const s=c.document(n,l).convert(n,{display:o}),i=a.outerHTML(s);return m?.(i,o)??i}})};export{H as createMathjaxInstance,M as getDocumentOptions,T 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 MarkdownIt 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 /* istanbul ignore next -- @preserve */\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
|
|
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 MarkdownIt 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 /* istanbul ignore next -- @preserve */\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 => {\n /* istanbul ignore if -- @preserve */\n if (!isMathJaxFullInstalled)\n throw new Error('[@mdit/mathjax] \"mathjax-full\" is not installed!');\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 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 = (\n md: MarkdownIt,\n {\n allowInlineWithSpace,\n adaptor,\n documentOptions,\n mathFence,\n transformer,\n }: MathjaxInstance,\n): void => {\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","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,aAAa,4BAA4B,GACnE,CAAE,YAAAC,CAAY,EAAI,KAAa,QAAA,0CAA0C,EACzE,CAAE,IAAAC,CAAI,EAAI,KAAa,QAAA,8BAA8B,EACrD,CAAE,MAAAC,CAAM,EAAI,KAAM,QAAO,iCAAiC,EAC1D,CAAE,IAAAC,CAAI,EAAI,KAAM,QAAO,+BAA+B,EACtD,CAAE,YAAAC,CAAY,EAAI,aAAa,yCAAyC,EACxE,CAAE,oBAAAC,CAAoB,EAAI,KAAa,QAAA,kCAAkC,EACzE,CAAE,oBAAAC,CAAoB,EAAI,KACzB,QAAA,uCACF,CACF,MAAQ,CAAA,uCAENR,EAAyB,EAC3B,OAUaS,EACXC,GACoB,CAEpB,qCAAA,GAAI,CAACV,EACH,MAAM,IAAI,MAAM,kDAAkD,EAEpE,MAAO,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,CACF,EA0CaE,EAAwB,CACnCF,EAAoC,CAAA,IACT,CAC3B,MAAMG,EAAkBJ,EAAmBC,CAAO,EAE5C,CAAE,UAAAI,EAAW,SAAAC,CAAS,EAAIF,EAE1BG,EAAUV,EAAAA,EACVW,EAAUV,EAAoBS,CAAO,EAEvCN,EAAQ,OAAS,IACnBF,EAAsDS,CAAO,EAE/D,MAAMC,EAAa,IAAY,CAEzBJ,aAAqBV,GAAOU,EAAU,WAAW,CACvD,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,IAEOG,CACT,EAEA,MAAO,CACL,QAAAL,EACA,gBAAAH,EACA,qBAAsBH,EAAQ,sBAAwB,GACtD,UAAWA,EAAQ,WAAa,GAChC,WAAAQ,EACA,MAAAC,EACA,YAAAC,EACA,YAAaV,EAAQ,aAAe,IACtC,CACF,EAEaY,EAAU,CACrBC,EACA,CACE,qBAAAC,EACA,QAAAR,EACA,gBAAAH,EACA,UAAAY,EACA,YAAAC,CACF,IACS,CACTH,EAAG,IAAII,EAAK,CACV,qBAAAH,EACA,UAAAC,EACA,OAAQ,CAACG,EAASC,IAAgB,CAChC,MAAMC,EAAe7B,EAClB,SAAS2B,EAASf,CAAe,EACjC,QAAQe,EAAS,CAChB,QAASC,CACX,CAAC,EAEGE,EAASf,EAAQ,UAAUc,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.20.0",
|
|
4
4
|
"description": "mathjax plugin for MarkdownIt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@types/markdown-it": "^14.1.2",
|
|
40
40
|
"upath": "^2.0.1",
|
|
41
|
-
"@mdit/plugin-tex": "0.
|
|
41
|
+
"@mdit/plugin-tex": "0.20.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"mathjax-full": "3.2.2"
|