@fiduswriter/document 0.1.0-alpha.3 → 0.1.0-alpha.4
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/README.md +22 -1
- package/dist/bibliography/common.d.ts +92 -0
- package/dist/bibliography/common.d.ts.map +1 -0
- package/dist/bibliography/common.js +85 -0
- package/dist/bibliography/common.js.map +1 -0
- package/dist/bibliography/csl_bib.d.ts +3 -0
- package/dist/bibliography/csl_bib.d.ts.map +1 -0
- package/dist/bibliography/csl_bib.js +131 -0
- package/dist/bibliography/csl_bib.js.map +1 -0
- package/dist/citations/citeproc_sys.d.ts +13 -0
- package/dist/citations/citeproc_sys.d.ts.map +1 -0
- package/dist/citations/citeproc_sys.js +43 -0
- package/dist/citations/citeproc_sys.js.map +1 -0
- package/dist/citations/format.d.ts +23 -0
- package/dist/citations/format.d.ts.map +1 -0
- package/dist/citations/format.js +161 -0
- package/dist/citations/format.js.map +1 -0
- package/dist/editor/e2ee/encryptor.d.ts +123 -0
- package/dist/editor/e2ee/encryptor.d.ts.map +1 -0
- package/dist/editor/e2ee/encryptor.js +201 -0
- package/dist/editor/e2ee/encryptor.js.map +1 -0
- package/dist/exporter/docx/citations.d.ts +21 -0
- package/dist/exporter/docx/citations.d.ts.map +1 -0
- package/dist/exporter/docx/citations.js +154 -0
- package/dist/exporter/docx/citations.js.map +1 -0
- package/dist/exporter/docx/comments.d.ts +18 -0
- package/dist/exporter/docx/comments.d.ts.map +1 -0
- package/dist/exporter/docx/comments.js +137 -0
- package/dist/exporter/docx/comments.js.map +1 -0
- package/dist/exporter/docx/footnotes.d.ts +42 -0
- package/dist/exporter/docx/footnotes.d.ts.map +1 -0
- package/dist/exporter/docx/footnotes.js +182 -0
- package/dist/exporter/docx/footnotes.js.map +1 -0
- package/dist/exporter/docx/images.d.ts +14 -0
- package/dist/exporter/docx/images.d.ts.map +1 -0
- package/dist/exporter/docx/images.js +86 -0
- package/dist/exporter/docx/images.js.map +1 -0
- package/dist/exporter/docx/index.d.ts +22 -0
- package/dist/exporter/docx/index.d.ts.map +1 -0
- package/dist/exporter/docx/index.js +107 -0
- package/dist/exporter/docx/index.js.map +1 -0
- package/dist/exporter/docx/lists.d.ts +33 -0
- package/dist/exporter/docx/lists.d.ts.map +1 -0
- package/dist/exporter/docx/lists.js +229 -0
- package/dist/exporter/docx/lists.js.map +1 -0
- package/dist/exporter/docx/math.d.ts +13 -0
- package/dist/exporter/docx/math.d.ts.map +1 -0
- package/dist/exporter/docx/math.js +42 -0
- package/dist/exporter/docx/math.js.map +1 -0
- package/dist/exporter/docx/metadata.d.ts +14 -0
- package/dist/exporter/docx/metadata.d.ts.map +1 -0
- package/dist/exporter/docx/metadata.js +239 -0
- package/dist/exporter/docx/metadata.js.map +1 -0
- package/dist/exporter/docx/rels.d.ts +25 -0
- package/dist/exporter/docx/rels.d.ts.map +1 -0
- package/dist/exporter/docx/rels.js +168 -0
- package/dist/exporter/docx/rels.js.map +1 -0
- package/dist/exporter/docx/render.d.ts +20 -0
- package/dist/exporter/docx/render.d.ts.map +1 -0
- package/dist/exporter/docx/render.js +774 -0
- package/dist/exporter/docx/render.js.map +1 -0
- package/dist/exporter/docx/richtext.d.ts +25 -0
- package/dist/exporter/docx/richtext.d.ts.map +1 -0
- package/dist/exporter/docx/richtext.js +1052 -0
- package/dist/exporter/docx/richtext.js.map +1 -0
- package/dist/exporter/docx/tables.d.ts +14 -0
- package/dist/exporter/docx/tables.d.ts.map +1 -0
- package/dist/exporter/docx/tables.js +109 -0
- package/dist/exporter/docx/tables.js.map +1 -0
- package/dist/exporter/docx/tools.d.ts +3 -0
- package/dist/exporter/docx/tools.d.ts.map +1 -0
- package/dist/exporter/docx/tools.js +48 -0
- package/dist/exporter/docx/tools.js.map +1 -0
- package/dist/exporter/epub/index.d.ts +11 -0
- package/dist/exporter/epub/index.d.ts.map +1 -0
- package/dist/exporter/epub/index.js +102 -0
- package/dist/exporter/epub/index.js.map +1 -0
- package/dist/exporter/epub/templates.d.ts +32 -0
- package/dist/exporter/epub/templates.d.ts.map +1 -0
- package/dist/exporter/epub/templates.js +95 -0
- package/dist/exporter/epub/templates.js.map +1 -0
- package/dist/exporter/epub/tools.d.ts +5 -0
- package/dist/exporter/epub/tools.d.ts.map +1 -0
- package/dist/exporter/epub/tools.js +81 -0
- package/dist/exporter/epub/tools.js.map +1 -0
- package/dist/exporter/html/citations.d.ts +27 -0
- package/dist/exporter/html/citations.d.ts.map +1 -0
- package/dist/exporter/html/citations.js +91 -0
- package/dist/exporter/html/citations.js.map +1 -0
- package/dist/exporter/html/convert.d.ts +100 -0
- package/dist/exporter/html/convert.d.ts.map +1 -0
- package/dist/exporter/html/convert.js +718 -0
- package/dist/exporter/html/convert.js.map +1 -0
- package/dist/exporter/html/index.d.ts +61 -0
- package/dist/exporter/html/index.d.ts.map +1 -0
- package/dist/exporter/html/index.js +134 -0
- package/dist/exporter/html/index.js.map +1 -0
- package/dist/exporter/html/templates.d.ts +10 -0
- package/dist/exporter/html/templates.d.ts.map +1 -0
- package/dist/exporter/html/templates.js +21 -0
- package/dist/exporter/html/templates.js.map +1 -0
- package/dist/exporter/html/tools.d.ts +2 -0
- package/dist/exporter/html/tools.d.ts.map +1 -0
- package/dist/exporter/html/tools.js +49 -0
- package/dist/exporter/html/tools.js.map +1 -0
- package/dist/exporter/jats/bibliography.d.ts +2 -0
- package/dist/exporter/jats/bibliography.d.ts.map +1 -0
- package/dist/exporter/jats/bibliography.js +153 -0
- package/dist/exporter/jats/bibliography.js.map +1 -0
- package/dist/exporter/jats/citations.d.ts +14 -0
- package/dist/exporter/jats/citations.d.ts.map +1 -0
- package/dist/exporter/jats/citations.js +83 -0
- package/dist/exporter/jats/citations.js.map +1 -0
- package/dist/exporter/jats/convert.d.ts +45 -0
- package/dist/exporter/jats/convert.d.ts.map +1 -0
- package/dist/exporter/jats/convert.js +799 -0
- package/dist/exporter/jats/convert.js.map +1 -0
- package/dist/exporter/jats/index.d.ts +19 -0
- package/dist/exporter/jats/index.d.ts.map +1 -0
- package/dist/exporter/jats/index.js +66 -0
- package/dist/exporter/jats/index.js.map +1 -0
- package/dist/exporter/jats/templates.d.ts +16 -0
- package/dist/exporter/jats/templates.d.ts.map +1 -0
- package/dist/exporter/jats/templates.js +25 -0
- package/dist/exporter/jats/templates.js.map +1 -0
- package/dist/exporter/jats/text.d.ts +3 -0
- package/dist/exporter/jats/text.d.ts.map +1 -0
- package/dist/exporter/jats/text.js +72 -0
- package/dist/exporter/jats/text.js.map +1 -0
- package/dist/exporter/latex/convert.d.ts +27 -0
- package/dist/exporter/latex/convert.d.ts.map +1 -0
- package/dist/exporter/latex/convert.js +865 -0
- package/dist/exporter/latex/convert.js.map +1 -0
- package/dist/exporter/latex/escape_latex.d.ts +2 -0
- package/dist/exporter/latex/escape_latex.d.ts.map +1 -0
- package/dist/exporter/latex/escape_latex.js +20 -0
- package/dist/exporter/latex/escape_latex.js.map +1 -0
- package/dist/exporter/latex/index.d.ts +23 -0
- package/dist/exporter/latex/index.d.ts.map +1 -0
- package/dist/exporter/latex/index.js +57 -0
- package/dist/exporter/latex/index.js.map +1 -0
- package/dist/exporter/latex/readme.d.ts +2 -0
- package/dist/exporter/latex/readme.d.ts.map +1 -0
- package/dist/exporter/latex/readme.js +23 -0
- package/dist/exporter/latex/readme.js.map +1 -0
- package/dist/exporter/native/shrink.d.ts +21 -0
- package/dist/exporter/native/shrink.d.ts.map +1 -0
- package/dist/exporter/native/shrink.js +115 -0
- package/dist/exporter/native/shrink.js.map +1 -0
- package/dist/exporter/odt/citations.d.ts +18 -0
- package/dist/exporter/odt/citations.d.ts.map +1 -0
- package/dist/exporter/odt/citations.js +87 -0
- package/dist/exporter/odt/citations.js.map +1 -0
- package/dist/exporter/odt/footnotes.d.ts +25 -0
- package/dist/exporter/odt/footnotes.d.ts.map +1 -0
- package/dist/exporter/odt/footnotes.js +112 -0
- package/dist/exporter/odt/footnotes.js.map +1 -0
- package/dist/exporter/odt/images.d.ts +13 -0
- package/dist/exporter/odt/images.d.ts.map +1 -0
- package/dist/exporter/odt/images.js +98 -0
- package/dist/exporter/odt/images.js.map +1 -0
- package/dist/exporter/odt/index.d.ts +23 -0
- package/dist/exporter/odt/index.d.ts.map +1 -0
- package/dist/exporter/odt/index.js +99 -0
- package/dist/exporter/odt/index.js.map +1 -0
- package/dist/exporter/odt/math.d.ts +13 -0
- package/dist/exporter/odt/math.d.ts.map +1 -0
- package/dist/exporter/odt/math.js +48 -0
- package/dist/exporter/odt/math.js.map +1 -0
- package/dist/exporter/odt/metadata.d.ts +14 -0
- package/dist/exporter/odt/metadata.d.ts.map +1 -0
- package/dist/exporter/odt/metadata.js +203 -0
- package/dist/exporter/odt/metadata.js.map +1 -0
- package/dist/exporter/odt/render.d.ts +24 -0
- package/dist/exporter/odt/render.d.ts.map +1 -0
- package/dist/exporter/odt/render.js +644 -0
- package/dist/exporter/odt/render.js.map +1 -0
- package/dist/exporter/odt/richtext.d.ts +22 -0
- package/dist/exporter/odt/richtext.d.ts.map +1 -0
- package/dist/exporter/odt/richtext.js +728 -0
- package/dist/exporter/odt/richtext.js.map +1 -0
- package/dist/exporter/odt/styles.d.ts +33 -0
- package/dist/exporter/odt/styles.d.ts.map +1 -0
- package/dist/exporter/odt/styles.js +348 -0
- package/dist/exporter/odt/styles.js.map +1 -0
- package/dist/exporter/odt/track.d.ts +11 -0
- package/dist/exporter/odt/track.d.ts.map +1 -0
- package/dist/exporter/odt/track.js +59 -0
- package/dist/exporter/odt/track.js.map +1 -0
- package/dist/exporter/pandoc/citations.d.ts +17 -0
- package/dist/exporter/pandoc/citations.d.ts.map +1 -0
- package/dist/exporter/pandoc/citations.js +85 -0
- package/dist/exporter/pandoc/citations.js.map +1 -0
- package/dist/exporter/pandoc/convert.d.ts +38 -0
- package/dist/exporter/pandoc/convert.d.ts.map +1 -0
- package/dist/exporter/pandoc/convert.js +881 -0
- package/dist/exporter/pandoc/convert.js.map +1 -0
- package/dist/exporter/pandoc/index.d.ts +38 -0
- package/dist/exporter/pandoc/index.d.ts.map +1 -0
- package/dist/exporter/pandoc/index.js +67 -0
- package/dist/exporter/pandoc/index.js.map +1 -0
- package/dist/exporter/pandoc/readme.d.ts +2 -0
- package/dist/exporter/pandoc/readme.d.ts.map +1 -0
- package/dist/exporter/pandoc/readme.js +9 -0
- package/dist/exporter/pandoc/readme.js.map +1 -0
- package/dist/exporter/pandoc/tools.d.ts +6 -0
- package/dist/exporter/pandoc/tools.d.ts.map +1 -0
- package/dist/exporter/pandoc/tools.js +52 -0
- package/dist/exporter/pandoc/tools.js.map +1 -0
- package/dist/exporter/print/index.d.ts +9 -0
- package/dist/exporter/print/index.d.ts.map +1 -0
- package/dist/exporter/print/index.js +140 -0
- package/dist/exporter/print/index.js.map +1 -0
- package/dist/exporter/tools/doc_content.d.ts +7 -0
- package/dist/exporter/tools/doc_content.d.ts.map +1 -0
- package/dist/exporter/tools/doc_content.js +129 -0
- package/dist/exporter/tools/doc_content.js.map +1 -0
- package/dist/exporter/tools/file.d.ts +2 -0
- package/dist/exporter/tools/file.d.ts.map +1 -0
- package/dist/exporter/tools/file.js +10 -0
- package/dist/exporter/tools/file.js.map +1 -0
- package/dist/exporter/tools/json.d.ts +7 -0
- package/dist/exporter/tools/json.d.ts.map +1 -0
- package/dist/exporter/tools/json.js +82 -0
- package/dist/exporter/tools/json.js.map +1 -0
- package/dist/exporter/tools/svg.d.ts +2 -0
- package/dist/exporter/tools/svg.d.ts.map +1 -0
- package/dist/exporter/tools/svg.js +26 -0
- package/dist/exporter/tools/svg.js.map +1 -0
- package/dist/exporter/tools/xml.d.ts +41 -0
- package/dist/exporter/tools/xml.d.ts.map +1 -0
- package/dist/exporter/tools/xml.js +440 -0
- package/dist/exporter/tools/xml.js.map +1 -0
- package/dist/exporter/tools/xml_zip.d.ts +20 -0
- package/dist/exporter/tools/xml_zip.d.ts.map +1 -0
- package/dist/exporter/tools/xml_zip.js +86 -0
- package/dist/exporter/tools/xml_zip.js.map +1 -0
- package/dist/exporter/tools/zip.d.ts +21 -0
- package/dist/exporter/tools/zip.d.ts.map +1 -0
- package/dist/exporter/tools/zip.js +71 -0
- package/dist/exporter/tools/zip.js.map +1 -0
- package/dist/exporter/tools/zotero_csl.d.ts +10 -0
- package/dist/exporter/tools/zotero_csl.d.ts.map +1 -0
- package/dist/exporter/tools/zotero_csl.js +78 -0
- package/dist/exporter/tools/zotero_csl.js.map +1 -0
- package/dist/importer/citations.d.ts +25 -0
- package/dist/importer/citations.d.ts.map +1 -0
- package/dist/importer/citations.js +116 -0
- package/dist/importer/citations.js.map +1 -0
- package/dist/importer/docx/citations.d.ts +65 -0
- package/dist/importer/docx/citations.d.ts.map +1 -0
- package/dist/importer/docx/citations.js +106 -0
- package/dist/importer/docx/citations.js.map +1 -0
- package/dist/importer/docx/convert.d.ts +228 -0
- package/dist/importer/docx/convert.d.ts.map +1 -0
- package/dist/importer/docx/convert.js +1226 -0
- package/dist/importer/docx/convert.js.map +1 -0
- package/dist/importer/docx/helpers.d.ts +2 -0
- package/dist/importer/docx/helpers.d.ts.map +1 -0
- package/dist/importer/docx/helpers.js +10 -0
- package/dist/importer/docx/helpers.js.map +1 -0
- package/dist/importer/docx/omml2mathml.d.ts +7 -0
- package/dist/importer/docx/omml2mathml.d.ts.map +1 -0
- package/dist/importer/docx/omml2mathml.js +1239 -0
- package/dist/importer/docx/omml2mathml.js.map +1 -0
- package/dist/importer/docx/parse.d.ts +205 -0
- package/dist/importer/docx/parse.d.ts.map +1 -0
- package/dist/importer/docx/parse.js +663 -0
- package/dist/importer/docx/parse.js.map +1 -0
- package/dist/importer/native/get_images.d.ts +11 -0
- package/dist/importer/native/get_images.d.ts.map +1 -0
- package/dist/importer/native/get_images.js +64 -0
- package/dist/importer/native/get_images.js.map +1 -0
- package/dist/importer/native/update.d.ts +6 -0
- package/dist/importer/native/update.d.ts.map +1 -0
- package/dist/importer/native/update.js +26 -0
- package/dist/importer/native/update.js.map +1 -0
- package/dist/importer/odt/citations.d.ts +47 -0
- package/dist/importer/odt/citations.d.ts.map +1 -0
- package/dist/importer/odt/citations.js +79 -0
- package/dist/importer/odt/citations.js.map +1 -0
- package/dist/importer/odt/convert.d.ts +330 -0
- package/dist/importer/odt/convert.d.ts.map +1 -0
- package/dist/importer/odt/convert.js +1506 -0
- package/dist/importer/odt/convert.js.map +1 -0
- package/dist/importer/pandoc/convert.d.ts +84 -0
- package/dist/importer/pandoc/convert.d.ts.map +1 -0
- package/dist/importer/pandoc/convert.js +777 -0
- package/dist/importer/pandoc/convert.js.map +1 -0
- package/dist/importer/pandoc/helpers.d.ts +4 -0
- package/dist/importer/pandoc/helpers.d.ts.map +1 -0
- package/dist/importer/pandoc/helpers.js +75 -0
- package/dist/importer/pandoc/helpers.js.map +1 -0
- package/dist/importer/zip_analyzer.d.ts +25 -0
- package/dist/importer/zip_analyzer.d.ts.map +1 -0
- package/dist/importer/zip_analyzer.js +84 -0
- package/dist/importer/zip_analyzer.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/mathlive/opf_includes.d.ts +2 -0
- package/dist/mathlive/opf_includes.d.ts.map +1 -0
- package/dist/mathlive/opf_includes.js +25 -0
- package/dist/mathlive/opf_includes.js.map +1 -0
- package/dist/schema/common/annotate.d.ts +59 -0
- package/dist/schema/common/annotate.d.ts.map +1 -0
- package/dist/schema/common/annotate.js +75 -0
- package/dist/schema/common/annotate.js.map +1 -0
- package/dist/schema/common/base.d.ts +109 -0
- package/dist/schema/common/base.d.ts.map +1 -0
- package/dist/schema/common/base.js +109 -0
- package/dist/schema/common/base.js.map +1 -0
- package/dist/schema/common/citation.d.ts +29 -0
- package/dist/schema/common/citation.d.ts.map +1 -0
- package/dist/schema/common/citation.js +62 -0
- package/dist/schema/common/citation.js.map +1 -0
- package/dist/schema/common/equation.d.ts +18 -0
- package/dist/schema/common/equation.d.ts.map +1 -0
- package/dist/schema/common/equation.js +32 -0
- package/dist/schema/common/equation.js.map +1 -0
- package/dist/schema/common/figure.d.ts +108 -0
- package/dist/schema/common/figure.d.ts.map +1 -0
- package/dist/schema/common/figure.js +176 -0
- package/dist/schema/common/figure.js.map +1 -0
- package/dist/schema/common/heading.d.ts +33 -0
- package/dist/schema/common/heading.d.ts.map +1 -0
- package/dist/schema/common/heading.js +41 -0
- package/dist/schema/common/heading.js.map +1 -0
- package/dist/schema/common/index.d.ts +11 -0
- package/dist/schema/common/index.d.ts.map +1 -0
- package/dist/schema/common/index.js +11 -0
- package/dist/schema/common/index.js.map +1 -0
- package/dist/schema/common/list.d.ts +83 -0
- package/dist/schema/common/list.d.ts.map +1 -0
- package/dist/schema/common/list.js +92 -0
- package/dist/schema/common/list.js.map +1 -0
- package/dist/schema/common/reference.d.ts +78 -0
- package/dist/schema/common/reference.d.ts.map +1 -0
- package/dist/schema/common/reference.js +97 -0
- package/dist/schema/common/reference.js.map +1 -0
- package/dist/schema/common/table.d.ts +92 -0
- package/dist/schema/common/table.d.ts.map +1 -0
- package/dist/schema/common/table.js +85 -0
- package/dist/schema/common/table.js.map +1 -0
- package/dist/schema/common/track.d.ts +131 -0
- package/dist/schema/common/track.d.ts.map +1 -0
- package/dist/schema/common/track.js +184 -0
- package/dist/schema/common/track.js.map +1 -0
- package/dist/schema/const.d.ts +3 -0
- package/dist/schema/const.d.ts.map +1 -0
- package/{src → dist}/schema/const.js +3 -3
- package/dist/schema/const.js.map +1 -0
- package/dist/schema/convert.d.ts +3 -0
- package/dist/schema/convert.d.ts.map +1 -0
- package/dist/schema/convert.js +1215 -0
- package/dist/schema/convert.js.map +1 -0
- package/dist/schema/document/content.d.ts +137 -0
- package/dist/schema/document/content.d.ts.map +1 -0
- package/dist/schema/document/content.js +177 -0
- package/dist/schema/document/content.js.map +1 -0
- package/dist/schema/document/index.d.ts +879 -0
- package/dist/schema/document/index.d.ts.map +1 -0
- package/dist/schema/document/index.js +68 -0
- package/dist/schema/document/index.js.map +1 -0
- package/dist/schema/document/structure.d.ts +273 -0
- package/dist/schema/document/structure.d.ts.map +1 -0
- package/dist/schema/document/structure.js +445 -0
- package/dist/schema/document/structure.js.map +1 -0
- package/dist/schema/export.d.ts +880 -0
- package/dist/schema/export.d.ts.map +1 -0
- package/dist/schema/export.js +16 -0
- package/dist/schema/export.js.map +1 -0
- package/dist/schema/footnotes.d.ts +499 -0
- package/dist/schema/footnotes.d.ts.map +1 -0
- package/dist/schema/footnotes.js +88 -0
- package/dist/schema/footnotes.js.map +1 -0
- package/dist/schema/footnotes_convert.d.ts +5 -0
- package/dist/schema/footnotes_convert.d.ts.map +1 -0
- package/dist/schema/footnotes_convert.js +26 -0
- package/dist/schema/footnotes_convert.js.map +1 -0
- package/dist/schema/i18n.d.ts +586 -0
- package/dist/schema/i18n.d.ts.map +1 -0
- package/dist/schema/i18n.js +585 -0
- package/dist/schema/i18n.js.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +6 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/mini_json.d.ts +5 -0
- package/dist/schema/mini_json.d.ts.map +1 -0
- package/dist/schema/mini_json.js +50 -0
- package/dist/schema/mini_json.js.map +1 -0
- package/dist/schema/text.d.ts +2 -0
- package/dist/schema/text.d.ts.map +1 -0
- package/dist/schema/text.js +23 -0
- package/dist/schema/text.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +48 -16
- package/scripts/export-schema.js +1 -1
- package/src/exporter/tools/{file.js → file.ts} +1 -1
- package/src/exporter/tools/{json.js → json.ts} +30 -19
- package/src/global.d.ts +11 -0
- package/src/schema/const.ts +58 -0
- package/src/types.ts +136 -0
- package/jest.config.js +0 -24
- /package/src/{index.js → index.ts} +0 -0
|
@@ -0,0 +1,1239 @@
|
|
|
1
|
+
// Converted version of https://github.com/scienceai/omml2mathml/blob/master/index.js
|
|
2
|
+
// that works with our xml dom.
|
|
3
|
+
import { xmlDOM } from "../../exporter/tools/xml.js";
|
|
4
|
+
const MATH_NS = "http://www.w3.org/1998/Math/MathML";
|
|
5
|
+
// Regular expression matching mathematical operators
|
|
6
|
+
const oprx = /[\+\-\*\/\^\&\|\!\~\<\>\=\:\u2208\u2209\u220B\u220C\u2218\u2219\u221D\u2223\u2224\u2225\u2226\u2227\u2228\u2229\u222A\u222B\u222C\u222D\u2234\u2235\u2236\u2237\u2238\u2239\u223A\u223B\u223C\u223D\u223E\u223F\u2240\u2241\u2242\u2243\u2244\u2245\u2246\u2247\u2248\u2249\u224A\u224B\u224C\u224D\u224E\u224F\u2250\u2251\u2252\u2253\u2254\u2255\u2256\u2257\u2258\u2259\u225A\u225B\u225C\u225D\u225E\u225F\u2260\u2261\u2262\u2263\u2264\u2265\u2266\u2267\u2268\u2269\u226A\u226B\u226C\u226D\u226E\u226F\u2270\u2271\u2272\u2273\u2274\u2275\u2276\u2277\u2278\u2279\u227A\u227B\u227C\u227D\u227E\u227F\u2280\u2281\u2282\u2283\u2284\u2285\u2286\u2287\u2288\u2289\u228A\u228B\u228C\u228D\u228E\u228F\u2290\u2291\u2292\u2293\u2294\u2295\u2296\u2297\u2298\u2299\u229A\u229B\u229C\u229D\u229E\u229F\u22A0\u22A1\u22A2\u22A3\u22A4\u22A5\u22A6\u22A7\u22A8\u22A9\u22AA\u22AB\u22AC\u22AD\u22AE\u22AF\u22B0\u22B1\u22B2\u22B3\u22B4\u22B5\u22B6\u22B7\u22B8\u22B9\u22BA\u22BB\u22BC\u22BD\u22C0\u22C1\u22C2\u22C3\u22C4\u22C5\u22C6\u22C7\u22C8\u22C9\u22CA\u22CB\u22CC\u22CD\u22CE\u22CF\u22D0\u22D1\u22D2\u22D3\u22D4\u22D5\u22D6\u22D7\u22D8\u22D9\u22DA\u22DB\u22DC\u22DD\u22DE\u22DF\u22E0\u22E1\u22E2\u22E3\u22E4\u22E5\u22E6\u22E7\u22E8\u22E9\u22EA\u22EB\u22EC\u22ED\u22EE\u22EF\u22F0\u22F1\u22F2\u22F3\u22F4\u22F5\u22F6\u22F7\u22F8\u22F9\u22FA\u22FB\u22FC\u22FD\u22FE\u22FF]/;
|
|
7
|
+
/**
|
|
8
|
+
* Converts OMML to MathML
|
|
9
|
+
* @param {XMLElement} omml - OMML XML element
|
|
10
|
+
* @return {string} MathML XML string
|
|
11
|
+
*/
|
|
12
|
+
export function omml2mathml(omml) {
|
|
13
|
+
// Create the root math element
|
|
14
|
+
const math = xmlDOM(`<math xmlns="${MATH_NS}" display="inline"></math>`);
|
|
15
|
+
// Process the OMML document
|
|
16
|
+
processOMML(omml, math);
|
|
17
|
+
return math;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Process the OMML document and convert to MathML
|
|
21
|
+
* @param {XMLElement} omml - The OMML element to process
|
|
22
|
+
* @param {XMLElement} math - The parent MathML element
|
|
23
|
+
*/
|
|
24
|
+
function processOMML(omml, math) {
|
|
25
|
+
// Handle different OMML elements
|
|
26
|
+
if (omml.tagName === "m:oMathPara") {
|
|
27
|
+
math.setAttribute("display", "block");
|
|
28
|
+
omml.queryAll("m:oMath").forEach(omath => {
|
|
29
|
+
processOMML(omath, math);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (omml.tagName === "m:oMath") {
|
|
33
|
+
const mrow = createMathElement("mrow", {}, math);
|
|
34
|
+
processChildren(omml, mrow);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
processElement(omml, math);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Process an OMML element and create corresponding MathML
|
|
42
|
+
* @param {XMLElement} element - The OMML element to process
|
|
43
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
44
|
+
*/
|
|
45
|
+
function processElement(element, parent) {
|
|
46
|
+
if (!element || !element.tagName) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
switch (element.tagName) {
|
|
50
|
+
case "m:f":
|
|
51
|
+
processFraction(element, parent);
|
|
52
|
+
break;
|
|
53
|
+
case "m:r":
|
|
54
|
+
processRun(element, parent);
|
|
55
|
+
break;
|
|
56
|
+
case "m:limLow":
|
|
57
|
+
processLimLow(element, parent);
|
|
58
|
+
break;
|
|
59
|
+
case "m:limUpp":
|
|
60
|
+
processLimUpp(element, parent);
|
|
61
|
+
break;
|
|
62
|
+
case "m:sSub":
|
|
63
|
+
processSubscript(element, parent);
|
|
64
|
+
break;
|
|
65
|
+
case "m:sSup":
|
|
66
|
+
processSuperscript(element, parent);
|
|
67
|
+
break;
|
|
68
|
+
case "m:sSubSup":
|
|
69
|
+
processSubSuperscript(element, parent);
|
|
70
|
+
break;
|
|
71
|
+
case "m:sPre":
|
|
72
|
+
processPreScript(element, parent);
|
|
73
|
+
break;
|
|
74
|
+
case "m:m":
|
|
75
|
+
processMatrix(element, parent);
|
|
76
|
+
break;
|
|
77
|
+
case "m:rad":
|
|
78
|
+
processRadical(element, parent);
|
|
79
|
+
break;
|
|
80
|
+
case "m:nary":
|
|
81
|
+
processNary(element, parent);
|
|
82
|
+
break;
|
|
83
|
+
case "m:d":
|
|
84
|
+
processDelimiter(element, parent);
|
|
85
|
+
break;
|
|
86
|
+
case "m:eqArr":
|
|
87
|
+
processEqArr(element, parent);
|
|
88
|
+
break;
|
|
89
|
+
case "m:func":
|
|
90
|
+
processFunction(element, parent);
|
|
91
|
+
break;
|
|
92
|
+
case "m:acc":
|
|
93
|
+
processAccent(element, parent);
|
|
94
|
+
break;
|
|
95
|
+
case "m:groupChr":
|
|
96
|
+
processGroupChar(element, parent);
|
|
97
|
+
break;
|
|
98
|
+
case "m:borderBox":
|
|
99
|
+
processBorderBox(element, parent);
|
|
100
|
+
break;
|
|
101
|
+
case "m:bar":
|
|
102
|
+
processBar(element, parent);
|
|
103
|
+
break;
|
|
104
|
+
case "m:phant":
|
|
105
|
+
processPhantom(element, parent);
|
|
106
|
+
break;
|
|
107
|
+
case "m:e":
|
|
108
|
+
case "m:den":
|
|
109
|
+
case "m:num":
|
|
110
|
+
case "m:lim":
|
|
111
|
+
case "m:sup":
|
|
112
|
+
case "m:sub":
|
|
113
|
+
processArgument(element, parent);
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
// Process children for unhandled elements
|
|
117
|
+
processChildren(element, parent);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Process all children of an element
|
|
122
|
+
* @param {XMLElement} element - The element whose children to process
|
|
123
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
124
|
+
*/
|
|
125
|
+
function processChildren(element, parent) {
|
|
126
|
+
if (!element || !element.children) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
element.children.forEach(child => {
|
|
130
|
+
if (typeof child === "object") {
|
|
131
|
+
processElement(child, parent);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create a MathML element with specified attributes
|
|
137
|
+
* @param {string} tag - The MathML tag name
|
|
138
|
+
* @param {Object} attrs - The attributes to set
|
|
139
|
+
* @param {XMLElement} parent - The parent element
|
|
140
|
+
* @return {XMLElement} The created element
|
|
141
|
+
*/
|
|
142
|
+
function createMathElement(tag, attrs = {}, parent = null) {
|
|
143
|
+
const elem = xmlDOM(`<${tag}></${tag}>`);
|
|
144
|
+
// Set attributes
|
|
145
|
+
Object.entries(attrs).forEach(([key, value]) => {
|
|
146
|
+
if (value !== undefined && value !== "") {
|
|
147
|
+
elem.setAttribute(key, value);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
if (parent) {
|
|
151
|
+
parent.appendChild(elem);
|
|
152
|
+
}
|
|
153
|
+
return elem;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Process a fraction element
|
|
157
|
+
* @param {XMLElement} element - The OMML fraction element
|
|
158
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
159
|
+
*/
|
|
160
|
+
function processFraction(element, parent) {
|
|
161
|
+
const type = getAttr(element, "m:fPr/m:type", "m:val") || "";
|
|
162
|
+
if (type.toLowerCase() === "lin") {
|
|
163
|
+
const mrow = createMathElement("mrow", {}, parent);
|
|
164
|
+
const numRow = createMathElement("mrow", {}, mrow);
|
|
165
|
+
const num = element.query("m:num");
|
|
166
|
+
if (num) {
|
|
167
|
+
processElement(num, numRow);
|
|
168
|
+
}
|
|
169
|
+
const mo = createMathElement("mo", {}, mrow);
|
|
170
|
+
mo.textContent = "/";
|
|
171
|
+
const denRow = createMathElement("mrow", {}, mrow);
|
|
172
|
+
const den = element.query("m:den");
|
|
173
|
+
if (den) {
|
|
174
|
+
processElement(den, denRow);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const attr = getFracProps(type.toLowerCase());
|
|
179
|
+
const mfrac = createMathElement("mfrac", attr, parent);
|
|
180
|
+
const numRow = createMathElement("mrow", {}, mfrac);
|
|
181
|
+
const num = element.query("m:num");
|
|
182
|
+
if (num) {
|
|
183
|
+
processElement(num, numRow);
|
|
184
|
+
}
|
|
185
|
+
const denRow = createMathElement("mrow", {}, mfrac);
|
|
186
|
+
const den = element.query("m:den");
|
|
187
|
+
if (den) {
|
|
188
|
+
processElement(den, denRow);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Process a run of text
|
|
194
|
+
* @param {XMLElement} element - The OMML run element
|
|
195
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
196
|
+
*/
|
|
197
|
+
function processRun(element, parent) {
|
|
198
|
+
const nor = forceFalse(getAttr(element, "m:rPr/m:nor", "m:val") || "false");
|
|
199
|
+
if (nor) {
|
|
200
|
+
const mtext = createMathElement("mtext", {}, parent);
|
|
201
|
+
const textContent = element
|
|
202
|
+
.queryAll("m:t")
|
|
203
|
+
.map(t => t.textContent)
|
|
204
|
+
.join("");
|
|
205
|
+
mtext.textContent = nbsp(textContent);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
element.queryAll("m:t").forEach(t => {
|
|
209
|
+
const toParse = t.textContent;
|
|
210
|
+
const scr = getAttr(element, "m:rPr/m:scr", "m:val");
|
|
211
|
+
const sty = getAttr(element, "m:rPr/m:sty", "m:val");
|
|
212
|
+
parseMT(element, parent, {
|
|
213
|
+
toParse,
|
|
214
|
+
scr,
|
|
215
|
+
sty,
|
|
216
|
+
nor: false
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Process a lower limit element
|
|
223
|
+
* @param {XMLElement} element - The OMML limLow element
|
|
224
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
225
|
+
*/
|
|
226
|
+
function processLimLow(element, parent) {
|
|
227
|
+
const munder = createMathElement("munder", {}, parent);
|
|
228
|
+
const row1 = createMathElement("mrow", {}, munder);
|
|
229
|
+
const row2 = createMathElement("mrow", {}, munder);
|
|
230
|
+
const e = element.query("m:e");
|
|
231
|
+
if (e) {
|
|
232
|
+
processElement(e, row1);
|
|
233
|
+
}
|
|
234
|
+
const lim = element.query("m:lim");
|
|
235
|
+
if (lim) {
|
|
236
|
+
processElement(lim, row2);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Process an upper limit element
|
|
241
|
+
* @param {XMLElement} element - The OMML limUpp element
|
|
242
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
243
|
+
*/
|
|
244
|
+
function processLimUpp(element, parent) {
|
|
245
|
+
const mover = createMathElement("mover", {}, parent);
|
|
246
|
+
const row1 = createMathElement("mrow", {}, mover);
|
|
247
|
+
const row2 = createMathElement("mrow", {}, mover);
|
|
248
|
+
const e = element.query("m:e");
|
|
249
|
+
if (e) {
|
|
250
|
+
processElement(e, row1);
|
|
251
|
+
}
|
|
252
|
+
const lim = element.query("m:lim");
|
|
253
|
+
if (lim) {
|
|
254
|
+
processElement(lim, row2);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Process a subscript element
|
|
259
|
+
* @param {XMLElement} element - The OMML sSub element
|
|
260
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
261
|
+
*/
|
|
262
|
+
function processSubscript(element, parent) {
|
|
263
|
+
const msub = createMathElement("msub", {}, parent);
|
|
264
|
+
const row1 = createMathElement("mrow", {}, msub);
|
|
265
|
+
const row2 = createMathElement("mrow", {}, msub);
|
|
266
|
+
const e = element.query("m:e");
|
|
267
|
+
if (e) {
|
|
268
|
+
processElement(e, row1);
|
|
269
|
+
}
|
|
270
|
+
const sub = element.query("m:sub");
|
|
271
|
+
if (sub) {
|
|
272
|
+
processElement(sub, row2);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Process a superscript element
|
|
277
|
+
* @param {XMLElement} element - The OMML sSup element
|
|
278
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
279
|
+
*/
|
|
280
|
+
function processSuperscript(element, parent) {
|
|
281
|
+
const msup = createMathElement("msup", {}, parent);
|
|
282
|
+
const row1 = createMathElement("mrow", {}, msup);
|
|
283
|
+
const row2 = createMathElement("mrow", {}, msup);
|
|
284
|
+
const e = element.query("m:e");
|
|
285
|
+
if (e) {
|
|
286
|
+
processElement(e, row1);
|
|
287
|
+
}
|
|
288
|
+
const sup = element.query("m:sup");
|
|
289
|
+
if (sup) {
|
|
290
|
+
processElement(sup, row2);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Process a subscript-superscript element
|
|
295
|
+
* @param {XMLElement} element - The OMML sSubSup element
|
|
296
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
297
|
+
*/
|
|
298
|
+
function processSubSuperscript(element, parent) {
|
|
299
|
+
const msubsup = createMathElement("msubsup", {}, parent);
|
|
300
|
+
const row1 = createMathElement("mrow", {}, msubsup);
|
|
301
|
+
const row2 = createMathElement("mrow", {}, msubsup);
|
|
302
|
+
const row3 = createMathElement("mrow", {}, msubsup);
|
|
303
|
+
const e = element.query("m:e");
|
|
304
|
+
if (e) {
|
|
305
|
+
processElement(e, row1);
|
|
306
|
+
}
|
|
307
|
+
const sub = element.query("m:sub");
|
|
308
|
+
if (sub) {
|
|
309
|
+
processElement(sub, row2);
|
|
310
|
+
}
|
|
311
|
+
const sup = element.query("m:sup");
|
|
312
|
+
if (sup) {
|
|
313
|
+
processElement(sup, row3);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Process a prescripted element
|
|
318
|
+
* @param {XMLElement} element - The OMML sPre element
|
|
319
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
320
|
+
*/
|
|
321
|
+
function processPreScript(element, parent) {
|
|
322
|
+
const mmultiscripts = createMathElement("mmultiscripts", {}, parent);
|
|
323
|
+
const row = createMathElement("mrow", {}, mmultiscripts);
|
|
324
|
+
const e = element.query("m:e");
|
|
325
|
+
if (e) {
|
|
326
|
+
processElement(e, row);
|
|
327
|
+
}
|
|
328
|
+
createMathElement("mprescripts", {}, mmultiscripts);
|
|
329
|
+
const sub = element.query("m:sub");
|
|
330
|
+
outputScript(mmultiscripts, sub);
|
|
331
|
+
const sup = element.query("m:sup");
|
|
332
|
+
outputScript(mmultiscripts, sup);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Process a matrix element
|
|
336
|
+
* @param {XMLElement} element - The OMML matrix element
|
|
337
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
338
|
+
*/
|
|
339
|
+
function processMatrix(element, parent) {
|
|
340
|
+
const mcjc = getAttr(element, "m:mPr/m:mcs/m:mc/m:mcPr/m:mcJc", "m:val");
|
|
341
|
+
const attrs = {};
|
|
342
|
+
if (mcjc && mcjc.toLowerCase() !== "center") {
|
|
343
|
+
attrs.columnalign = mcjc.toLowerCase();
|
|
344
|
+
}
|
|
345
|
+
const mtable = createMathElement("mtable", attrs, parent);
|
|
346
|
+
element.queryAll("m:mr").forEach(mr => {
|
|
347
|
+
const mtr = createMathElement("mtr", {}, mtable);
|
|
348
|
+
mr.queryAll("m:e").forEach(me => {
|
|
349
|
+
const mtd = createMathElement("mtd", {}, mtr);
|
|
350
|
+
processElement(me, mtd);
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Process a radical element
|
|
356
|
+
* @param {XMLElement} element - The OMML radical element
|
|
357
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
358
|
+
*/
|
|
359
|
+
function processRadical(element, parent) {
|
|
360
|
+
const degHide = forceFalse(getAttr(element, "m:radPr/m:degHide", "m:val") || "false");
|
|
361
|
+
if (degHide) {
|
|
362
|
+
const msqrt = createMathElement("msqrt", {}, parent);
|
|
363
|
+
const e = element.query("m:e");
|
|
364
|
+
if (e) {
|
|
365
|
+
processElement(e, msqrt);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
const mroot = createMathElement("mroot", {}, parent);
|
|
370
|
+
const row1 = createMathElement("mrow", {}, mroot);
|
|
371
|
+
const row2 = createMathElement("mrow", {}, mroot);
|
|
372
|
+
const e = element.query("m:e");
|
|
373
|
+
if (e) {
|
|
374
|
+
processElement(e, row1);
|
|
375
|
+
}
|
|
376
|
+
const deg = element.query("m:deg");
|
|
377
|
+
if (deg) {
|
|
378
|
+
processElement(deg, row2);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Process an n-ary operator element
|
|
384
|
+
* @param {XMLElement} element - The OMML nary element
|
|
385
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
386
|
+
*/
|
|
387
|
+
function processNary(element, parent) {
|
|
388
|
+
const subHide = forceFalse(getAttr(element, "m:naryPr/m:subHide", "m:val") || "false");
|
|
389
|
+
const supHide = forceFalse(getAttr(element, "m:naryPr/m:supHide", "m:val") || "false");
|
|
390
|
+
const limLocSubSup = (getAttr(element, "m:naryPr/m:limLoc", "m:val") || "").toLowerCase() ===
|
|
391
|
+
"" ||
|
|
392
|
+
(getAttr(element, "m:naryPr/m:limLoc", "m:val") || "").toLowerCase() ===
|
|
393
|
+
"subsup";
|
|
394
|
+
const grow = forceFalse(getAttr(element, "m:naryPr/m:grow", "m:val") || "false");
|
|
395
|
+
const mrow = createMathElement("mrow", {}, parent);
|
|
396
|
+
if (supHide && subHide) {
|
|
397
|
+
outputNAryMO(element, mrow, grow);
|
|
398
|
+
}
|
|
399
|
+
else if (subHide) {
|
|
400
|
+
const outer = createMathElement(limLocSubSup ? "msup" : "mover", {}, mrow);
|
|
401
|
+
outputNAryMO(element, outer, grow);
|
|
402
|
+
const suprow = createMathElement("mrow", {}, outer);
|
|
403
|
+
const sup = element.query("m:sup");
|
|
404
|
+
if (sup) {
|
|
405
|
+
processElement(sup, suprow);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
else if (supHide) {
|
|
409
|
+
const outer = createMathElement(limLocSubSup ? "msub" : "munder", {}, mrow);
|
|
410
|
+
outputNAryMO(element, outer, grow);
|
|
411
|
+
const subrow = createMathElement("mrow", {}, outer);
|
|
412
|
+
const sub = element.query("m:sub");
|
|
413
|
+
if (sub) {
|
|
414
|
+
processElement(sub, subrow);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
const outer = createMathElement(limLocSubSup ? "msubsup" : "munderover", {}, mrow);
|
|
419
|
+
outputNAryMO(element, outer, grow);
|
|
420
|
+
const subrow1 = createMathElement("mrow", {}, outer);
|
|
421
|
+
const sub = element.query("m:sub");
|
|
422
|
+
if (sub) {
|
|
423
|
+
processElement(sub, subrow1);
|
|
424
|
+
}
|
|
425
|
+
const subrow2 = createMathElement("mrow", {}, outer);
|
|
426
|
+
const sup = element.query("m:sup");
|
|
427
|
+
if (sup) {
|
|
428
|
+
processElement(sup, subrow2);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const erow = createMathElement("mrow", {}, mrow);
|
|
432
|
+
const e = element.query("m:e");
|
|
433
|
+
if (e) {
|
|
434
|
+
processElement(e, erow);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Process a delimiter element
|
|
439
|
+
* @param {XMLElement} element - The OMML delimiter element
|
|
440
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
441
|
+
*/
|
|
442
|
+
function processDelimiter(element, parent) {
|
|
443
|
+
const begChr = getAttr(element, "m:dPr/m:begChr", "m:val");
|
|
444
|
+
const endChr = getAttr(element, "m:dPr/m:endChr", "m:val");
|
|
445
|
+
const sepChr = getAttr(element, "m:dPr/m:sepChr", "m:val") || "|";
|
|
446
|
+
const attr = {};
|
|
447
|
+
if (begChr !== undefined && begChr !== "(") {
|
|
448
|
+
attr.open = begChr;
|
|
449
|
+
}
|
|
450
|
+
if (endChr !== undefined && endChr !== ")") {
|
|
451
|
+
attr.close = endChr;
|
|
452
|
+
}
|
|
453
|
+
if (sepChr !== ",") {
|
|
454
|
+
attr.separators = sepChr;
|
|
455
|
+
}
|
|
456
|
+
const mfenced = createMathElement("mfenced", attr, parent);
|
|
457
|
+
element.queryAll("m:e").forEach(me => {
|
|
458
|
+
const row = createMathElement("mrow", {}, mfenced);
|
|
459
|
+
processElement(me, row);
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Process an equation array element
|
|
464
|
+
* @param {XMLElement} element - The OMML eqArr element
|
|
465
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
466
|
+
*/
|
|
467
|
+
function processEqArr(element, parent) {
|
|
468
|
+
const mtable = createMathElement("mtable", {}, parent);
|
|
469
|
+
element.queryAll("m:e").forEach(me => {
|
|
470
|
+
const mtr = createMathElement("mtr", {}, mtable);
|
|
471
|
+
const mtd = createMathElement("mtd", {}, mtr);
|
|
472
|
+
const scrLvl = getAttr(me, "m:argPr/m:scrLvl", "m:val");
|
|
473
|
+
const outer = scrLvl !== "0" && scrLvl
|
|
474
|
+
? createMathElement("mrow", {}, mtd)
|
|
475
|
+
: createMathElement("mstyle", { scriptlevel: scrLvl }, mtd);
|
|
476
|
+
createMathElement("maligngroup", {}, outer);
|
|
477
|
+
const firstChild = me.children[0];
|
|
478
|
+
if (firstChild) {
|
|
479
|
+
createEqArrRow(outer, element, firstChild, 1);
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Process a function element
|
|
485
|
+
* @param {XMLElement} element - The OMML function element
|
|
486
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
487
|
+
*/
|
|
488
|
+
function processFunction(element, parent) {
|
|
489
|
+
const outer = createMathElement("mrow", {}, parent);
|
|
490
|
+
const row1 = createMathElement("mrow", {}, outer);
|
|
491
|
+
element.queryAll("m:fName").forEach(fn => {
|
|
492
|
+
processElement(fn, row1);
|
|
493
|
+
});
|
|
494
|
+
const mo = createMathElement("mo", {}, outer);
|
|
495
|
+
mo.textContent = "\u2061"; // Function application
|
|
496
|
+
const row2 = createMathElement("mrow", {}, outer);
|
|
497
|
+
const e = element.query("m:e");
|
|
498
|
+
if (e) {
|
|
499
|
+
processElement(e, row2);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Process an accent element
|
|
504
|
+
* @param {XMLElement} element - The OMML accent element
|
|
505
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
506
|
+
*/
|
|
507
|
+
function processAccent(element, parent) {
|
|
508
|
+
const mover = createMathElement("mover", { accent: "true" }, parent);
|
|
509
|
+
const row = createMathElement("mrow", {}, mover);
|
|
510
|
+
const e = element.query("m:e");
|
|
511
|
+
if (e) {
|
|
512
|
+
processElement(e, row);
|
|
513
|
+
}
|
|
514
|
+
const acc = (getAttr(element, "m:accPr/m:chr", "m:val") || "\u0302").substr(0, 1);
|
|
515
|
+
const nonComb = toNonCombining(acc);
|
|
516
|
+
if (acc.length === 0) {
|
|
517
|
+
createMathElement("mo", {}, mover);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
const nor = forceFalse(getAttr(element, "m:rPr/m:nor", "m:val") || "false");
|
|
521
|
+
parseMT(element, mover, {
|
|
522
|
+
toParse: nonComb,
|
|
523
|
+
scr: getAttr(element, "m:e/*/m:rPr/m:scr", "m:val"),
|
|
524
|
+
sty: getAttr(element, "m:e/*/m:rPr/m:sty", "m:val"),
|
|
525
|
+
nor
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Process a group character element
|
|
531
|
+
* @param {XMLElement} element - The OMML groupChr element
|
|
532
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
533
|
+
*/
|
|
534
|
+
function processGroupChar(element, parent) {
|
|
535
|
+
const lastGroupChrPr = element.query("m:groupChrPr");
|
|
536
|
+
if (!lastGroupChrPr) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const pos = (getAttr(lastGroupChrPr, "m:pos", "m:val") || "").toLowerCase();
|
|
540
|
+
const vertJc = (getAttr(lastGroupChrPr, "m:vertJc", "m:val") || "").toLowerCase();
|
|
541
|
+
const chr = getAttr(lastGroupChrPr, "m:chr", "m:val") || "\u23DF";
|
|
542
|
+
const mkMrow = parent => {
|
|
543
|
+
const mrow = createMathElement("mrow", {}, parent);
|
|
544
|
+
const e = element.query("m:e");
|
|
545
|
+
if (e) {
|
|
546
|
+
processElement(e, mrow);
|
|
547
|
+
}
|
|
548
|
+
return mrow;
|
|
549
|
+
};
|
|
550
|
+
const mkMo = parent => {
|
|
551
|
+
const mo = createMathElement("mo", {}, parent);
|
|
552
|
+
mo.textContent = chr.substr(0, 1);
|
|
553
|
+
return mo;
|
|
554
|
+
};
|
|
555
|
+
if (pos === "top") {
|
|
556
|
+
if (vertJc === "bot") {
|
|
557
|
+
const outer = createMathElement("mover", { accent: "false" }, parent);
|
|
558
|
+
mkMrow(outer);
|
|
559
|
+
mkMo(outer);
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
const outer = createMathElement("munder", { accentunder: "false" }, parent);
|
|
563
|
+
mkMo(outer);
|
|
564
|
+
mkMrow(outer);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
if (vertJc === "bot") {
|
|
569
|
+
const outer = createMathElement("mover", { accent: "false" }, parent);
|
|
570
|
+
mkMo(outer);
|
|
571
|
+
mkMrow(outer);
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
const outer = createMathElement("munder", { accentunder: "false" }, parent);
|
|
575
|
+
mkMrow(outer);
|
|
576
|
+
mkMo(outer);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Process a border box element
|
|
582
|
+
* @param {XMLElement} element - The OMML borderBox element
|
|
583
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
584
|
+
*/
|
|
585
|
+
function processBorderBox(element, parent) {
|
|
586
|
+
const hideTop = forceTrue(getAttr(element, "m:borderBoxPr/m:hideTop", "m:val") || "false");
|
|
587
|
+
const hideBot = forceTrue(getAttr(element, "m:borderBoxPr/m:hideBot", "m:val") || "false");
|
|
588
|
+
const hideLeft = forceTrue(getAttr(element, "m:borderBoxPr/m:hideLeft", "m:val") || "false");
|
|
589
|
+
const hideRight = forceTrue(getAttr(element, "m:borderBoxPr/m:hideRight", "m:val") || "false");
|
|
590
|
+
const strikeH = forceTrue(getAttr(element, "m:borderBoxPr/m:strikeH", "m:val") || "false");
|
|
591
|
+
const strikeV = forceTrue(getAttr(element, "m:borderBoxPr/m:strikeV", "m:val") || "false");
|
|
592
|
+
const strikeBLTR = forceTrue(getAttr(element, "m:borderBoxPr/m:strikeBLTR", "m:val") || "false");
|
|
593
|
+
const strikeTLBR = forceTrue(getAttr(element, "m:borderBoxPr/m:strikeTLBR", "m:val") || "false");
|
|
594
|
+
let outer;
|
|
595
|
+
if (hideTop &&
|
|
596
|
+
hideBot &&
|
|
597
|
+
hideLeft &&
|
|
598
|
+
hideRight &&
|
|
599
|
+
!strikeH &&
|
|
600
|
+
!strikeV &&
|
|
601
|
+
!strikeBLTR &&
|
|
602
|
+
!strikeTLBR) {
|
|
603
|
+
outer = createMathElement("mrow", {}, parent);
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
const notation = createMEnclodeNotation({
|
|
607
|
+
hideTop,
|
|
608
|
+
hideBot,
|
|
609
|
+
hideLeft,
|
|
610
|
+
hideRight,
|
|
611
|
+
strikeH,
|
|
612
|
+
strikeV,
|
|
613
|
+
strikeBLTR,
|
|
614
|
+
strikeTLBR
|
|
615
|
+
});
|
|
616
|
+
outer = createMathElement("menclose", notation, parent);
|
|
617
|
+
}
|
|
618
|
+
const e = element.query("m:e");
|
|
619
|
+
if (e) {
|
|
620
|
+
processElement(e, outer);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Process a bar element
|
|
625
|
+
* @param {XMLElement} element - The OMML bar element
|
|
626
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
627
|
+
*/
|
|
628
|
+
function processBar(element, parent) {
|
|
629
|
+
const pos = (getAttr(element, "m:barPr/m:pos", "m:val") || "").toLowerCase();
|
|
630
|
+
if (pos === "top") {
|
|
631
|
+
const outer = createMathElement("mover", { accent: "false" }, parent);
|
|
632
|
+
const row = createMathElement("mrow", {}, outer);
|
|
633
|
+
const mo = createMathElement("mo", {}, outer);
|
|
634
|
+
const e = element.query("m:e");
|
|
635
|
+
if (e) {
|
|
636
|
+
processElement(e, row);
|
|
637
|
+
}
|
|
638
|
+
mo.textContent = "\u00af"; // Macron
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
const outer = createMathElement("munder", { underaccent: "false" }, parent);
|
|
642
|
+
const row = createMathElement("mrow", {}, outer);
|
|
643
|
+
const mo = createMathElement("mo", {}, outer);
|
|
644
|
+
const e = element.query("m:e");
|
|
645
|
+
if (e) {
|
|
646
|
+
processElement(e, row);
|
|
647
|
+
}
|
|
648
|
+
mo.textContent = "\u005f"; // Underscore
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Process a phantom element
|
|
653
|
+
* @param {XMLElement} element - The OMML phantom element
|
|
654
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
655
|
+
*/
|
|
656
|
+
function processPhantom(element, parent) {
|
|
657
|
+
const zeroWid = forceFalse(getAttr(element, "m:phantPr/m:zeroWid", "m:val") || "false");
|
|
658
|
+
const zeroAsc = forceFalse(getAttr(element, "m:phantPr/m:zeroAsc", "m:val") || "false");
|
|
659
|
+
const zeroDesc = forceFalse(getAttr(element, "m:phantPr/m:zeroDesc", "m:val") || "false");
|
|
660
|
+
const showVal = forceFalse(getAttr(element, "m:phantPr/m:show", "m:val") || "false");
|
|
661
|
+
let container;
|
|
662
|
+
if (showVal) {
|
|
663
|
+
container = createMathElement("mpadded", createMPaddedAttr({ zeroWid, zeroAsc, zeroDesc }), parent);
|
|
664
|
+
}
|
|
665
|
+
else if (!zeroWid && !zeroAsc && !zeroDesc) {
|
|
666
|
+
container = createMathElement("mphantom", {}, parent);
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
const phant = createMathElement("mphantom", {}, parent);
|
|
670
|
+
container = createMathElement("mpadded", createMPaddedAttr({ zeroWid, zeroAsc, zeroDesc }), phant);
|
|
671
|
+
}
|
|
672
|
+
const row = createMathElement("mrow", {}, container);
|
|
673
|
+
const e = element.query("m:e");
|
|
674
|
+
if (e) {
|
|
675
|
+
processElement(e, row);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Process an argument element
|
|
680
|
+
* @param {XMLElement} element - The OMML argument element
|
|
681
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
682
|
+
*/
|
|
683
|
+
function processArgument(element, parent) {
|
|
684
|
+
const scriptlevel = getAttr(element, "m:argPr/m:scrLvl", "m:val");
|
|
685
|
+
if (!scriptlevel) {
|
|
686
|
+
processChildren(element, parent);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
const style = createMathElement("mstyle", { scriptlevel }, parent);
|
|
690
|
+
processChildren(element, style);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Get attribute value from an element using a simplified XPath-like path
|
|
695
|
+
* @param {XMLElement} element - The element to query
|
|
696
|
+
* @param {string} path - The simplified path to the attribute
|
|
697
|
+
* @param {string} attrName - The attribute name
|
|
698
|
+
* @return {string} The attribute value or empty string
|
|
699
|
+
*/
|
|
700
|
+
function getAttr(element, path, attrName) {
|
|
701
|
+
if (!element) {
|
|
702
|
+
return "";
|
|
703
|
+
}
|
|
704
|
+
const parts = path.split("/");
|
|
705
|
+
let current = element;
|
|
706
|
+
for (let i = 0; i < parts.length; i++) {
|
|
707
|
+
if (!current) {
|
|
708
|
+
return "";
|
|
709
|
+
}
|
|
710
|
+
const part = parts[i];
|
|
711
|
+
if (part.includes("[last()]")) {
|
|
712
|
+
const tagName = part.replace("[last()]", "");
|
|
713
|
+
const elements = current.queryAll(tagName);
|
|
714
|
+
current = elements.length ? elements[elements.length - 1] : null;
|
|
715
|
+
}
|
|
716
|
+
else if (part.includes("[")) {
|
|
717
|
+
const match = part.match(/([^[]+)\[(\d+)\]/);
|
|
718
|
+
if (match) {
|
|
719
|
+
const tagName = match[1];
|
|
720
|
+
const index = parseInt(match[2], 10) - 1;
|
|
721
|
+
const elements = current.queryAll(tagName);
|
|
722
|
+
current = elements[index] || null;
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
current = current.query(part) || null;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
else {
|
|
729
|
+
current = current.query(part) || null;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return current ? current.getAttribute(attrName) || "" : "";
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Output a script element, or "none" if not provided
|
|
736
|
+
* @param {XMLElement} parent - The parent element
|
|
737
|
+
* @param {XMLElement} element - The script element to output
|
|
738
|
+
*/
|
|
739
|
+
function outputScript(parent, element) {
|
|
740
|
+
if (element) {
|
|
741
|
+
const row = createMathElement("mrow", {}, parent);
|
|
742
|
+
processElement(element, row);
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
createMathElement("none", {}, parent);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Output an n-ary operator
|
|
750
|
+
* @param {XMLElement} element - The OMML nary element
|
|
751
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
752
|
+
* @param {boolean} grow - Whether the operator should stretch
|
|
753
|
+
*/
|
|
754
|
+
function outputNAryMO(element, parent, grow = false) {
|
|
755
|
+
const mo = createMathElement("mo", { stretchy: grow ? "true" : "false" }, parent);
|
|
756
|
+
const val = getAttr(element, "m:naryPr/m:chr", "m:val");
|
|
757
|
+
mo.textContent = val || "\u222b"; // Integral symbol by default
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Create an equation array row
|
|
761
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
762
|
+
* @param {XMLElement} src - The source OMML element
|
|
763
|
+
* @param {XMLElement} cur - The current OMML element
|
|
764
|
+
* @param {number} align - Alignment indicator
|
|
765
|
+
*/
|
|
766
|
+
function createEqArrRow(parent, src, cur, align) {
|
|
767
|
+
if (!cur) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
if (cur.tagName === "m:r") {
|
|
771
|
+
const allMt = cur
|
|
772
|
+
.queryAll("m:t")
|
|
773
|
+
.map(t => t.textContent)
|
|
774
|
+
.join("");
|
|
775
|
+
const nor = forceFalse(getAttr(cur, "m:rPr/m:nor", "m:val") || "false");
|
|
776
|
+
parseEqArrMr(parent, {
|
|
777
|
+
toParse: allMt,
|
|
778
|
+
scr: getAttr(cur, "m:rPr/m:scr", "m:val"),
|
|
779
|
+
sty: getAttr(cur, "m:rPr/m:sty", "m:val"),
|
|
780
|
+
nor,
|
|
781
|
+
align
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
processElement(cur, parent);
|
|
786
|
+
}
|
|
787
|
+
// Get the next sibling if available
|
|
788
|
+
const siblings = cur.parentElement ? cur.parentElement.children : [];
|
|
789
|
+
const index = siblings.indexOf(cur);
|
|
790
|
+
const nextSibling = index < siblings.length - 1 ? siblings[index + 1] : null;
|
|
791
|
+
if (nextSibling) {
|
|
792
|
+
const allMt = cur
|
|
793
|
+
.queryAll("m:t")
|
|
794
|
+
.map(t => t.textContent)
|
|
795
|
+
.join("");
|
|
796
|
+
const amp = countAmp(allMt);
|
|
797
|
+
createEqArrRow(parent, src, nextSibling, (align + (amp % 2)) % 2);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
* Parse equation array run text
|
|
802
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
803
|
+
* @param {Object} options - Parsing options
|
|
804
|
+
*/
|
|
805
|
+
function parseEqArrMr(parent, { toParse = "", scr, sty, nor, align }) {
|
|
806
|
+
if (!toParse.length) {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
if (toParse[0] === "&") {
|
|
810
|
+
createMathElement(align ? "malignmark" : "maligngroup", {}, parent);
|
|
811
|
+
parseEqArrMr(parent, {
|
|
812
|
+
toParse: toParse.substr(1),
|
|
813
|
+
align: !align,
|
|
814
|
+
scr,
|
|
815
|
+
sty,
|
|
816
|
+
nor
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
const firstOper = rxIndexOf(toParse, oprx);
|
|
821
|
+
const firstNum = rxIndexOf(toParse, /\d/);
|
|
822
|
+
const startsWithOper = firstOper === 1;
|
|
823
|
+
const startsWithNum = firstNum === 1;
|
|
824
|
+
if (!startsWithOper && !startsWithNum) {
|
|
825
|
+
if (!nor) {
|
|
826
|
+
const mi = createMathElement("mi", tokenAttributes({
|
|
827
|
+
scr,
|
|
828
|
+
sty,
|
|
829
|
+
nor,
|
|
830
|
+
charToPrint: 1,
|
|
831
|
+
tokenType: "mi"
|
|
832
|
+
}), parent);
|
|
833
|
+
mi.textContent = nbsp(toParse.substr(0, 1));
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
const mt = createMathElement("mtext", {}, parent);
|
|
837
|
+
mt.textContent = nbsp(toParse.substr(0, 1));
|
|
838
|
+
}
|
|
839
|
+
parseEqArrMr(parent, {
|
|
840
|
+
toParse: toParse.substr(1),
|
|
841
|
+
scr,
|
|
842
|
+
sty,
|
|
843
|
+
nor,
|
|
844
|
+
align
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
else if (startsWithOper) {
|
|
848
|
+
if (!nor) {
|
|
849
|
+
const mo = createMathElement("mo", tokenAttributes({
|
|
850
|
+
nor,
|
|
851
|
+
charToPrint: 1,
|
|
852
|
+
tokenType: "mo"
|
|
853
|
+
}), parent);
|
|
854
|
+
mo.textContent = toParse.substr(0, 1);
|
|
855
|
+
}
|
|
856
|
+
else {
|
|
857
|
+
const mt = createMathElement("mtext", {}, parent);
|
|
858
|
+
mt.textContent = toParse.substr(0, 1);
|
|
859
|
+
}
|
|
860
|
+
parseEqArrMr(parent, {
|
|
861
|
+
toParse: toParse.substr(1),
|
|
862
|
+
scr,
|
|
863
|
+
sty,
|
|
864
|
+
nor,
|
|
865
|
+
align
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
else {
|
|
869
|
+
const num = numStart(toParse);
|
|
870
|
+
if (!nor) {
|
|
871
|
+
const mn = createMathElement("mn", tokenAttributes({
|
|
872
|
+
sty: "p",
|
|
873
|
+
nor,
|
|
874
|
+
charToPrint: 1,
|
|
875
|
+
tokenType: "mn"
|
|
876
|
+
}), parent);
|
|
877
|
+
mn.textContent = num;
|
|
878
|
+
}
|
|
879
|
+
else {
|
|
880
|
+
const mt = createMathElement("mtext", {}, parent);
|
|
881
|
+
mt.textContent = num;
|
|
882
|
+
}
|
|
883
|
+
parseEqArrMr(parent, {
|
|
884
|
+
toParse: toParse.substr(num.length),
|
|
885
|
+
scr,
|
|
886
|
+
sty,
|
|
887
|
+
nor,
|
|
888
|
+
align
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Parse math text
|
|
895
|
+
* @param {XMLElement} ctx - The context OMML element
|
|
896
|
+
* @param {XMLElement} parent - The parent MathML element
|
|
897
|
+
* @param {Object} options - Parsing options
|
|
898
|
+
*/
|
|
899
|
+
function parseMT(ctx, parent, { toParse = "", scr, sty, nor }) {
|
|
900
|
+
if (!toParse.length) {
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
const firstOper = rxIndexOf(toParse, oprx);
|
|
904
|
+
const firstNum = rxIndexOf(toParse, /\d/);
|
|
905
|
+
const startsWithOper = firstOper === 1;
|
|
906
|
+
const startsWithNum = firstNum === 1;
|
|
907
|
+
if (!startsWithOper && !startsWithNum) {
|
|
908
|
+
let charToPrint = 1;
|
|
909
|
+
// Check if we're in a function name
|
|
910
|
+
const inFuncName = ctx.closest("m:fName") !== null;
|
|
911
|
+
if (inFuncName) {
|
|
912
|
+
if (!firstOper && !firstNum) {
|
|
913
|
+
charToPrint = toParse.length;
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
charToPrint =
|
|
917
|
+
Math.min(firstOper || Number.MAX_VALUE, firstNum || Number.MAX_VALUE) - 1;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
const mi = createMathElement("mi", tokenAttributes({
|
|
921
|
+
scr,
|
|
922
|
+
sty,
|
|
923
|
+
nor,
|
|
924
|
+
charToPrint,
|
|
925
|
+
tokenType: "mi"
|
|
926
|
+
}), parent);
|
|
927
|
+
mi.textContent = nbsp(toParse.substr(0, charToPrint));
|
|
928
|
+
parseMT(ctx, parent, {
|
|
929
|
+
toParse: toParse.substr(charToPrint),
|
|
930
|
+
scr,
|
|
931
|
+
sty,
|
|
932
|
+
nor
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
else if (startsWithOper) {
|
|
936
|
+
const mo = createMathElement("mo", tokenAttributes({
|
|
937
|
+
nor,
|
|
938
|
+
tokenType: "mo"
|
|
939
|
+
}), parent);
|
|
940
|
+
mo.textContent = toParse.substr(0, 1);
|
|
941
|
+
parseMT(ctx, parent, {
|
|
942
|
+
toParse: toParse.substr(1),
|
|
943
|
+
scr,
|
|
944
|
+
sty,
|
|
945
|
+
nor
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
const num = numStart(toParse);
|
|
950
|
+
const mn = createMathElement("mn", tokenAttributes({
|
|
951
|
+
scr,
|
|
952
|
+
sty: "p",
|
|
953
|
+
nor,
|
|
954
|
+
tokenType: "mn"
|
|
955
|
+
}), parent);
|
|
956
|
+
mn.textContent = num;
|
|
957
|
+
parseMT(ctx, parent, {
|
|
958
|
+
toParse: toParse.substr(num.length),
|
|
959
|
+
scr,
|
|
960
|
+
sty,
|
|
961
|
+
nor
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Find the index of a regex match in a string
|
|
967
|
+
* @param {string} str - The string to search
|
|
968
|
+
* @param {RegExp} rx - The regex to match
|
|
969
|
+
* @return {number} The match index + 1, or 0 if no match
|
|
970
|
+
*/
|
|
971
|
+
function rxIndexOf(str, rx) {
|
|
972
|
+
const re = rx.exec(str);
|
|
973
|
+
if (!re) {
|
|
974
|
+
return 0;
|
|
975
|
+
}
|
|
976
|
+
return re.index + 1;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Get the start of a number in a string
|
|
980
|
+
* @param {string} str - The string to check
|
|
981
|
+
* @return {string} The number at the start of the string
|
|
982
|
+
*/
|
|
983
|
+
function numStart(str) {
|
|
984
|
+
if (!str) {
|
|
985
|
+
return "";
|
|
986
|
+
}
|
|
987
|
+
const match = str.match(/^(\d+)/);
|
|
988
|
+
return match ? match[1] : "";
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Count ampersands in a string
|
|
992
|
+
* @param {string} str - The string to check
|
|
993
|
+
* @return {number} The number of ampersands
|
|
994
|
+
*/
|
|
995
|
+
function countAmp(str) {
|
|
996
|
+
return ((str || "").match(/&/g) || []).length;
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Convert a combining character to its non-combining equivalent
|
|
1000
|
+
* @param {string} ch - The character to convert
|
|
1001
|
+
* @return {string} The non-combining equivalent
|
|
1002
|
+
*/
|
|
1003
|
+
function toNonCombining(ch) {
|
|
1004
|
+
const combiMap = {
|
|
1005
|
+
"\u0306": "\u02D8", // breve
|
|
1006
|
+
"\u032e": "\u02D8", // breve below
|
|
1007
|
+
"\u0312": "\u00B8", // cedilla
|
|
1008
|
+
"\u0327": "\u00B8", // cedilla
|
|
1009
|
+
"\u0300": "\u0060", // grave
|
|
1010
|
+
"\u0316": "\u0060", // grave below
|
|
1011
|
+
"\u0305": "\u002D", // macron/overbar
|
|
1012
|
+
"\u0332": "\u002D", // macron/underbar
|
|
1013
|
+
"\u0323": "\u002E", // dot below
|
|
1014
|
+
"\u0307": "\u02D9", // dot above
|
|
1015
|
+
"\u030B": "\u02DD", // double acute
|
|
1016
|
+
"\u0317": "\u00B4", // acute below
|
|
1017
|
+
"\u0301": "\u00B4", // acute
|
|
1018
|
+
"\u0330": "\u007E", // tilde below
|
|
1019
|
+
"\u0303": "\u007E", // tilde
|
|
1020
|
+
"\u0324": "\u00A8", // diaeresis below
|
|
1021
|
+
"\u0308": "\u00A8", // diaeresis
|
|
1022
|
+
"\u032C": "\u02C7", // caron below
|
|
1023
|
+
"\u030C": "\u02C7", // caron
|
|
1024
|
+
"\u0302": "\u005E", // circumflex
|
|
1025
|
+
"\u032D": "\u005E", // circumflex below
|
|
1026
|
+
"\u20D7": "\u2192", // vector/right arrow
|
|
1027
|
+
"\u20EF": "\u2192", // vector/right arrow below
|
|
1028
|
+
"\u20D6": "\u2190", // left arrow
|
|
1029
|
+
"\u20EE": "\u2190" // left arrow below
|
|
1030
|
+
};
|
|
1031
|
+
return combiMap[ch] || ch;
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Create MathML token attributes based on token settings
|
|
1035
|
+
* @param {Object} options - Token options
|
|
1036
|
+
* @return {Object} Attribute object
|
|
1037
|
+
*/
|
|
1038
|
+
function tokenAttributes({ scr, sty, nor, charToPrint = 0, tokenType }) {
|
|
1039
|
+
const attr = {};
|
|
1040
|
+
if (nor) {
|
|
1041
|
+
attr.mathvariant = "normal";
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
let mathvariant;
|
|
1045
|
+
const fontweight = sty === "b" || sty === "bi" ? "bold" : "normal";
|
|
1046
|
+
const fontstyle = sty === "b" || sty === "p" ? "normal" : "italic";
|
|
1047
|
+
if (tokenType !== "mn") {
|
|
1048
|
+
if (scr === "monospace") {
|
|
1049
|
+
mathvariant = "monospace";
|
|
1050
|
+
}
|
|
1051
|
+
else if (scr === "sans-serif" && sty === "i") {
|
|
1052
|
+
mathvariant = "sans-serif-italic";
|
|
1053
|
+
}
|
|
1054
|
+
else if (scr === "sans-serif" && sty === "b") {
|
|
1055
|
+
mathvariant = "bold-sans-serif";
|
|
1056
|
+
}
|
|
1057
|
+
else if (scr === "sans-serif" && sty === "bi") {
|
|
1058
|
+
mathvariant = "sans-serif-bold-italic";
|
|
1059
|
+
}
|
|
1060
|
+
else if (scr === "sans-serif") {
|
|
1061
|
+
mathvariant = "sans-serif";
|
|
1062
|
+
}
|
|
1063
|
+
else if (scr === "fraktur" && (sty === "b" || sty === "i")) {
|
|
1064
|
+
mathvariant = "bold-fraktur";
|
|
1065
|
+
}
|
|
1066
|
+
else if (scr === "fraktur") {
|
|
1067
|
+
mathvariant = "fraktur";
|
|
1068
|
+
}
|
|
1069
|
+
else if (scr === "double-struck") {
|
|
1070
|
+
mathvariant = "double-struck";
|
|
1071
|
+
}
|
|
1072
|
+
else if (scr === "script" && (sty === "b" || sty === "i")) {
|
|
1073
|
+
mathvariant = "bold-script";
|
|
1074
|
+
}
|
|
1075
|
+
else if (scr === "script") {
|
|
1076
|
+
mathvariant = "script";
|
|
1077
|
+
}
|
|
1078
|
+
else if (scr === "roman" || !scr) {
|
|
1079
|
+
if (sty === "b") {
|
|
1080
|
+
mathvariant = "bold";
|
|
1081
|
+
}
|
|
1082
|
+
else if (sty === "i") {
|
|
1083
|
+
mathvariant = "italic";
|
|
1084
|
+
}
|
|
1085
|
+
else if (sty === "p") {
|
|
1086
|
+
mathvariant = "normal";
|
|
1087
|
+
}
|
|
1088
|
+
else if (sty === "bi") {
|
|
1089
|
+
mathvariant = "bold-italic";
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
if (tokenType === "mo" && mathvariant !== "normal") {
|
|
1094
|
+
return attr;
|
|
1095
|
+
}
|
|
1096
|
+
if (tokenType === "mi" &&
|
|
1097
|
+
charToPrint === 1 &&
|
|
1098
|
+
(mathvariant === "italic" || !mathvariant)) {
|
|
1099
|
+
return attr;
|
|
1100
|
+
}
|
|
1101
|
+
if (tokenType === "mi" &&
|
|
1102
|
+
charToPrint > 1 &&
|
|
1103
|
+
(mathvariant === "italic" || !mathvariant)) {
|
|
1104
|
+
attr.mathvariant = "italic";
|
|
1105
|
+
}
|
|
1106
|
+
else if (mathvariant && mathvariant !== "italic") {
|
|
1107
|
+
attr.mathvariant = mathvariant;
|
|
1108
|
+
}
|
|
1109
|
+
else {
|
|
1110
|
+
if (fontstyle === "italic" &&
|
|
1111
|
+
!(tokenType === "mi" && charToPrint === 1)) {
|
|
1112
|
+
attr.fontstyle = "italic";
|
|
1113
|
+
}
|
|
1114
|
+
if (fontweight === "bold") {
|
|
1115
|
+
attr.fontweight = "bold";
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
return attr;
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Create menclose notation attribute value
|
|
1123
|
+
* @param {Object} options - Notation options
|
|
1124
|
+
* @return {Object} The notation attributes
|
|
1125
|
+
*/
|
|
1126
|
+
function createMEnclodeNotation({ hideTop, hideBot, hideLeft, hideRight, strikeH, strikeV, strikeBLTR, strikeTLBR }) {
|
|
1127
|
+
const notation = [];
|
|
1128
|
+
if (!hideTop && !hideBot && !hideLeft && !hideRight) {
|
|
1129
|
+
notation.push("box");
|
|
1130
|
+
}
|
|
1131
|
+
else {
|
|
1132
|
+
if (!hideTop) {
|
|
1133
|
+
notation.push("top");
|
|
1134
|
+
}
|
|
1135
|
+
if (!hideBot) {
|
|
1136
|
+
notation.push("bottom");
|
|
1137
|
+
}
|
|
1138
|
+
if (!hideLeft) {
|
|
1139
|
+
notation.push("left");
|
|
1140
|
+
}
|
|
1141
|
+
if (!hideRight) {
|
|
1142
|
+
notation.push("right");
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
if (strikeH) {
|
|
1146
|
+
notation.push("horizontalstrike");
|
|
1147
|
+
}
|
|
1148
|
+
if (strikeV) {
|
|
1149
|
+
notation.push("verticalstrike");
|
|
1150
|
+
}
|
|
1151
|
+
if (strikeBLTR) {
|
|
1152
|
+
notation.push("updiagonalstrike");
|
|
1153
|
+
}
|
|
1154
|
+
if (strikeTLBR) {
|
|
1155
|
+
notation.push("downdiagonalstrike");
|
|
1156
|
+
}
|
|
1157
|
+
return { notation: notation.join(" ") };
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Create mpadded attributes
|
|
1161
|
+
* @param {Object} options - Padding options
|
|
1162
|
+
* @return {Object} The padding attributes
|
|
1163
|
+
*/
|
|
1164
|
+
function createMPaddedAttr({ zeroWid, zeroAsc, zeroDesc }) {
|
|
1165
|
+
const attr = {};
|
|
1166
|
+
if (zeroWid) {
|
|
1167
|
+
attr.width = "0in";
|
|
1168
|
+
}
|
|
1169
|
+
if (zeroAsc) {
|
|
1170
|
+
attr.height = "0in";
|
|
1171
|
+
}
|
|
1172
|
+
if (zeroDesc) {
|
|
1173
|
+
attr.depth = "0in";
|
|
1174
|
+
}
|
|
1175
|
+
return attr;
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Get fraction properties
|
|
1179
|
+
* @param {string} type - Fraction type
|
|
1180
|
+
* @return {Object} Fraction attributes
|
|
1181
|
+
*/
|
|
1182
|
+
function getFracProps(type) {
|
|
1183
|
+
if (type === "skw" || type === "lin") {
|
|
1184
|
+
return { bevelled: "true" };
|
|
1185
|
+
}
|
|
1186
|
+
if (type === "nobar") {
|
|
1187
|
+
return { linethickness: "0pt" };
|
|
1188
|
+
}
|
|
1189
|
+
return {};
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Replace spaces with non-breaking spaces
|
|
1193
|
+
* @param {string} str - The string to process
|
|
1194
|
+
* @return {string} String with non-breaking spaces
|
|
1195
|
+
*/
|
|
1196
|
+
function nbsp(str) {
|
|
1197
|
+
if (!str) {
|
|
1198
|
+
return "";
|
|
1199
|
+
}
|
|
1200
|
+
return str.replace(/\s/g, "\u00a0");
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Parse a boolean value
|
|
1204
|
+
* @param {string} str - The string to parse
|
|
1205
|
+
* @return {boolean|undefined} The parsed boolean or undefined
|
|
1206
|
+
*/
|
|
1207
|
+
function tf(str) {
|
|
1208
|
+
if (str == null) {
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
str = str.toLowerCase();
|
|
1212
|
+
if (str === "on" || str === "1" || str === "true") {
|
|
1213
|
+
return true;
|
|
1214
|
+
}
|
|
1215
|
+
if (str === "off" || str === "0" || str === "false") {
|
|
1216
|
+
return false;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Force a value to be true unless explicitly false
|
|
1221
|
+
* @param {string} str - The string to parse
|
|
1222
|
+
* @return {boolean} True unless the string is explicitly false
|
|
1223
|
+
*/
|
|
1224
|
+
function forceFalse(str) {
|
|
1225
|
+
const res = tf(str);
|
|
1226
|
+
if (res === false) {
|
|
1227
|
+
return false;
|
|
1228
|
+
}
|
|
1229
|
+
return true;
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Force a value to be false unless explicitly true
|
|
1233
|
+
* @param {string} str - The string to parse
|
|
1234
|
+
* @return {boolean} False unless the string is explicitly true
|
|
1235
|
+
*/
|
|
1236
|
+
function forceTrue(str) {
|
|
1237
|
+
return tf(str) || false;
|
|
1238
|
+
}
|
|
1239
|
+
//# sourceMappingURL=omml2mathml.js.map
|