@pie-lib/math-rendering 2.3.9 → 2.3.10-next.86
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/CHANGELOG.json +15 -0
- package/CHANGELOG.md +3 -42
- package/lib/render-math.js +2 -1
- package/lib/render-math.js.map +1 -1
- package/package.json +3 -3
- package/src/render-math.js +2 -1
package/CHANGELOG.json
CHANGED
|
@@ -653,5 +653,20 @@
|
|
|
653
653
|
"committerDate": "2021-08-17 10:59:50 +0300",
|
|
654
654
|
"isTagged": true,
|
|
655
655
|
"tag": "@pie-lib/math-rendering@2.3.9"
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
"type": "fix",
|
|
659
|
+
"scope": null,
|
|
660
|
+
"subject": "wip",
|
|
661
|
+
"merge": null,
|
|
662
|
+
"header": "fix: wip",
|
|
663
|
+
"body": null,
|
|
664
|
+
"footer": null,
|
|
665
|
+
"notes": [],
|
|
666
|
+
"hash": "fe4316df075edfc2c0565641b58c4ca453057651",
|
|
667
|
+
"gitTags": " (origin/fix/fix-math-module)",
|
|
668
|
+
"committerDate": "2021-09-06 13:29:44 +0100",
|
|
669
|
+
"isTagged": true,
|
|
670
|
+
"tag": "@pie-lib/math-rendering@2.3.10"
|
|
656
671
|
}
|
|
657
672
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -18,83 +18,44 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
18
18
|
|
|
19
19
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
21
|
## [2.3.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.5...@pie-lib/math-rendering@2.3.6) (2021-03-01)
|
|
26
22
|
|
|
27
23
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
25
|
## [2.3.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.4...@pie-lib/math-rendering@2.3.5) (2021-03-01)
|
|
34
26
|
|
|
35
|
-
|
|
36
27
|
### Bug Fixes
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
- **math-rendering:** linebreak rendering fixed for mathquill custom elements - PD-787 ([5216f6a](https://github.com/pie-framework/pie-lib/commit/5216f6a))
|
|
43
30
|
|
|
44
31
|
## [2.3.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.3...@pie-lib/math-rendering@2.3.4) (2021-02-15)
|
|
45
32
|
|
|
46
33
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
47
34
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
35
|
## [2.3.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.1...@pie-lib/math-rendering@2.3.3) (2021-02-15)
|
|
53
36
|
|
|
54
37
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
55
38
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
39
|
## [2.3.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.3.0...@pie-lib/math-rendering@2.3.1) (2021-01-28)
|
|
61
40
|
|
|
62
|
-
|
|
63
41
|
### Bug Fixes
|
|
64
42
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
43
|
+
- add lodash dependency ([de2227f](https://github.com/pie-framework/pie-lib/commit/de2227f))
|
|
70
44
|
|
|
71
45
|
# [2.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.4...@pie-lib/math-rendering@2.3.0) (2021-01-25)
|
|
72
46
|
|
|
73
|
-
|
|
74
47
|
### Features
|
|
75
48
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
49
|
+
- demo changes include for the issue PD-368 ([c493d9f](https://github.com/pie-framework/pie-lib/commit/c493d9f))
|
|
81
50
|
|
|
82
51
|
## [2.2.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.3...@pie-lib/math-rendering@2.2.4) (2021-01-11)
|
|
83
52
|
|
|
84
53
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
85
54
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
55
|
## [2.2.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.2...@pie-lib/math-rendering@2.2.3) (2020-10-26)
|
|
91
56
|
|
|
92
57
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
93
58
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
59
|
## [2.2.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.2.1...@pie-lib/math-rendering@2.2.2) (2020-10-26)
|
|
99
60
|
|
|
100
61
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
package/lib/render-math.js
CHANGED
package/lib/render-math.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render-math.js"],"names":["window","log","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","getGlobal","key","pkg","name","version","split","defaultOpts","opts","fixMathElement","element","property","textContent","unwrapped","replace","fixMathElements","mathElements","document","querySelectorAll","forEach","item","bootstrap","Typeset","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","inlineMath","processEscapes","mmlConfig","parseError","node","error","adaptor","fontURL","mathjax","htmlConfig","wrapperFactory","CHTMLWrapperFactory","defaultNodes","chtmlNodes","mml","MathML","customMmlFactory","MmlFactory","mmlNodes","html","compileError","mj","math","err","typesetError","doc","InputJax","TeX","OutputJax","CHTML","setMmlFactory","elements","findMath","length","compile","getMetrics","typeset","updateDocument","clear","renderMath","el","renderOpts","instance","Element","arr","Array","from","CHTMLmspace","styles","display"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;AAVA,IAAI,OAAOA,MAAP,KAAkB,WAAtB,EAAmC;AACjC,iCAAoB,qCAApB;AACD;;AAUD,IAAMC,GAAG,GAAG,uBAAM,wBAAN,CAAZ;AAEA,IAAMC,mBAAmB,GAAG,yBAA5B;AACA,IAAMC,aAAa,GAAG,YAAtB;;AAEA,IAAMC,SAAS,GAAG,SAAZA,SAAY,GAAM;AACtB,MAAMC,GAAG,aAAMC,oBAAIC,IAAV,cAAkBD,oBAAIE,OAAJ,CAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAAlB,CAAT;;AAEA,MAAI,OAAOT,MAAP,KAAkB,WAAtB,EAAmC;AACjC,QAAI,CAACA,MAAM,CAACK,GAAD,CAAX,EAAkB;AAChBL,MAAAA,MAAM,CAACK,GAAD,CAAN,GAAc,EAAd;AACD;;AACD,WAAOL,MAAM,CAACK,GAAD,CAAb;AACD,GALD,MAKO;AACL,WAAO,EAAP;AACD;AACF,CAXD;AAaA;;;;;;;;;AAOA,IAAMK,WAAW,GAAG,SAAdA,WAAc;AAAA,SAAMN,SAAS,GAAGO,IAAZ,IAAoB,EAA1B;AAAA,CAApB;;AAEO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,OAAO,EAAI;AACvC,MAAIC,QAAQ,GAAG,WAAf;;AAEA,MAAID,OAAO,CAACE,WAAZ,EAAyB;AACvBD,IAAAA,QAAQ,GAAG,aAAX;AACD;;AAED,MAAID,OAAO,CAACC,QAAD,CAAX,EAAuB;AACrBD,IAAAA,OAAO,CAACC,QAAD,CAAP,GAAoB,6BAAS,+BAAWD,OAAO,CAACC,QAAD,CAAlB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B,QAAMW,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAA3E,SAAS,GAAG6E,QAAZ,EAAqBxD,OAArB,+CAAgC0D,GAAhC;AACD;AACF,CAnBD;AAqBA;;;;;;;;;;;AASAG,oBAAYC,MAAZ,GAAqB;AACnB,gBAAc;AACZC,IAAAA,OAAO,EAAE,OADG;AAEZ,kBAAc;AAFF;AADK,CAArB;eAOeV,U","sourcesContent":["import { mathjax } from 'mathjax-full/js/mathjax';\nimport { MathML } from 'mathjax-full/js/input/mathml';\nimport { TeX } from 'mathjax-full/js/input/tex';\n\nimport { CHTML } from 'mathjax-full/js/output/chtml';\nimport { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';\nimport { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';\nimport { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n\nif (typeof window !== 'undefined') {\n RegisterHTMLHandler(browserAdaptor());\n}\n\nimport pkg from '../package.json';\nimport { mmlNodes, chtmlNodes } from './mstack';\nimport debug from 'debug';\nimport { wrapMath, unWrapMath } from './normalization';\nimport { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';\nimport { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';\nimport { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';\n\nconst log = debug('pie-lib:math-rendering');\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst getGlobal = () => {\n const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n\n if (typeof window !== 'undefined') {\n if (!window[key]) {\n window[key] = {};\n }\n return window[key];\n } else {\n return {};\n }\n};\n\n/** Add temporary support for a global singleDollar override\n * <code>\n * // This will enable single dollar rendering\n * window.pie = window.pie || {};\n * window.pie.mathRendering = {useSingleDollar: true };\n * </code>\n */\nconst defaultOpts = () => getGlobal().opts || {};\n\nexport const fixMathElement = element => {\n let property = 'innerText';\n\n if (element.textContent) {\n property = 'textContent';\n }\n\n if (element[property]) {\n element[property] = wrapMath(unWrapMath(element[property]).unwrapped);\n // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.\n // we need to replace the custom embedded elements with valid latex that Mathjax can understand\n element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);\n }\n};\n\nexport const fixMathElements = () => {\n const mathElements = document.querySelectorAll('[data-latex]');\n\n mathElements.forEach(item => fixMathElement(item));\n};\n\nconst bootstrap = opts => {\n if (typeof window === 'undefined') {\n return { Typeset: () => ({}) };\n }\n\n opts = opts || defaultOpts();\n\n if (opts.useSingleDollar) {\n // eslint-disable-next-line\n console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\\\(...\\\\)');\n }\n\n const packages = AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax\n\n // The autoload extension predefines all the macros from the extensions that haven't been loaded already\n // so that they automatically load the needed extension when they are first used\n packages.push('autoload');\n\n const macros = {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}'\n };\n\n const texConfig = opts.useSingleDollar\n ? {\n packages,\n macros,\n inlineMath: [['$', '$'], ['\\\\(', '\\\\)']],\n processEscapes: true\n }\n : {\n packages,\n macros\n };\n\n const mmlConfig = {\n parseError: function(node) {\n // function to process parsing errors\n console.log('error:', node);\n this.error(this.adaptor.textContent(node).replace(/\\n.*/g, ''));\n }\n };\n\n const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;\n const htmlConfig = {\n fontURL,\n\n wrapperFactory: new CHTMLWrapperFactory({\n ...CHTMLWrapperFactory.defaultNodes,\n ...chtmlNodes\n })\n };\n\n const mml = new MathML(mmlConfig);\n\n const customMmlFactory = new MmlFactory({\n ...MmlFactory.defaultNodes,\n ...mmlNodes\n });\n\n const html = mathjax.document(document, {\n compileError: (mj, math, err) => {\n console.log('bad math?:', math);\n console.error(err);\n },\n typesetError: function(doc, math, err) {\n console.log('typeset error');\n console.error(err);\n doc.typesetError(math, err);\n },\n\n InputJax: [new TeX(texConfig), mml],\n OutputJax: new CHTML(htmlConfig)\n });\n\n // Note: we must set this *after* mathjax.document (no idea why)\n mml.setMmlFactory(customMmlFactory);\n\n return {\n version: mathjax.version,\n html: html,\n\n Typeset: function(...elements) {\n this.html\n .findMath(elements.length ? { elements } : {})\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument()\n .clear();\n }\n };\n};\n\nconst renderMath = (el, renderOpts) => {\n //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)\n fixMathElements();\n\n if (!getGlobal().instance) {\n getGlobal().instance = bootstrap(renderOpts);\n }\n\n if (!el) {\n log('el is undefined');\n return;\n }\n\n if (el instanceof Element) {\n getGlobal().instance.Typeset(el);\n } else if (el.length) {\n const arr = Array.from(el);\n getGlobal().instance.Typeset(...arr);\n }\n};\n\n/**\n * This style is added to overried default styling of mjx-mspace Mathjax tag\n * In mathjax src code \\newline latex gets parsed to <mjx-mspace></mjx-mspace>,\n * but has the default style\n * 'mjx-mspace': {\n \"display\": 'in-line',\n \"text-align\": 'left'\n } which prevents it from showing as a newline value\n */\nCHTMLmspace.styles = {\n 'mjx-mspace': {\n display: 'block',\n 'text-align': 'center'\n }\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
|
|
1
|
+
{"version":3,"sources":["../src/render-math.js"],"names":["window","log","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","getGlobal","key","pkg","name","version","split","defaultOpts","opts","fixMathElement","element","property","textContent","unwrapped","replace","fixMathElements","mathElements","document","querySelectorAll","forEach","item","bootstrap","Typeset","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","inlineMath","processEscapes","mmlConfig","parseError","node","error","adaptor","fontURL","mathjax","htmlConfig","wrapperFactory","CHTMLWrapperFactory","defaultNodes","chtmlNodes","mml","MathML","customMmlFactory","MmlFactory","mmlNodes","html","compileError","mj","math","err","typesetError","doc","InputJax","TeX","OutputJax","CHTML","setMmlFactory","elements","findMath","length","compile","getMetrics","typeset","updateDocument","clear","renderMath","el","renderOpts","instance","Element","arr","Array","from","CHTMLmspace","styles","display","height"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;AAVA,IAAI,OAAOA,MAAP,KAAkB,WAAtB,EAAmC;AACjC,iCAAoB,qCAApB;AACD;;AAUD,IAAMC,GAAG,GAAG,uBAAM,wBAAN,CAAZ;AAEA,IAAMC,mBAAmB,GAAG,yBAA5B;AACA,IAAMC,aAAa,GAAG,YAAtB;;AAEA,IAAMC,SAAS,GAAG,SAAZA,SAAY,GAAM;AACtB,MAAMC,GAAG,aAAMC,oBAAIC,IAAV,cAAkBD,oBAAIE,OAAJ,CAAYC,KAAZ,CAAkB,GAAlB,EAAuB,CAAvB,CAAlB,CAAT;;AAEA,MAAI,OAAOT,MAAP,KAAkB,WAAtB,EAAmC;AACjC,QAAI,CAACA,MAAM,CAACK,GAAD,CAAX,EAAkB;AAChBL,MAAAA,MAAM,CAACK,GAAD,CAAN,GAAc,EAAd;AACD;;AACD,WAAOL,MAAM,CAACK,GAAD,CAAb;AACD,GALD,MAKO;AACL,WAAO,EAAP;AACD;AACF,CAXD;AAaA;;;;;;;;;AAOA,IAAMK,WAAW,GAAG,SAAdA,WAAc;AAAA,SAAMN,SAAS,GAAGO,IAAZ,IAAoB,EAA1B;AAAA,CAApB;;AAEO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAAAC,OAAO,EAAI;AACvC,MAAIC,QAAQ,GAAG,WAAf;;AAEA,MAAID,OAAO,CAACE,WAAZ,EAAyB;AACvBD,IAAAA,QA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YAAYG,OAAlB,EAA2B;AACzB9E,IAAAA,SAAS,GAAG6E,QAAZ,CAAqBxD,OAArB,CAA6BsD,EAA7B;AACD,GAFD,MAEO,IAAIA,EAAE,CAACP,MAAP,EAAe;AAAA;;AACpB,QAAMW,GAAG,GAAGC,KAAK,CAACC,IAAN,CAAWN,EAAX,CAAZ;;AACA,2BAAA3E,SAAS,GAAG6E,QAAZ,EAAqBxD,OAArB,+CAAgC0D,GAAhC;AACD;AACF,CAnBD;AAqBA;;;;;;;;;;;AASAG,oBAAYC,MAAZ,GAAqB;AACnB,gBAAc;AACZC,IAAAA,OAAO,EAAE,OADG;AAEZ,kBAAc,QAFF;AAGZC,IAAAA,MAAM,EAAE;AAHI;AADK,CAArB;eAQeX,U","sourcesContent":["import { mathjax } from 'mathjax-full/js/mathjax';\nimport { MathML } from 'mathjax-full/js/input/mathml';\nimport { TeX } from 'mathjax-full/js/input/tex';\n\nimport { CHTML } from 'mathjax-full/js/output/chtml';\nimport { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';\nimport { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';\nimport { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n\nif (typeof window !== 'undefined') {\n RegisterHTMLHandler(browserAdaptor());\n}\n\nimport pkg from '../package.json';\nimport { mmlNodes, chtmlNodes } from './mstack';\nimport debug from 'debug';\nimport { wrapMath, unWrapMath } from './normalization';\nimport { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';\nimport { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';\nimport { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';\n\nconst log = debug('pie-lib:math-rendering');\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst getGlobal = () => {\n const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n\n if (typeof window !== 'undefined') {\n if (!window[key]) {\n window[key] = {};\n }\n return window[key];\n } else {\n return {};\n }\n};\n\n/** Add temporary support for a global singleDollar override\n * <code>\n * // This will enable single dollar rendering\n * window.pie = window.pie || {};\n * window.pie.mathRendering = {useSingleDollar: true };\n * </code>\n */\nconst defaultOpts = () => getGlobal().opts || {};\n\nexport const fixMathElement = element => {\n let property = 'innerText';\n\n if (element.textContent) {\n property = 'textContent';\n }\n\n if (element[property]) {\n element[property] = wrapMath(unWrapMath(element[property]).unwrapped);\n // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.\n // we need to replace the custom embedded elements with valid latex that Mathjax can understand\n element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);\n }\n};\n\nexport const fixMathElements = () => {\n const mathElements = document.querySelectorAll('[data-latex]');\n\n mathElements.forEach(item => fixMathElement(item));\n};\n\nconst bootstrap = opts => {\n if (typeof window === 'undefined') {\n return { Typeset: () => ({}) };\n }\n\n opts = opts || defaultOpts();\n\n if (opts.useSingleDollar) {\n // eslint-disable-next-line\n console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\\\(...\\\\)');\n }\n\n const packages = AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax\n\n // The autoload extension predefines all the macros from the extensions that haven't been loaded already\n // so that they automatically load the needed extension when they are first used\n packages.push('autoload');\n\n const macros = {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}'\n };\n\n const texConfig = opts.useSingleDollar\n ? {\n packages,\n macros,\n inlineMath: [['$', '$'], ['\\\\(', '\\\\)']],\n processEscapes: true\n }\n : {\n packages,\n macros\n };\n\n const mmlConfig = {\n parseError: function(node) {\n // function to process parsing errors\n console.log('error:', node);\n this.error(this.adaptor.textContent(node).replace(/\\n.*/g, ''));\n }\n };\n\n const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;\n const htmlConfig = {\n fontURL,\n\n wrapperFactory: new CHTMLWrapperFactory({\n ...CHTMLWrapperFactory.defaultNodes,\n ...chtmlNodes\n })\n };\n\n const mml = new MathML(mmlConfig);\n\n const customMmlFactory = new MmlFactory({\n ...MmlFactory.defaultNodes,\n ...mmlNodes\n });\n\n const html = mathjax.document(document, {\n compileError: (mj, math, err) => {\n console.log('bad math?:', math);\n console.error(err);\n },\n typesetError: function(doc, math, err) {\n console.log('typeset error');\n console.error(err);\n doc.typesetError(math, err);\n },\n\n InputJax: [new TeX(texConfig), mml],\n OutputJax: new CHTML(htmlConfig)\n });\n\n // Note: we must set this *after* mathjax.document (no idea why)\n mml.setMmlFactory(customMmlFactory);\n\n return {\n version: mathjax.version,\n html: html,\n\n Typeset: function(...elements) {\n this.html\n .findMath(elements.length ? { elements } : {})\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument()\n .clear();\n }\n };\n};\n\nconst renderMath = (el, renderOpts) => {\n //TODO: remove this - has nothing to do with math-rendering (it's from editable-html)\n fixMathElements();\n\n if (!getGlobal().instance) {\n getGlobal().instance = bootstrap(renderOpts);\n }\n\n if (!el) {\n log('el is undefined');\n return;\n }\n\n if (el instanceof Element) {\n getGlobal().instance.Typeset(el);\n } else if (el.length) {\n const arr = Array.from(el);\n getGlobal().instance.Typeset(...arr);\n }\n};\n\n/**\n * This style is added to overried default styling of mjx-mspace Mathjax tag\n * In mathjax src code \\newline latex gets parsed to <mjx-mspace></mjx-mspace>,\n * but has the default style\n * 'mjx-mspace': {\n \"display\": 'in-line',\n \"text-align\": 'left'\n } which prevents it from showing as a newline value\n */\nCHTMLmspace.styles = {\n 'mjx-mspace': {\n display: 'block',\n 'text-align': 'center',\n height: '5px'\n }\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-rendering",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.10-next.86+f45a2d2e",
|
|
4
4
|
"description": "math rendering utilities",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"debug": "^4.1.1",
|
|
14
14
|
"lodash": "^4.17.11",
|
|
15
|
-
"mathjax-full": "^3.
|
|
15
|
+
"mathjax-full": "^3.2.0"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "f45a2d2e117fa21914e67a74c97fbec724227986",
|
|
18
18
|
"scripts": {}
|
|
19
19
|
}
|