@mdit/plugin-mathjax-slim 0.14.0 → 0.15.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 +2 -2
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { MmlNode } from 'mathjax-full/js/core/MmlTree/MmlNode.js';
|
|
|
2
2
|
import TexError from 'mathjax-full/js/input/tex/TexError.js';
|
|
3
3
|
import { TeX } from 'mathjax-full/js/input/tex.js';
|
|
4
4
|
import { MarkdownItTexOptions } from '@mdit/plugin-tex';
|
|
5
|
-
import
|
|
5
|
+
import MarkdownIt from 'markdown-it';
|
|
6
6
|
import { LiteElement } from 'mathjax-full/js/adaptors/lite/Element.js';
|
|
7
7
|
import { LiteAdaptor } from 'mathjax-full/js/adaptors/liteAdaptor.js';
|
|
8
8
|
import { CHTML } from 'mathjax-full/js/output/chtml.js';
|
|
@@ -279,6 +279,6 @@ interface MathjaxInstance extends Required<Pick<MarkdownItMathjaxOptions, "allow
|
|
|
279
279
|
transformer: TeXTransformer | null;
|
|
280
280
|
}
|
|
281
281
|
declare const createMathjaxInstance: (options?: MarkdownItMathjaxOptions) => MathjaxInstance | null;
|
|
282
|
-
declare const mathjax:
|
|
282
|
+
declare const mathjax: (md: MarkdownIt, { allowInlineWithSpace, adaptor, documentOptions, mathFence, transformer, }: MathjaxInstance) => void;
|
|
283
283
|
|
|
284
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 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,h,p,w,d,x,S;try{({mathjax:c}=await import("mathjax-full/js/mathjax.js")),{AllPackages:f}=await import("mathjax-full/js/input/tex/AllPackages.js"),{TeX:h}=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{u=!1}const M=t=>u?{InputJax:new h({packages:f,...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}:(console.error('[@mdit/mathjax] "mathjax-full" is not installed!'),null),H=(t={})=>{const e=M(t);if(!e)return null;const{OutputJax:a,InputJax:i}=e,n=d(),s=x(n);t.a11y!==!1&&S(s);const r=()=>{a instanceof p&&a.clearCache()},o=()=>{i.reset()},m=()=>{const l=n.innerHTML(a.styleSheet(c.document("",e)));return r(),l};return{adaptor:n,documentOptions:e,allowInlineWithSpace:t.allowInlineWithSpace??!1,mathFence:t.mathFence??!1,clearStyle:r,reset:o,outputStyle:m,transformer:t.transformer??null}},T=(t,{allowInlineWithSpace:e,adaptor:a,documentOptions:i,mathFence:n,transformer:s})=>{t.use(v,{allowInlineWithSpace:e,mathFence:n,render:(r,o)=>{const m=c.document(r,i).convert(r,{display:o}),l=a.outerHTML(m);return s?.(l,o)??l}})};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
|
|
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 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 = (\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,KAAM,QAAO,kCAAkC,EACzE,CAAE,oBAAAC,CAAoB,EAAI,KAAM,QAC/B,uCACF,CACF,MAAQ,CACNR,EAAyB,EAC3B,OAUaS,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,CACT,IAAA,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,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.15.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.15.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"mathjax-full": "3.2.2"
|