@mdit/plugin-katex 0.4.8 → 0.5.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.cjs +3 -3
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1 -1
- package/lib/index.d.mts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.mjs.map +1 -1
- package/package.json +18 -8
package/lib/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`}catch(t){return r.throwOnError&&console.warn(t),`<p class='katex-block katex-error' title='${
|
|
3
|
-
`}},q=(e,r={})=>{const{mathFence:t=!1,mhchem:i=!1,logger:
|
|
1
|
+
"use strict";var x=require("node:module"),k=require("@mdit/plugin-tex"),a=require("katex"),u=typeof document<"u"?document.currentScript:null;const o=e=>e.replace(/&/gu,"&").replace(/</gu,"<").replace(/>/gu,">").replace(/"/gu,""").replace(/'/gu,"'"),f=x.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:u&&u.src||new URL("index.cjs",document.baseURI).href),w=(e,r)=>{try{return a.renderToString(e,{...r,displayMode:!1})}catch(t){return r.throwOnError&&console.warn(t),`<span class='katex-error' title='${o(t.toString())}'>${o(e)}</span>`}},y=(e,r)=>{try{return`<p class='katex-block'>${a.renderToString(e,{...r,displayMode:!0})}</p>
|
|
2
|
+
`}catch(t){return r.throwOnError&&console.warn(t),`<p class='katex-block katex-error' title='${o(t.toString())}'>${o(e)}</p>
|
|
3
|
+
`}},q=(e,r={})=>{const{mathFence:t=!1,mhchem:i=!1,logger:l=n=>n==="newLineInDisplayMode"?"ignore":"warn",...s}=r;i&&f("katex/contrib/mhchem"),e.use(k.tex,{mathFence:t,render:(n,p,d)=>{const c={strict:(g,m,h)=>l(g,m,h,d)??"ignore",throwOnError:!1,...s};return p?y(n,c):w(n,c)}})};exports.katex=q;
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|
package/lib/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/plugin.ts"],"sourcesContent":["export const escapeHtml = (unsafeHTML: string): string =>\n unsafeHTML\n .replace(/&/gu, \"&\")\n .replace(/</gu, \"<\")\n .replace(/>/gu, \">\")\n .replace(/\"/gu, \""\")\n .replace(/'/gu, \"'\");\n","import { createRequire } from \"node:module\";\n\nimport { tex } from \"@mdit/plugin-tex\";\nimport Katex, { type KatexOptions as OriginalKatexOptions } from \"katex\";\nimport type MarkdownIt from \"markdown-it\";\n\nimport { type KatexToken, type MarkdownItKatexOptions } from \"./options.js\";\nimport { escapeHtml } from \"./utils.js\";\n\nconst require = createRequire(import.meta.url);\n\nconst katexInline = (tex: string, options: OriginalKatexOptions): string => {\n try {\n return Katex.renderToString(tex, { ...options, displayMode: false });\n } catch (error) {\n if (options.throwOnError) console.warn(error);\n\n return `<span class='katex-error' title='${escapeHtml(\n (error as Error).toString()
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/plugin.ts"],"sourcesContent":["export const escapeHtml = (unsafeHTML: string): string =>\n unsafeHTML\n .replace(/&/gu, \"&\")\n .replace(/</gu, \"<\")\n .replace(/>/gu, \">\")\n .replace(/\"/gu, \""\")\n .replace(/'/gu, \"'\");\n","import { createRequire } from \"node:module\";\n\nimport { tex } from \"@mdit/plugin-tex\";\nimport Katex, { type KatexOptions as OriginalKatexOptions } from \"katex\";\nimport type MarkdownIt from \"markdown-it\";\n\nimport { type KatexToken, type MarkdownItKatexOptions } from \"./options.js\";\nimport { escapeHtml } from \"./utils.js\";\n\nconst require = createRequire(import.meta.url);\n\nconst katexInline = (tex: string, options: OriginalKatexOptions): string => {\n try {\n return Katex.renderToString(tex, { ...options, displayMode: false });\n } catch (error) {\n if (options.throwOnError) console.warn(error);\n\n return `<span class='katex-error' title='${escapeHtml(\n (error as Error).toString(),\n )}'>${escapeHtml(tex)}</span>`;\n }\n};\n\nconst katexBlock = (tex: string, options: OriginalKatexOptions): string => {\n try {\n return `<p class='katex-block'>${Katex.renderToString(tex, {\n ...options,\n displayMode: true,\n })}</p>\\n`;\n } catch (error) {\n if (options.throwOnError) console.warn(error);\n\n return `<p class='katex-block katex-error' title='${escapeHtml(\n (error as Error).toString(),\n )}'>${escapeHtml(tex)}</p>\\n`;\n }\n};\n\nexport const katex = <MarkdownItEnv = unknown>(\n md: MarkdownIt,\n options: MarkdownItKatexOptions<MarkdownItEnv> = {},\n): void => {\n const {\n mathFence = false,\n mhchem = false,\n logger = (errorCode: string): string =>\n errorCode === \"newLineInDisplayMode\" ? \"ignore\" : \"warn\",\n ...userOptions\n } = options;\n\n if (mhchem) require(\"katex/contrib/mhchem\");\n\n md.use(tex, {\n mathFence,\n render: (content: string, displayMode: boolean, env: MarkdownItEnv) => {\n const katexOptions = {\n strict: (\n errorCode:\n | \"unknownSymbol\"\n | \"unicodeTextInMathMode\"\n | \"mathVsTextUnits\"\n | \"commentAtEnd\"\n | \"htmlExtension\"\n | \"newLineInDisplayMode\",\n errorMsg: string,\n token: KatexToken,\n ): string => logger(errorCode, errorMsg, token, env) ?? \"ignore\",\n throwOnError: false,\n ...userOptions,\n };\n\n return displayMode\n ? katexBlock(content, katexOptions)\n : katexInline(content, katexOptions);\n },\n });\n};\n"],"names":["escapeHtml","unsafeHTML","require","createRequire","katexInline","tex","options","Katex","error","katexBlock","katex","md","mathFence","mhchem","logger","errorCode","userOptions","content","displayMode","env","katexOptions","errorMsg","token"],"mappings":"6IAAa,MAAAA,EAAcC,GACzBA,EACG,QAAQ,MAAO,OAAO,EACtB,QAAQ,MAAO,MAAM,EACrB,QAAQ,MAAO,MAAM,EACrB,QAAQ,MAAO,QAAQ,EACvB,QAAQ,MAAO,QAAQ,ECGtBC,EAAUC,EAAc,oIAAe,EAEvCC,EAAc,CAACC,EAAaC,IAA0C,CAC1E,GAAI,CACF,OAAOC,EAAM,eAAeF,EAAK,CAAE,GAAGC,EAAS,YAAa,EAAM,CAAC,CACrE,OAASE,EAAO,CACd,OAAIF,EAAQ,cAAc,QAAQ,KAAKE,CAAK,EAErC,oCAAoCR,EACxCQ,EAAgB,SACnB,CAAA,CAAC,KAAKR,EAAWK,CAAG,CAAC,SACvB,CACF,EAEMI,EAAa,CAACJ,EAAaC,IAA0C,CACzE,GAAI,CACF,MAAO,0BAA0BC,EAAM,eAAeF,EAAK,CACzD,GAAGC,EACH,YAAa,EACf,CAAC,CAAC;AAAA,CACJ,OAASE,EAAO,CACd,OAAIF,EAAQ,cAAc,QAAQ,KAAKE,CAAK,EAErC,6CAA6CR,EACjDQ,EAAgB,SAAS,CAC5B,CAAC,KAAKR,EAAWK,CAAG,CAAC;AAAA,CACvB,CACF,EAEaK,EAAQ,CACnBC,EACAL,EAAiD,CAAA,IACxC,CACT,KAAM,CACJ,UAAAM,EAAY,GACZ,OAAAC,EAAS,GACT,OAAAC,EAAUC,GACRA,IAAc,uBAAyB,SAAW,OACpD,GAAGC,CACL,EAAIV,EAEAO,GAAQX,EAAQ,sBAAsB,EAE1CS,EAAG,IAAIN,EAAAA,IAAK,CACV,UAAAO,EACA,OAAQ,CAACK,EAAiBC,EAAsBC,IAAuB,CACrE,MAAMC,EAAe,CACnB,OAAQ,CACNL,EAOAM,EACAC,IACWR,EAAOC,EAAWM,EAAUC,EAAOH,CAAG,GAAK,SACxD,aAAc,GACd,GAAGH,CACL,EAEA,OAAOE,EACHT,EAAWQ,EAASG,CAAY,EAChChB,EAAYa,EAASG,CAAY,CACvC,CACF,CAAC,CACH"}
|
package/lib/index.d.cts
CHANGED
|
@@ -49,4 +49,4 @@ interface MarkdownItKatexOptions<MarkdownItEnv = unknown> extends KatexOptions {
|
|
|
49
49
|
|
|
50
50
|
declare const katex: <MarkdownItEnv = unknown>(md: MarkdownIt, options?: MarkdownItKatexOptions<MarkdownItEnv>) => void;
|
|
51
51
|
|
|
52
|
-
export { KatexLogger, KatexToken, MarkdownItKatexOptions, katex };
|
|
52
|
+
export { type KatexLogger, type KatexToken, type MarkdownItKatexOptions, katex };
|
package/lib/index.d.mts
CHANGED
|
@@ -49,4 +49,4 @@ interface MarkdownItKatexOptions<MarkdownItEnv = unknown> extends KatexOptions {
|
|
|
49
49
|
|
|
50
50
|
declare const katex: <MarkdownItEnv = unknown>(md: MarkdownIt, options?: MarkdownItKatexOptions<MarkdownItEnv>) => void;
|
|
51
51
|
|
|
52
|
-
export { KatexLogger, KatexToken, MarkdownItKatexOptions, katex };
|
|
52
|
+
export { type KatexLogger, type KatexToken, type MarkdownItKatexOptions, katex };
|
package/lib/index.d.ts
CHANGED
|
@@ -49,4 +49,4 @@ interface MarkdownItKatexOptions<MarkdownItEnv = unknown> extends KatexOptions {
|
|
|
49
49
|
|
|
50
50
|
declare const katex: <MarkdownItEnv = unknown>(md: MarkdownIt, options?: MarkdownItKatexOptions<MarkdownItEnv>) => void;
|
|
51
51
|
|
|
52
|
-
export { KatexLogger, KatexToken, MarkdownItKatexOptions, katex };
|
|
52
|
+
export { type KatexLogger, type KatexToken, type MarkdownItKatexOptions, katex };
|
package/lib/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/utils.ts","../src/plugin.ts"],"sourcesContent":["export const escapeHtml = (unsafeHTML: string): string =>\n unsafeHTML\n .replace(/&/gu, \"&\")\n .replace(/</gu, \"<\")\n .replace(/>/gu, \">\")\n .replace(/\"/gu, \""\")\n .replace(/'/gu, \"'\");\n","import { createRequire } from \"node:module\";\n\nimport { tex } from \"@mdit/plugin-tex\";\nimport Katex, { type KatexOptions as OriginalKatexOptions } from \"katex\";\nimport type MarkdownIt from \"markdown-it\";\n\nimport { type KatexToken, type MarkdownItKatexOptions } from \"./options.js\";\nimport { escapeHtml } from \"./utils.js\";\n\nconst require = createRequire(import.meta.url);\n\nconst katexInline = (tex: string, options: OriginalKatexOptions): string => {\n try {\n return Katex.renderToString(tex, { ...options, displayMode: false });\n } catch (error) {\n if (options.throwOnError) console.warn(error);\n\n return `<span class='katex-error' title='${escapeHtml(\n (error as Error).toString()
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/utils.ts","../src/plugin.ts"],"sourcesContent":["export const escapeHtml = (unsafeHTML: string): string =>\n unsafeHTML\n .replace(/&/gu, \"&\")\n .replace(/</gu, \"<\")\n .replace(/>/gu, \">\")\n .replace(/\"/gu, \""\")\n .replace(/'/gu, \"'\");\n","import { createRequire } from \"node:module\";\n\nimport { tex } from \"@mdit/plugin-tex\";\nimport Katex, { type KatexOptions as OriginalKatexOptions } from \"katex\";\nimport type MarkdownIt from \"markdown-it\";\n\nimport { type KatexToken, type MarkdownItKatexOptions } from \"./options.js\";\nimport { escapeHtml } from \"./utils.js\";\n\nconst require = createRequire(import.meta.url);\n\nconst katexInline = (tex: string, options: OriginalKatexOptions): string => {\n try {\n return Katex.renderToString(tex, { ...options, displayMode: false });\n } catch (error) {\n if (options.throwOnError) console.warn(error);\n\n return `<span class='katex-error' title='${escapeHtml(\n (error as Error).toString(),\n )}'>${escapeHtml(tex)}</span>`;\n }\n};\n\nconst katexBlock = (tex: string, options: OriginalKatexOptions): string => {\n try {\n return `<p class='katex-block'>${Katex.renderToString(tex, {\n ...options,\n displayMode: true,\n })}</p>\\n`;\n } catch (error) {\n if (options.throwOnError) console.warn(error);\n\n return `<p class='katex-block katex-error' title='${escapeHtml(\n (error as Error).toString(),\n )}'>${escapeHtml(tex)}</p>\\n`;\n }\n};\n\nexport const katex = <MarkdownItEnv = unknown>(\n md: MarkdownIt,\n options: MarkdownItKatexOptions<MarkdownItEnv> = {},\n): void => {\n const {\n mathFence = false,\n mhchem = false,\n logger = (errorCode: string): string =>\n errorCode === \"newLineInDisplayMode\" ? \"ignore\" : \"warn\",\n ...userOptions\n } = options;\n\n if (mhchem) require(\"katex/contrib/mhchem\");\n\n md.use(tex, {\n mathFence,\n render: (content: string, displayMode: boolean, env: MarkdownItEnv) => {\n const katexOptions = {\n strict: (\n errorCode:\n | \"unknownSymbol\"\n | \"unicodeTextInMathMode\"\n | \"mathVsTextUnits\"\n | \"commentAtEnd\"\n | \"htmlExtension\"\n | \"newLineInDisplayMode\",\n errorMsg: string,\n token: KatexToken,\n ): string => logger(errorCode, errorMsg, token, env) ?? \"ignore\",\n throwOnError: false,\n ...userOptions,\n };\n\n return displayMode\n ? katexBlock(content, katexOptions)\n : katexInline(content, katexOptions);\n },\n });\n};\n"],"names":["escapeHtml","unsafeHTML","require","createRequire","katexInline","tex","options","Katex","error","katexBlock","katex","md","mathFence","mhchem","logger","errorCode","userOptions","content","displayMode","env","katexOptions","errorMsg","token"],"mappings":"wGAAa,MAAAA,EAAcC,GACzBA,EACG,QAAQ,MAAO,OAAO,EACtB,QAAQ,MAAO,MAAM,EACrB,QAAQ,MAAO,MAAM,EACrB,QAAQ,MAAO,QAAQ,EACvB,QAAQ,MAAO,QAAQ,ECGtBC,EAAUC,EAAc,YAAY,GAAG,EAEvCC,EAAc,CAACC,EAAaC,IAA0C,CAC1E,GAAI,CACF,OAAOC,EAAM,eAAeF,EAAK,CAAE,GAAGC,EAAS,YAAa,EAAM,CAAC,CACrE,OAASE,EAAO,CACd,OAAIF,EAAQ,cAAc,QAAQ,KAAKE,CAAK,EAErC,oCAAoCR,EACxCQ,EAAgB,UACnB,CAAC,KAAKR,EAAWK,CAAG,CAAC,SACvB,CACF,EAEMI,EAAa,CAACJ,EAAaC,IAA0C,CACzE,GAAI,CACF,MAAO,0BAA0BC,EAAM,eAAeF,EAAK,CACzD,GAAGC,EACH,YAAa,EACf,CAAC,CAAC;AAAA,CACJ,OAASE,EAAO,CACd,OAAIF,EAAQ,cAAc,QAAQ,KAAKE,CAAK,EAErC,6CAA6CR,EACjDQ,EAAgB,SAAS,CAC5B,CAAC,KAAKR,EAAWK,CAAG,CAAC;AAAA,CACvB,CACF,EAEaK,EAAQ,CACnBC,EACAL,EAAiD,CAAA,IACxC,CACT,KAAM,CACJ,UAAAM,EAAY,GACZ,OAAAC,EAAS,GACT,OAAAC,EAAUC,GACRA,IAAc,uBAAyB,SAAW,OACpD,GAAGC,CACL,EAAIV,EAEAO,GAAQX,EAAQ,sBAAsB,EAE1CS,EAAG,IAAIN,EAAK,CACV,UAAAO,EACA,OAAQ,CAACK,EAAiBC,EAAsBC,IAAuB,CACrE,MAAMC,EAAe,CACnB,OAAQ,CACNL,EAOAM,EACAC,IACWR,EAAOC,EAAWM,EAAUC,EAAOH,CAAG,GAAK,SACxD,aAAc,GACd,GAAGH,CACL,EAEA,OAAOE,EACHT,EAAWQ,EAASG,CAAY,EAChChB,EAAYa,EAASG,CAAY,CACvC,CACF,CAAC,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdit/plugin-katex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "katex plugin for MarkdownIt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdownit",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "Mr.Hope",
|
|
23
23
|
"email": "mister-hope@outlook.com",
|
|
24
|
-
"url": "https://
|
|
24
|
+
"url": "https://mister-hope.com"
|
|
25
25
|
},
|
|
26
26
|
"main": "lib/index.cjs",
|
|
27
27
|
"types": "lib/index.d.ts",
|
|
@@ -38,14 +38,24 @@
|
|
|
38
38
|
"lib"
|
|
39
39
|
],
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">= 18"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@types/katex": "^0.16.
|
|
45
|
-
"@types/markdown-it": "^
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
"@types/katex": "^0.16.3",
|
|
45
|
+
"@types/markdown-it": "^13.0.2",
|
|
46
|
+
"@mdit/plugin-tex": "0.5.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"markdown-it": "^13.0.2",
|
|
50
|
+
"katex": "^0.16.9"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"markdown-it": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"katex": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
49
59
|
},
|
|
50
60
|
"publishConfig": {
|
|
51
61
|
"access": "public"
|