@mdit/plugin-katex 0.1.0-alpha.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 +21 -0
- package/README.md +16 -0
- package/lib/index.cjs +4 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +17 -0
- package/lib/index.d.mts +17 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.mjs +4 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2022 - PRESENT by MrHope
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @mdit/plugin-katex
|
|
2
|
+
|
|
3
|
+
[  ](https://www.npmjs.com/package/@mdit/plugin-katex)
|
|
4
|
+
|
|
5
|
+
katex plugin for MarkdownIt.
|
|
6
|
+
|
|
7
|
+
## Install / 安装
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# pnpm
|
|
11
|
+
pnpm add -D @mdit/plugin-katex
|
|
12
|
+
# npm
|
|
13
|
+
npm i -D @mdit/plugin-katex
|
|
14
|
+
# yarn
|
|
15
|
+
yarn add -D @mdit/plugin-katex
|
|
16
|
+
```
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var i=require("node:module"),l=require("@mdit/plugin-tex"),a=require("katex");const n=e=>e.replace(/&/gu,"&").replace(/</gu,"<").replace(/>/gu,">").replace(/"/gu,""").replace(/'/gu,"'"),p=i.createRequire(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("index.cjs",document.baseURI).href),d=(e,t)=>{try{return a.renderToString(e,{...t,displayMode:!1})}catch(r){return t.throwOnError&&console.warn(r),`<span class='katex-error' title='${n(r.toString())}'>${n(e)}</span>`}},g=(e,t)=>{try{return`<p class='katex-block'>${a.renderToString(e,{...t,displayMode:!0,strict:r=>r==="newLineInDisplayMode"?"ignore":"warn"})}</p>
|
|
2
|
+
`}catch(r){return t.throwOnError&&console.warn(r),`<p class='katex-block katex-error' title='${n(r.toString())}'>${n(e)}</p>
|
|
3
|
+
`}},m=(e,t={})=>{const{mhchem:r=!1,...s}=t;r&&p("katex/contrib/mhchem");const c={throwOnError:!1,...s};e.use(l.tex,{render:(o,u)=>u?g(o,c):d(o,c)})};exports.katex=m;
|
|
4
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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\";\nimport { tex } from \"@mdit/plugin-tex\";\nimport Katex from \"katex\";\nimport { escapeHtml } from \"./utils.js\";\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type { KatexOptions as OriginalKatexOptions } from \"katex\";\nimport type { MarkdownItKatexOptions } from \"./options.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 strict: (errorCode: string): string =>\n errorCode === \"newLineInDisplayMode\" ? \"ignore\" : \"warn\",\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: PluginWithOptions<MarkdownItKatexOptions> = (\n md,\n options = {}\n) => {\n const { mhchem = false, ...userOptions } = options;\n\n if (mhchem) require(\"katex/contrib/mhchem\");\n\n const katexOptions = {\n throwOnError: false,\n ...userOptions,\n };\n\n md.use(tex, {\n render: (content: string, displayMode: boolean) =>\n displayMode\n ? katexBlock(content, katexOptions)\n : katexInline(content, katexOptions),\n });\n};\n"],"names":["escapeHtml","unsafeHTML","require","createRequire","katexInline","tex","options","Katex","error","katexBlock","errorCode","katex","md","mhchem","userOptions","katexOptions","content","displayMode"],"mappings":"2FAAa,MAAAA,EAAcC,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} from 'katex';
|
|
2
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
3
|
+
|
|
4
|
+
interface MarkdownItKatexOptions extends KatexOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether enable mhchem extension
|
|
7
|
+
*
|
|
8
|
+
* 是否启用 mhchem 扩展
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
mhchem?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare const katex: PluginWithOptions<MarkdownItKatexOptions>;
|
|
16
|
+
|
|
17
|
+
export { MarkdownItKatexOptions, katex };
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { KatexOptions } from 'katex';
|
|
2
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
3
|
+
|
|
4
|
+
interface MarkdownItKatexOptions extends KatexOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether enable mhchem extension
|
|
7
|
+
*
|
|
8
|
+
* 是否启用 mhchem 扩展
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
mhchem?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare const katex: PluginWithOptions<MarkdownItKatexOptions>;
|
|
16
|
+
|
|
17
|
+
export { MarkdownItKatexOptions, katex };
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { KatexOptions } from 'katex';
|
|
2
|
+
import { PluginWithOptions } from 'markdown-it';
|
|
3
|
+
|
|
4
|
+
interface MarkdownItKatexOptions extends KatexOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether enable mhchem extension
|
|
7
|
+
*
|
|
8
|
+
* 是否启用 mhchem 扩展
|
|
9
|
+
*
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
mhchem?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare const katex: PluginWithOptions<MarkdownItKatexOptions>;
|
|
16
|
+
|
|
17
|
+
export { MarkdownItKatexOptions, katex };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as l}from"node:module";import{tex as i}from"@mdit/plugin-tex";import c from"katex";const o=r=>r.replace(/&/gu,"&").replace(/</gu,"<").replace(/>/gu,">").replace(/"/gu,""").replace(/'/gu,"'"),m=l(import.meta.url),u=(r,t)=>{try{return c.renderToString(r,{...t,displayMode:!1})}catch(e){return t.throwOnError&&console.warn(e),`<span class='katex-error' title='${o(e.toString())}'>${o(r)}</span>`}},g=(r,t)=>{try{return`<p class='katex-block'>${c.renderToString(r,{...t,displayMode:!0,strict:e=>e==="newLineInDisplayMode"?"ignore":"warn"})}</p>
|
|
2
|
+
`}catch(e){return t.throwOnError&&console.warn(e),`<p class='katex-block katex-error' title='${o(e.toString())}'>${o(r)}</p>
|
|
3
|
+
`}},h=(r,t={})=>{const{mhchem:e=!1,...s}=t;e&&m("katex/contrib/mhchem");const n={throwOnError:!1,...s};r.use(i,{render:(a,p)=>p?g(a,n):u(a,n)})};export{h as katex};
|
|
4
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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\";\nimport { tex } from \"@mdit/plugin-tex\";\nimport Katex from \"katex\";\nimport { escapeHtml } from \"./utils.js\";\n\nimport type { PluginWithOptions } from \"markdown-it\";\nimport type { KatexOptions as OriginalKatexOptions } from \"katex\";\nimport type { MarkdownItKatexOptions } from \"./options.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 strict: (errorCode: string): string =>\n errorCode === \"newLineInDisplayMode\" ? \"ignore\" : \"warn\",\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: PluginWithOptions<MarkdownItKatexOptions> = (\n md,\n options = {}\n) => {\n const { mhchem = false, ...userOptions } = options;\n\n if (mhchem) require(\"katex/contrib/mhchem\");\n\n const katexOptions = {\n throwOnError: false,\n ...userOptions,\n };\n\n md.use(tex, {\n render: (content: string, displayMode: boolean) =>\n displayMode\n ? katexBlock(content, katexOptions)\n : katexInline(content, katexOptions),\n });\n};\n"],"names":["escapeHtml","unsafeHTML","require","createRequire","katexInline","tex","options","Katex","error","katexBlock","errorCode","katex","md","mhchem","userOptions","katexOptions","content","displayMode"],"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,GACP,OAAIF,EAAQ,cAAc,QAAQ,KAAKE,CAAK,EAErC,oCAAoCR,EACxCQ,EAAgB,SACnB,CAAA,MAAMR,EAAWK,CAAG,UACtB,CACF,EAEMI,EAAa,CAACJ,EAAaC,IAA0C,CACzE,GAAI,CACF,MAAO,0BAA0BC,EAAM,eAAeF,EAAK,CACzD,GAAGC,EACH,YAAa,GACb,OAASI,GACPA,IAAc,uBAAyB,SAAW,MACtD,CAAC;AAAA,CACH,OAASF,GACP,OAAIF,EAAQ,cAAc,QAAQ,KAAKE,CAAK,EAErC,6CAA6CR,EACjDQ,EAAgB,UACnB,MAAMR,EAAWK,CAAG;AAAA,CACtB,CACF,EAEaM,EAAmD,CAC9DC,EACAN,EAAU,CAAC,IACR,CACH,KAAM,CAAE,OAAAO,EAAS,MAAUC,CAAY,EAAIR,EAEvCO,GAAQX,EAAQ,sBAAsB,EAE1C,MAAMa,EAAe,CACnB,aAAc,GACd,GAAGD,CACL,EAEAF,EAAG,IAAIP,EAAK,CACV,OAAQ,CAACW,EAAiBC,IACxBA,EACIR,EAAWO,EAASD,CAAY,EAChCX,EAAYY,EAASD,CAAY,CACzC,CAAC,CACH"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdit/plugin-katex",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "katex plugin for MarkdownIt",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"markdownit",
|
|
7
|
+
"markdown-it",
|
|
8
|
+
"markdown-it-plugin",
|
|
9
|
+
"katex"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/Mister-Hope//mdit-plugins/packages/katex#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Mister-Hope//mdit-plugins/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/Mister-Hope//mdit-plugins.git",
|
|
18
|
+
"directory": "packages/katex"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": {
|
|
22
|
+
"name": "Mr.Hope",
|
|
23
|
+
"email": "mister-hope@outlook.com",
|
|
24
|
+
"url": "https://mrhope.site"
|
|
25
|
+
},
|
|
26
|
+
"main": "lib/index.cjs",
|
|
27
|
+
"types": "lib/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": "./lib/index.mjs",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"lib"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@types/katex": "^0.16.0",
|
|
37
|
+
"@types/markdown-it": "^12.2.3",
|
|
38
|
+
"katex": "^0.16.4",
|
|
39
|
+
"markdown-it": "^13.0.1",
|
|
40
|
+
"@mdit/plugin-tex": "0.1.0-alpha.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rollup -c rollup.config.ts --configPlugin esbuild",
|
|
47
|
+
"clean": "rimraf ./lib"
|
|
48
|
+
}
|
|
49
|
+
}
|