@wordpress/latex-to-mathml 2.0.0 → 2.2.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/build/index.cjs +50 -50
- package/build/index.cjs.map +1 -7
- package/build/loader.cjs +8 -35
- package/build/loader.cjs.map +1 -7
- package/build-module/index.mjs +32 -28
- package/build-module/index.mjs.map +1 -7
- package/build-module/loader.mjs +4 -5
- package/build-module/loader.mjs.map +1 -7
- package/build-types/loader.d.ts +2 -0
- package/build-types/loader.d.ts.map +1 -0
- package/package.json +3 -3
- package/build-types/test/index.jsdom.test.d.ts +0 -2
- package/build-types/test/index.jsdom.test.d.ts.map +0 -1
- /package/src/test/{index.jsdom.test.js → index.jsdom.test.ts} +0 -0
package/build/index.cjs
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
5
|
+
});
|
|
6
|
+
// \0rolldown/runtime.js
|
|
2
7
|
var __create = Object.create;
|
|
3
8
|
var __defProp = Object.defineProperty;
|
|
4
9
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
10
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
11
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
12
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
13
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: ((k) => from[k]).bind(null, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
19
22
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
26
|
+
}) : target, mod));
|
|
27
|
+
let temml = require("temml");
|
|
28
|
+
temml = __toESM(temml);
|
|
30
29
|
// packages/latex-to-mathml/src/index.ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Converts LaTeX math syntax to MathML.
|
|
32
|
+
*
|
|
33
|
+
* @param latex - The LaTeX string to convert.
|
|
34
|
+
* @param options - Conversion options.
|
|
35
|
+
* @param options.displayMode
|
|
36
|
+
* @return The MathML string.
|
|
37
|
+
* @throws Will throw an error if the LaTeX is invalid.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```js
|
|
41
|
+
* import latexToMathML from '@wordpress/latex-to-mathml';
|
|
42
|
+
*
|
|
43
|
+
* const mathML = latexToMathML( 'x^2', { displayMode: false } );
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
37
46
|
function latexToMathML(latex, { displayMode = true } = {}) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"mtd.tml-right, mtd.tml-left"
|
|
51
|
-
)) {
|
|
52
|
-
cell.setAttribute(
|
|
53
|
-
"columnalign",
|
|
54
|
-
cell.classList.contains("tml-right") ? "right" : "left"
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
for (const element of math.querySelectorAll("[class]")) {
|
|
58
|
-
element.removeAttribute("class");
|
|
59
|
-
}
|
|
60
|
-
return math.innerHTML;
|
|
47
|
+
const mathML = temml.default.renderToString(latex, {
|
|
48
|
+
displayMode,
|
|
49
|
+
annotate: true,
|
|
50
|
+
throwOnError: true
|
|
51
|
+
});
|
|
52
|
+
const doc = document.implementation.createHTMLDocument("");
|
|
53
|
+
doc.body.innerHTML = mathML;
|
|
54
|
+
const math = doc.body.querySelector("math");
|
|
55
|
+
if (!math) return "";
|
|
56
|
+
for (const cell of math.querySelectorAll("mtd.tml-right, mtd.tml-left")) cell.setAttribute("columnalign", cell.classList.contains("tml-right") ? "right" : "left");
|
|
57
|
+
for (const element of math.querySelectorAll("[class]")) element.removeAttribute("class");
|
|
58
|
+
return math.innerHTML;
|
|
61
59
|
}
|
|
62
|
-
|
|
60
|
+
exports.default = latexToMathML;
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import temml from 'temml';\n\n/**\n * Options for LaTeX to MathML conversion.\n */\nexport interface LatexToMathMLOptions {\n\t/**\n\t * Whether to render in display mode (block) or inline mode.\n\t * @default true\n\t */\n\tdisplayMode?: boolean;\n}\n\n/**\n * Converts LaTeX math syntax to MathML.\n *\n * @param latex - The LaTeX string to convert.\n * @param options - Conversion options.\n * @param options.displayMode\n * @return The MathML string.\n * @throws Will throw an error if the LaTeX is invalid.\n *\n * @example\n * ```js\n * import latexToMathML from '@wordpress/latex-to-mathml';\n *\n * const mathML = latexToMathML( 'x^2', { displayMode: false } );\n * ```\n */\nexport default function latexToMathML(\n\tlatex: string,\n\t{ displayMode = true }: LatexToMathMLOptions = {}\n): string {\n\tconst mathML = temml.renderToString( latex, {\n\t\tdisplayMode,\n\t\tannotate: true,\n\t\tthrowOnError: true,\n\t} );\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = mathML;\n\tconst math = doc.body.querySelector( 'math' );\n\tif ( ! math ) {\n\t\treturn '';\n\t}\n\n\t// temml marks the cells of `aligned`, `cases` and tagged equations with\n\t// classes for its own stylesheet. Write the MathML `columnalign`\n\t// attribute on the cell instead, so the alignment is part of the content:\n\t// Firefox and Safari honor it natively, and the polyfill in `style.scss`\n\t// covers Chromium, which implements MathML Core only.\n\tfor ( const cell of math.querySelectorAll(\n\t\t'mtd.tml-right, mtd.tml-left'\n\t) ) {\n\t\tcell.setAttribute(\n\t\t\t'columnalign',\n\t\t\tcell.classList.contains( 'tml-right' ) ? 'right' : 'left'\n\t\t);\n\t}\n\n\t// The remaining classes are hooks for temml's stylesheet, which is not\n\t// used. Drop them so the content is plain MathML and does not depend on\n\t// the class names of a temml version.\n\tfor ( const element of math.querySelectorAll( '[class]' ) ) {\n\t\telement.removeAttribute( 'class' );\n\t}\n\n\treturn math.innerHTML;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AA6BH,SAAR,cACN,OACA,EAAE,cAAc,KAAK,IAA0B,CAAC,GACvC;AACT,QAAM,SAAS,aAAAA,QAAM,eAAgB,OAAO;AAAA,IAC3C;AAAA,IACA,UAAU;AAAA,IACV,cAAc;AAAA,EACf,CAAE;AACF,QAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;AAC3D,MAAI,KAAK,YAAY;AACrB,QAAM,OAAO,IAAI,KAAK,cAAe,MAAO;AAC5C,MAAK,CAAE,MAAO;AACb,WAAO;AAAA,EACR;AAOA,aAAY,QAAQ,KAAK;AAAA,IACxB;AAAA,EACD,GAAI;AACH,SAAK;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,SAAU,WAAY,IAAI,UAAU;AAAA,IACpD;AAAA,EACD;AAKA,aAAY,WAAW,KAAK,iBAAkB,SAAU,GAAI;AAC3D,YAAQ,gBAAiB,OAAQ;AAAA,EAClC;AAEA,SAAO,KAAK;AACb;",
|
|
6
|
-
"names": ["temml"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import temml from 'temml';\n\n/**\n * Options for LaTeX to MathML conversion.\n */\nexport interface LatexToMathMLOptions {\n\t/**\n\t * Whether to render in display mode (block) or inline mode.\n\t * @default true\n\t */\n\tdisplayMode?: boolean;\n}\n\n/**\n * Converts LaTeX math syntax to MathML.\n *\n * @param latex - The LaTeX string to convert.\n * @param options - Conversion options.\n * @param options.displayMode\n * @return The MathML string.\n * @throws Will throw an error if the LaTeX is invalid.\n *\n * @example\n * ```js\n * import latexToMathML from '@wordpress/latex-to-mathml';\n *\n * const mathML = latexToMathML( 'x^2', { displayMode: false } );\n * ```\n */\nexport default function latexToMathML(\n\tlatex: string,\n\t{ displayMode = true }: LatexToMathMLOptions = {}\n): string {\n\tconst mathML = temml.renderToString( latex, {\n\t\tdisplayMode,\n\t\tannotate: true,\n\t\tthrowOnError: true,\n\t} );\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = mathML;\n\tconst math = doc.body.querySelector( 'math' );\n\tif ( ! math ) {\n\t\treturn '';\n\t}\n\n\t// temml marks the cells of `aligned`, `cases` and tagged equations with\n\t// classes for its own stylesheet. Write the MathML `columnalign`\n\t// attribute on the cell instead, so the alignment is part of the content:\n\t// Firefox and Safari honor it natively, and the polyfill in `style.scss`\n\t// covers Chromium, which implements MathML Core only.\n\tfor ( const cell of math.querySelectorAll(\n\t\t'mtd.tml-right, mtd.tml-left'\n\t) ) {\n\t\tcell.setAttribute(\n\t\t\t'columnalign',\n\t\t\tcell.classList.contains( 'tml-right' ) ? 'right' : 'left'\n\t\t);\n\t}\n\n\t// The remaining classes are hooks for temml's stylesheet, which is not\n\t// used. Drop them so the content is plain MathML and does not depend on\n\t// the class names of a temml version.\n\tfor ( const element of math.querySelectorAll( '[class]' ) ) {\n\t\telement.removeAttribute( 'class' );\n\t}\n\n\treturn math.innerHTML;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAwB,cACvB,OACA,EAAE,cAAc,SAA+B,CAAC,GACvC;CACT,MAAM,SAAS,MAAA,QAAM,eAAgB,OAAO;EAC3C;EACA,UAAU;EACV,cAAc;CACf,CAAE;CACF,MAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;CAC3D,IAAI,KAAK,YAAY;CACrB,MAAM,OAAO,IAAI,KAAK,cAAe,MAAO;CAC5C,IAAK,CAAE,MACN,OAAO;CAQR,KAAM,MAAM,QAAQ,KAAK,iBACxB,6BACD,GACC,KAAK,aACJ,eACA,KAAK,UAAU,SAAU,WAAY,IAAI,UAAU,MACpD;CAMD,KAAM,MAAM,WAAW,KAAK,iBAAkB,SAAU,GACvD,QAAQ,gBAAiB,OAAQ;CAGlC,OAAO,KAAK;AACb"}
|
package/build/loader.cjs
CHANGED
|
@@ -1,39 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// packages/latex-to-mathml/src/loader.ts
|
|
31
|
-
var loader_exports = {};
|
|
32
|
-
__export(loader_exports, {
|
|
33
|
-
default: () => loader
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
34
5
|
});
|
|
35
|
-
|
|
6
|
+
// packages/latex-to-mathml/src/loader.ts
|
|
36
7
|
function loader() {
|
|
37
|
-
|
|
8
|
+
return import("@wordpress/latex-to-mathml");
|
|
38
9
|
}
|
|
39
|
-
|
|
10
|
+
exports.default = loader;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=loader.cjs.map
|
package/build/loader.cjs.map
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/loader.ts"],
|
|
4
|
-
"sourcesContent": ["export default function loader() {\n\treturn import( '@wordpress/latex-to-mathml' );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAe,SAAR,SAA0B;AAChC,SAAO,OAAQ,4BAA6B;AAC7C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"loader.cjs","names":[],"sources":["../src/loader.ts"],"sourcesContent":["export default function loader() {\n\treturn import( '@wordpress/latex-to-mathml' );\n}\n"],"mappings":";;;;;;AAAA,SAAwB,SAAS;CAChC,OAAO,OAAQ;AAChB"}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
|
-
// packages/latex-to-mathml/src/index.ts
|
|
2
1
|
import temml from "temml";
|
|
2
|
+
// packages/latex-to-mathml/src/index.ts
|
|
3
|
+
/**
|
|
4
|
+
* Converts LaTeX math syntax to MathML.
|
|
5
|
+
*
|
|
6
|
+
* @param latex - The LaTeX string to convert.
|
|
7
|
+
* @param options - Conversion options.
|
|
8
|
+
* @param options.displayMode
|
|
9
|
+
* @return The MathML string.
|
|
10
|
+
* @throws Will throw an error if the LaTeX is invalid.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```js
|
|
14
|
+
* import latexToMathML from '@wordpress/latex-to-mathml';
|
|
15
|
+
*
|
|
16
|
+
* const mathML = latexToMathML( 'x^2', { displayMode: false } );
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
function latexToMathML(latex, { displayMode = true } = {}) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"mtd.tml-right, mtd.tml-left"
|
|
17
|
-
)) {
|
|
18
|
-
cell.setAttribute(
|
|
19
|
-
"columnalign",
|
|
20
|
-
cell.classList.contains("tml-right") ? "right" : "left"
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
for (const element of math.querySelectorAll("[class]")) {
|
|
24
|
-
element.removeAttribute("class");
|
|
25
|
-
}
|
|
26
|
-
return math.innerHTML;
|
|
20
|
+
const mathML = temml.renderToString(latex, {
|
|
21
|
+
displayMode,
|
|
22
|
+
annotate: true,
|
|
23
|
+
throwOnError: true
|
|
24
|
+
});
|
|
25
|
+
const doc = document.implementation.createHTMLDocument("");
|
|
26
|
+
doc.body.innerHTML = mathML;
|
|
27
|
+
const math = doc.body.querySelector("math");
|
|
28
|
+
if (!math) return "";
|
|
29
|
+
for (const cell of math.querySelectorAll("mtd.tml-right, mtd.tml-left")) cell.setAttribute("columnalign", cell.classList.contains("tml-right") ? "right" : "left");
|
|
30
|
+
for (const element of math.querySelectorAll("[class]")) element.removeAttribute("class");
|
|
31
|
+
return math.innerHTML;
|
|
27
32
|
}
|
|
28
|
-
export {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=index.mjs.map
|
|
33
|
+
export { latexToMathML as default };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import temml from 'temml';\n\n/**\n * Options for LaTeX to MathML conversion.\n */\nexport interface LatexToMathMLOptions {\n\t/**\n\t * Whether to render in display mode (block) or inline mode.\n\t * @default true\n\t */\n\tdisplayMode?: boolean;\n}\n\n/**\n * Converts LaTeX math syntax to MathML.\n *\n * @param latex - The LaTeX string to convert.\n * @param options - Conversion options.\n * @param options.displayMode\n * @return The MathML string.\n * @throws Will throw an error if the LaTeX is invalid.\n *\n * @example\n * ```js\n * import latexToMathML from '@wordpress/latex-to-mathml';\n *\n * const mathML = latexToMathML( 'x^2', { displayMode: false } );\n * ```\n */\nexport default function latexToMathML(\n\tlatex: string,\n\t{ displayMode = true }: LatexToMathMLOptions = {}\n): string {\n\tconst mathML = temml.renderToString( latex, {\n\t\tdisplayMode,\n\t\tannotate: true,\n\t\tthrowOnError: true,\n\t} );\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = mathML;\n\tconst math = doc.body.querySelector( 'math' );\n\tif ( ! math ) {\n\t\treturn '';\n\t}\n\n\t// temml marks the cells of `aligned`, `cases` and tagged equations with\n\t// classes for its own stylesheet. Write the MathML `columnalign`\n\t// attribute on the cell instead, so the alignment is part of the content:\n\t// Firefox and Safari honor it natively, and the polyfill in `style.scss`\n\t// covers Chromium, which implements MathML Core only.\n\tfor ( const cell of math.querySelectorAll(\n\t\t'mtd.tml-right, mtd.tml-left'\n\t) ) {\n\t\tcell.setAttribute(\n\t\t\t'columnalign',\n\t\t\tcell.classList.contains( 'tml-right' ) ? 'right' : 'left'\n\t\t);\n\t}\n\n\t// The remaining classes are hooks for temml's stylesheet, which is not\n\t// used. Drop them so the content is plain MathML and does not depend on\n\t// the class names of a temml version.\n\tfor ( const element of math.querySelectorAll( '[class]' ) ) {\n\t\telement.removeAttribute( 'class' );\n\t}\n\n\treturn math.innerHTML;\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,WAAW;AA6BH,SAAR,cACN,OACA,EAAE,cAAc,KAAK,IAA0B,CAAC,GACvC;AACT,QAAM,SAAS,MAAM,eAAgB,OAAO;AAAA,IAC3C;AAAA,IACA,UAAU;AAAA,IACV,cAAc;AAAA,EACf,CAAE;AACF,QAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;AAC3D,MAAI,KAAK,YAAY;AACrB,QAAM,OAAO,IAAI,KAAK,cAAe,MAAO;AAC5C,MAAK,CAAE,MAAO;AACb,WAAO;AAAA,EACR;AAOA,aAAY,QAAQ,KAAK;AAAA,IACxB;AAAA,EACD,GAAI;AACH,SAAK;AAAA,MACJ;AAAA,MACA,KAAK,UAAU,SAAU,WAAY,IAAI,UAAU;AAAA,IACpD;AAAA,EACD;AAKA,aAAY,WAAW,KAAK,iBAAkB,SAAU,GAAI;AAC3D,YAAQ,gBAAiB,OAAQ;AAAA,EAClC;AAEA,SAAO,KAAK;AACb;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import temml from 'temml';\n\n/**\n * Options for LaTeX to MathML conversion.\n */\nexport interface LatexToMathMLOptions {\n\t/**\n\t * Whether to render in display mode (block) or inline mode.\n\t * @default true\n\t */\n\tdisplayMode?: boolean;\n}\n\n/**\n * Converts LaTeX math syntax to MathML.\n *\n * @param latex - The LaTeX string to convert.\n * @param options - Conversion options.\n * @param options.displayMode\n * @return The MathML string.\n * @throws Will throw an error if the LaTeX is invalid.\n *\n * @example\n * ```js\n * import latexToMathML from '@wordpress/latex-to-mathml';\n *\n * const mathML = latexToMathML( 'x^2', { displayMode: false } );\n * ```\n */\nexport default function latexToMathML(\n\tlatex: string,\n\t{ displayMode = true }: LatexToMathMLOptions = {}\n): string {\n\tconst mathML = temml.renderToString( latex, {\n\t\tdisplayMode,\n\t\tannotate: true,\n\t\tthrowOnError: true,\n\t} );\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = mathML;\n\tconst math = doc.body.querySelector( 'math' );\n\tif ( ! math ) {\n\t\treturn '';\n\t}\n\n\t// temml marks the cells of `aligned`, `cases` and tagged equations with\n\t// classes for its own stylesheet. Write the MathML `columnalign`\n\t// attribute on the cell instead, so the alignment is part of the content:\n\t// Firefox and Safari honor it natively, and the polyfill in `style.scss`\n\t// covers Chromium, which implements MathML Core only.\n\tfor ( const cell of math.querySelectorAll(\n\t\t'mtd.tml-right, mtd.tml-left'\n\t) ) {\n\t\tcell.setAttribute(\n\t\t\t'columnalign',\n\t\t\tcell.classList.contains( 'tml-right' ) ? 'right' : 'left'\n\t\t);\n\t}\n\n\t// The remaining classes are hooks for temml's stylesheet, which is not\n\t// used. Drop them so the content is plain MathML and does not depend on\n\t// the class names of a temml version.\n\tfor ( const element of math.querySelectorAll( '[class]' ) ) {\n\t\telement.removeAttribute( 'class' );\n\t}\n\n\treturn math.innerHTML;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6BA,SAAwB,cACvB,OACA,EAAE,cAAc,SAA+B,CAAC,GACvC;CACT,MAAM,SAAS,MAAM,eAAgB,OAAO;EAC3C;EACA,UAAU;EACV,cAAc;CACf,CAAE;CACF,MAAM,MAAM,SAAS,eAAe,mBAAoB,EAAG;CAC3D,IAAI,KAAK,YAAY;CACrB,MAAM,OAAO,IAAI,KAAK,cAAe,MAAO;CAC5C,IAAK,CAAE,MACN,OAAO;CAQR,KAAM,MAAM,QAAQ,KAAK,iBACxB,6BACD,GACC,KAAK,aACJ,eACA,KAAK,UAAU,SAAU,WAAY,IAAI,UAAU,MACpD;CAMD,KAAM,MAAM,WAAW,KAAK,iBAAkB,SAAU,GACvD,QAAQ,gBAAiB,OAAQ;CAGlC,OAAO,KAAK;AACb"}
|
package/build-module/loader.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// packages/latex-to-mathml/src/loader.ts
|
|
2
2
|
function loader() {
|
|
3
|
-
|
|
3
|
+
return import("@wordpress/latex-to-mathml");
|
|
4
4
|
}
|
|
5
|
-
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//# sourceMappingURL=loader.mjs.map
|
|
5
|
+
export { loader as default };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=loader.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/loader.ts"],
|
|
4
|
-
"sourcesContent": ["export default function loader() {\n\treturn import( '@wordpress/latex-to-mathml' );\n}\n"],
|
|
5
|
-
"mappings": ";AAAe,SAAR,SAA0B;AAChC,SAAO,OAAQ,4BAA6B;AAC7C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"loader.mjs","names":[],"sources":["../src/loader.ts"],"sourcesContent":["export default function loader() {\n\treturn import( '@wordpress/latex-to-mathml' );\n}\n"],"mappings":";AAAA,SAAwB,SAAS;CAChC,OAAO,OAAQ;AAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,MAAM,yDAE7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/latex-to-mathml",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Convert LaTeX math syntax to MathML.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"temml": "^0.10.33"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"vitest": "^5.0
|
|
51
|
+
"vitest": "^5.1.0"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "1000cdf1dffd5b5e69f75cc4360aa76db8252264"
|
|
57
57
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.jsdom.test.d.ts","sourceRoot":"","sources":["../../src/test/index.jsdom.test.js"],"names":[],"mappings":""}
|
|
File without changes
|