@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,777 @@
|
|
|
1
|
+
import { parseCSL } from "biblatex-csl-converter";
|
|
2
|
+
import { applyAnnotation, applyMarkToNodes, mergeTextNodes } from "./helpers.js";
|
|
3
|
+
export class PandocConvert {
|
|
4
|
+
constructor(doc, importId, template, bibliography) {
|
|
5
|
+
this.doc = doc;
|
|
6
|
+
this.importId = importId;
|
|
7
|
+
this.template = template;
|
|
8
|
+
this.bibliography = bibliography;
|
|
9
|
+
this.images = [];
|
|
10
|
+
this.language = this.doc.meta?.lang?.c?.[0]?.c || "en-US";
|
|
11
|
+
this.SMALL_IMAGE_THRESHOLD = 1.0; // Smaller images will be discarded (in inches)
|
|
12
|
+
}
|
|
13
|
+
init() {
|
|
14
|
+
try {
|
|
15
|
+
this.validatePandocFormat();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
console.error("Pandoc format validation failed:", error);
|
|
19
|
+
throw new Error("Invalid Pandoc document format: " + error.message);
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
content: this.convert(),
|
|
23
|
+
settings: {
|
|
24
|
+
import_id: this.importId,
|
|
25
|
+
tracked: false,
|
|
26
|
+
language: this.language
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
validatePandocFormat() {
|
|
31
|
+
// Check API version (Pandoc uses [major, minor, patch] or [major, minor, patch, tweak])
|
|
32
|
+
if (!Array.isArray(this.doc["pandoc-api-version"]) ||
|
|
33
|
+
this.doc["pandoc-api-version"].length < 3 ||
|
|
34
|
+
!this.doc["pandoc-api-version"].every(num => typeof num === "number")) {
|
|
35
|
+
throw new Error("Invalid or missing Pandoc API version");
|
|
36
|
+
}
|
|
37
|
+
// Check for required top-level properties
|
|
38
|
+
if (!this.doc.blocks || !Array.isArray(this.doc.blocks)) {
|
|
39
|
+
throw new Error("Missing or invalid blocks property");
|
|
40
|
+
}
|
|
41
|
+
// Check meta property structure if it exists
|
|
42
|
+
if (this.doc.meta && typeof this.doc.meta !== "object") {
|
|
43
|
+
throw new Error("Invalid meta property");
|
|
44
|
+
}
|
|
45
|
+
// Basic validation of block structure
|
|
46
|
+
if (!this.doc.blocks.every(block => block &&
|
|
47
|
+
typeof block === "object" &&
|
|
48
|
+
typeof block.t === "string" &&
|
|
49
|
+
("c" in block || block.t === "Null"))) {
|
|
50
|
+
throw new Error("Invalid block structure");
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
convert() {
|
|
55
|
+
const templateParts = this.template.content.content.slice();
|
|
56
|
+
templateParts.shift();
|
|
57
|
+
// Create the outer document structure
|
|
58
|
+
const document = {
|
|
59
|
+
type: "doc",
|
|
60
|
+
attrs: {
|
|
61
|
+
import_id: this.importId
|
|
62
|
+
},
|
|
63
|
+
content: []
|
|
64
|
+
};
|
|
65
|
+
// Add title (required first element)
|
|
66
|
+
document.content.push({
|
|
67
|
+
type: "title",
|
|
68
|
+
content: this.convertInlines(this.doc.meta?.title?.c || [{ t: "Str", c: "Untitled" }])
|
|
69
|
+
});
|
|
70
|
+
// Add subtitle if present
|
|
71
|
+
if (this.doc.meta?.subtitle?.c) {
|
|
72
|
+
const templatePart = templateParts.find(part => part.attrs.metadata === "subtitle");
|
|
73
|
+
document.content.push({
|
|
74
|
+
type: "heading_part",
|
|
75
|
+
attrs: {
|
|
76
|
+
title: templatePart ? templatePart.attrs.title : "Subtitle",
|
|
77
|
+
id: templatePart ? templatePart.attrs.id : "subtitle",
|
|
78
|
+
metadata: "subtitle"
|
|
79
|
+
},
|
|
80
|
+
content: [
|
|
81
|
+
{
|
|
82
|
+
type: "heading1",
|
|
83
|
+
attrs: {
|
|
84
|
+
id: "H" + Math.random().toString(36).substr(2, 7)
|
|
85
|
+
},
|
|
86
|
+
content: this.convertInlines(this.doc.meta.subtitle.c)
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// Add authors if present
|
|
92
|
+
if (this.doc.meta?.author?.c) {
|
|
93
|
+
const templatePart = templateParts.find(part => part.attrs.metadata === "authors");
|
|
94
|
+
document.content.push({
|
|
95
|
+
type: "contributors_part",
|
|
96
|
+
attrs: {
|
|
97
|
+
title: templatePart ? templatePart.attrs.title : "Authors",
|
|
98
|
+
id: templatePart ? templatePart.attrs.id : "authors",
|
|
99
|
+
metadata: "authors"
|
|
100
|
+
},
|
|
101
|
+
content: this.doc.meta.author.c.map(author => ({
|
|
102
|
+
type: "contributor",
|
|
103
|
+
attrs: this.convertContributor(author)
|
|
104
|
+
}))
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// Add abstract if present
|
|
108
|
+
if (this.doc.meta?.abstract?.c) {
|
|
109
|
+
const templatePart = templateParts.find(part => part.attrs.metadata === "abstract");
|
|
110
|
+
document.content.push({
|
|
111
|
+
type: "richtext_part",
|
|
112
|
+
attrs: {
|
|
113
|
+
title: templatePart
|
|
114
|
+
? templatePart.attrs.title
|
|
115
|
+
: gettext("Abstract"),
|
|
116
|
+
id: templatePart ? templatePart.attrs.id : "abstract",
|
|
117
|
+
metadata: "abstract"
|
|
118
|
+
},
|
|
119
|
+
content: this.convertBlocks(this.doc.meta.abstract.c)
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const templatePart = templateParts.find(part => !part.attrs.metadata && part.type === "richtext_part");
|
|
123
|
+
// Add main body content
|
|
124
|
+
document.content.push({
|
|
125
|
+
type: "richtext_part",
|
|
126
|
+
attrs: {
|
|
127
|
+
title: templatePart ? templatePart.attrs.title : "Body",
|
|
128
|
+
id: templatePart ? templatePart.attrs.id : "body",
|
|
129
|
+
marks: ["strong", "em", "link"]
|
|
130
|
+
},
|
|
131
|
+
content: this.convertBlocks(this.doc.blocks)
|
|
132
|
+
});
|
|
133
|
+
return document;
|
|
134
|
+
}
|
|
135
|
+
convertContributor(author) {
|
|
136
|
+
const attrs = {
|
|
137
|
+
firstname: "",
|
|
138
|
+
lastname: "",
|
|
139
|
+
email: "",
|
|
140
|
+
institution: ""
|
|
141
|
+
};
|
|
142
|
+
// Extract name components
|
|
143
|
+
if (author.c) {
|
|
144
|
+
const textParts = author.c
|
|
145
|
+
.filter(part => part.t === "Str")
|
|
146
|
+
.map(part => part.c);
|
|
147
|
+
if (textParts.length > 1) {
|
|
148
|
+
attrs.lastname = textParts.pop();
|
|
149
|
+
attrs.firstname = textParts.join(" ");
|
|
150
|
+
}
|
|
151
|
+
else if (textParts.length === 1) {
|
|
152
|
+
attrs.lastname = textParts[0];
|
|
153
|
+
}
|
|
154
|
+
// Extract email from notes if present
|
|
155
|
+
const note = author.c.find(part => part.t === "Note");
|
|
156
|
+
if (note) {
|
|
157
|
+
attrs.email = this.convertInlines(note.c[0].c)
|
|
158
|
+
.map(node => node.text)
|
|
159
|
+
.join("");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return attrs;
|
|
163
|
+
}
|
|
164
|
+
convertBlocks(blocks) {
|
|
165
|
+
if (!blocks) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
return blocks
|
|
169
|
+
.map(block => this.convertBlock(block))
|
|
170
|
+
.flat()
|
|
171
|
+
.filter(block => block);
|
|
172
|
+
}
|
|
173
|
+
convertBlock(block) {
|
|
174
|
+
switch (block.t) {
|
|
175
|
+
case "CodeBlock": {
|
|
176
|
+
const [attrs, code] = block.c;
|
|
177
|
+
// attrs structure: [id, classes, keyValuePairs]
|
|
178
|
+
// Example: ["ref-label", ["python3"], [["caption", "The Caption"], ["linenos", ""]]]
|
|
179
|
+
const id = attrs?.[0] || "";
|
|
180
|
+
const language = attrs?.[1]?.[0] || ""; // First class is language
|
|
181
|
+
const keyValuePairs = attrs?.[2] || [];
|
|
182
|
+
// Extract caption and category from key-value pairs
|
|
183
|
+
let title = "";
|
|
184
|
+
let category = "";
|
|
185
|
+
const captionPair = keyValuePairs.find(pair => pair[0] === "caption");
|
|
186
|
+
if (captionPair) {
|
|
187
|
+
title = captionPair[1];
|
|
188
|
+
}
|
|
189
|
+
const categoryPair = keyValuePairs.find(pair => pair[0] === "category");
|
|
190
|
+
if (categoryPair) {
|
|
191
|
+
category = categoryPair[1];
|
|
192
|
+
}
|
|
193
|
+
else if (title) {
|
|
194
|
+
// If there's a caption but no explicit category, default to 'listing'
|
|
195
|
+
// This makes the code block referenceable and properly numbered
|
|
196
|
+
category = "listing";
|
|
197
|
+
}
|
|
198
|
+
return [
|
|
199
|
+
{
|
|
200
|
+
type: "code_block",
|
|
201
|
+
attrs: {
|
|
202
|
+
track: [],
|
|
203
|
+
language: language,
|
|
204
|
+
category: category,
|
|
205
|
+
title: title,
|
|
206
|
+
id: id
|
|
207
|
+
},
|
|
208
|
+
content: [{ type: "text", text: code }]
|
|
209
|
+
}
|
|
210
|
+
];
|
|
211
|
+
}
|
|
212
|
+
case "Div":
|
|
213
|
+
// Handle special figure containers
|
|
214
|
+
if (block.attr?.classes?.includes("figure")) {
|
|
215
|
+
return this.convertFigure(block);
|
|
216
|
+
}
|
|
217
|
+
// Ignore otherwise. Could be bibliography
|
|
218
|
+
// or other non-content block
|
|
219
|
+
return [];
|
|
220
|
+
case "Para":
|
|
221
|
+
case "Plain": {
|
|
222
|
+
// Process each inline, splitting into paragraphs and figures
|
|
223
|
+
const blocks = [];
|
|
224
|
+
let currentInlines = [];
|
|
225
|
+
for (const inline of block.c) {
|
|
226
|
+
if (inline.t === "Image") {
|
|
227
|
+
// Convert accumulated inlines to a paragraph
|
|
228
|
+
if (currentInlines.length > 0) {
|
|
229
|
+
blocks.push({
|
|
230
|
+
type: "paragraph",
|
|
231
|
+
content: this.convertInlines(currentInlines)
|
|
232
|
+
});
|
|
233
|
+
currentInlines = [];
|
|
234
|
+
}
|
|
235
|
+
// Convert image to figure and add as block
|
|
236
|
+
const figure = this.convertInline(inline);
|
|
237
|
+
blocks.push(figure);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
currentInlines.push(inline);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Add remaining inlines as a paragraph
|
|
244
|
+
if (currentInlines.length > 0) {
|
|
245
|
+
blocks.push({
|
|
246
|
+
type: "paragraph",
|
|
247
|
+
content: this.convertInlines(currentInlines)
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
return blocks;
|
|
251
|
+
}
|
|
252
|
+
case "Header":
|
|
253
|
+
return [
|
|
254
|
+
{
|
|
255
|
+
type: `heading${block.c[0]}`,
|
|
256
|
+
attrs: {
|
|
257
|
+
id: block.c[1][0]
|
|
258
|
+
},
|
|
259
|
+
content: this.convertInlines(block.c[2])
|
|
260
|
+
}
|
|
261
|
+
];
|
|
262
|
+
case "BlockQuote":
|
|
263
|
+
return [
|
|
264
|
+
{
|
|
265
|
+
type: "blockquote",
|
|
266
|
+
content: this.convertBlocks(block.c)
|
|
267
|
+
}
|
|
268
|
+
];
|
|
269
|
+
case "BulletList":
|
|
270
|
+
return [
|
|
271
|
+
{
|
|
272
|
+
type: "bullet_list",
|
|
273
|
+
content: block.c.map(item => ({
|
|
274
|
+
type: "list_item",
|
|
275
|
+
content: this.convertBlocks(item)
|
|
276
|
+
}))
|
|
277
|
+
}
|
|
278
|
+
];
|
|
279
|
+
case "DefinitionList": {
|
|
280
|
+
return block.c.flatMap(item => [
|
|
281
|
+
{
|
|
282
|
+
type: "paragraph",
|
|
283
|
+
content: applyMarkToNodes(this.convertInlines(item.term), "strong")
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
type: "bullet_list",
|
|
287
|
+
content: item.definitions.map(def => ({
|
|
288
|
+
type: "list_item",
|
|
289
|
+
content: this.convertBlocks(def)
|
|
290
|
+
}))
|
|
291
|
+
}
|
|
292
|
+
]);
|
|
293
|
+
}
|
|
294
|
+
case "OrderedList":
|
|
295
|
+
return [
|
|
296
|
+
{
|
|
297
|
+
type: "ordered_list",
|
|
298
|
+
attrs: {
|
|
299
|
+
order: block.c[0][0]
|
|
300
|
+
},
|
|
301
|
+
content: block.c[1].map(item => ({
|
|
302
|
+
type: "list_item",
|
|
303
|
+
content: this.convertBlocks(item)
|
|
304
|
+
}))
|
|
305
|
+
}
|
|
306
|
+
];
|
|
307
|
+
case "Table":
|
|
308
|
+
return [this.convertTable(block)];
|
|
309
|
+
case "Figure":
|
|
310
|
+
return [this.convertFigure(block)];
|
|
311
|
+
default:
|
|
312
|
+
console.warn(`Unhandled block type: ${block.t}`);
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
convertInlines(inlines) {
|
|
317
|
+
if (!inlines) {
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
// Convert each inline element, flatten, and merge adjacent text nodes with same marks
|
|
321
|
+
const convertedNodes = inlines
|
|
322
|
+
.map(inline => this.convertInline(inline))
|
|
323
|
+
.filter(inline => inline)
|
|
324
|
+
.flat();
|
|
325
|
+
// Remove hard breaks at start and end
|
|
326
|
+
const filteredNodes = convertedNodes.filter((node, index, array) => {
|
|
327
|
+
if (node.type === "hard_break") {
|
|
328
|
+
// Remove if first or last node
|
|
329
|
+
if (index === 0 || index === array.length - 1) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return true;
|
|
334
|
+
});
|
|
335
|
+
return mergeTextNodes(filteredNodes);
|
|
336
|
+
}
|
|
337
|
+
convertInline(inline) {
|
|
338
|
+
if (!inline) {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
switch (inline.t) {
|
|
342
|
+
case "Cite":
|
|
343
|
+
return this.convertCitation(inline);
|
|
344
|
+
case "Image": {
|
|
345
|
+
const imagePath = inline.c[2][0];
|
|
346
|
+
const widthInfo = inline.c[0][2].find(attr => attr[0] === "width");
|
|
347
|
+
if (widthInfo) {
|
|
348
|
+
const width = parseFloat(widthInfo[1]); // in inches
|
|
349
|
+
if (width < this.SMALL_IMAGE_THRESHOLD) {
|
|
350
|
+
console.warn(`Skipping small decorative image: ${imagePath} (width: ${width}%)`);
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const imageId = Math.floor(Math.random() * 1000000);
|
|
355
|
+
const imageTitle = imagePath.split("/").pop();
|
|
356
|
+
// Skip small decorative images
|
|
357
|
+
// Store image reference
|
|
358
|
+
this.images[imageId] = {
|
|
359
|
+
id: imageId,
|
|
360
|
+
title: imageTitle,
|
|
361
|
+
copyright: {
|
|
362
|
+
holder: false,
|
|
363
|
+
year: false,
|
|
364
|
+
freeToRead: true,
|
|
365
|
+
licenses: []
|
|
366
|
+
},
|
|
367
|
+
image: imagePath,
|
|
368
|
+
file_type: this.getImageFileType(imageTitle),
|
|
369
|
+
file: null,
|
|
370
|
+
checksum: 0
|
|
371
|
+
};
|
|
372
|
+
// Create a figure with optional caption
|
|
373
|
+
const caption = inline.c[1] || [];
|
|
374
|
+
let category = "none";
|
|
375
|
+
if (caption.length &&
|
|
376
|
+
["Figure", "Table", "Photo"].includes(caption[0].c)) {
|
|
377
|
+
category = caption[0].c.toLowerCase();
|
|
378
|
+
caption.shift(); // Category name, for example "Figure"
|
|
379
|
+
caption.shift(); // Space
|
|
380
|
+
caption.shift(); // Category number, for example "1:"
|
|
381
|
+
caption.shift(); // Space
|
|
382
|
+
}
|
|
383
|
+
const percentageWidth = this.extractImageWidth(inline.c[0][2]);
|
|
384
|
+
return {
|
|
385
|
+
type: "figure",
|
|
386
|
+
attrs: {
|
|
387
|
+
aligned: "center",
|
|
388
|
+
width: percentageWidth,
|
|
389
|
+
category,
|
|
390
|
+
caption: Boolean(caption.length)
|
|
391
|
+
},
|
|
392
|
+
content: [
|
|
393
|
+
{
|
|
394
|
+
type: "image",
|
|
395
|
+
attrs: {
|
|
396
|
+
image: imageId
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
type: "figure_caption",
|
|
401
|
+
content: this.convertInlines(caption)
|
|
402
|
+
}
|
|
403
|
+
]
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
case "Str":
|
|
407
|
+
return {
|
|
408
|
+
type: "text",
|
|
409
|
+
text: inline.c
|
|
410
|
+
};
|
|
411
|
+
case "Space":
|
|
412
|
+
return {
|
|
413
|
+
type: "text",
|
|
414
|
+
text: " "
|
|
415
|
+
};
|
|
416
|
+
case "Strong": {
|
|
417
|
+
const innerNodes = this.convertInlines(inline.c);
|
|
418
|
+
return mergeTextNodes(applyMarkToNodes(innerNodes, "strong"));
|
|
419
|
+
}
|
|
420
|
+
case "Emph": {
|
|
421
|
+
const innerNodes = this.convertInlines(inline.c);
|
|
422
|
+
return mergeTextNodes(applyMarkToNodes(innerNodes, "em"));
|
|
423
|
+
}
|
|
424
|
+
case "Underline": {
|
|
425
|
+
const innerNodes = this.convertInlines(inline.c);
|
|
426
|
+
return mergeTextNodes(applyMarkToNodes(innerNodes, "underline"));
|
|
427
|
+
}
|
|
428
|
+
case "Strikeout": {
|
|
429
|
+
const inner = this.convertInlines(inline.c);
|
|
430
|
+
return applyAnnotation(inner, "strikeout");
|
|
431
|
+
}
|
|
432
|
+
case "SmallCaps": {
|
|
433
|
+
const inner = this.convertInlines(inline.c);
|
|
434
|
+
return applyAnnotation(inner, "smallcaps");
|
|
435
|
+
}
|
|
436
|
+
case "Superscript": {
|
|
437
|
+
const innerNodes = this.convertInlines(inline.c);
|
|
438
|
+
return mergeTextNodes(applyMarkToNodes(innerNodes, "sup"));
|
|
439
|
+
}
|
|
440
|
+
case "Subscript": {
|
|
441
|
+
const innerNodes = this.convertInlines(inline.c);
|
|
442
|
+
return mergeTextNodes(applyMarkToNodes(innerNodes, "sub"));
|
|
443
|
+
}
|
|
444
|
+
case "Code": {
|
|
445
|
+
const text = inline.c[1];
|
|
446
|
+
return {
|
|
447
|
+
type: "text",
|
|
448
|
+
text: text,
|
|
449
|
+
marks: [{ type: "code" }]
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
case "Link": {
|
|
453
|
+
const innerNodes = this.convertInlines(inline.c[1]);
|
|
454
|
+
return mergeTextNodes(applyMarkToNodes(innerNodes, "link", { href: inline.c[2][0] }));
|
|
455
|
+
}
|
|
456
|
+
case "Note": {
|
|
457
|
+
if (inline.c.length === 1 &&
|
|
458
|
+
inline.c[0].t === "Para" &&
|
|
459
|
+
inline.c[0].c.length === 2 &&
|
|
460
|
+
inline.c[0].c[0].t === "Cite" &&
|
|
461
|
+
inline.c[0].c[1].t === "Str" &&
|
|
462
|
+
inline.c[0].c[1].c === ".") {
|
|
463
|
+
// This is a citation note rendered as a footnote.
|
|
464
|
+
return this.convertInline(inline.c[0].c[0]);
|
|
465
|
+
}
|
|
466
|
+
return {
|
|
467
|
+
type: "footnote",
|
|
468
|
+
attrs: {
|
|
469
|
+
footnote: this.convertBlocks(inline.c)
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
case "Math":
|
|
474
|
+
return {
|
|
475
|
+
type: "equation",
|
|
476
|
+
attrs: {
|
|
477
|
+
equation: inline.c[1]
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
case "Quoted": {
|
|
481
|
+
const type = inline.c[0].t === "SingleQuote" ? "single" : "double";
|
|
482
|
+
const quoteStart = type === "single" ? "‘" : "“"; // U+2018, U+201C
|
|
483
|
+
const quoteEnd = type === "single" ? "’" : "”"; // U+2019, U+201D
|
|
484
|
+
const innerNodes = this.convertInlines(inline.c[1]);
|
|
485
|
+
const quotedNodes = [
|
|
486
|
+
{ type: "text", text: quoteStart },
|
|
487
|
+
...innerNodes,
|
|
488
|
+
{ type: "text", text: quoteEnd }
|
|
489
|
+
];
|
|
490
|
+
return mergeTextNodes(quotedNodes);
|
|
491
|
+
}
|
|
492
|
+
case "RawBlock":
|
|
493
|
+
case "RawInline": {
|
|
494
|
+
return [
|
|
495
|
+
{
|
|
496
|
+
type: "text",
|
|
497
|
+
text: `[RAW CONTENT: ${inline.text}]`,
|
|
498
|
+
marks: [
|
|
499
|
+
{
|
|
500
|
+
type: "annotation_tag",
|
|
501
|
+
attrs: {
|
|
502
|
+
type: "raw",
|
|
503
|
+
key: inline.format,
|
|
504
|
+
value: ""
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
]
|
|
508
|
+
}
|
|
509
|
+
];
|
|
510
|
+
}
|
|
511
|
+
case "SoftBreak":
|
|
512
|
+
return { type: "text", text: " " };
|
|
513
|
+
case "LineBreak":
|
|
514
|
+
return { type: "hard_break" };
|
|
515
|
+
case "Span": {
|
|
516
|
+
// Check if this is a Zotero CSL citation
|
|
517
|
+
const attrs = inline.c[0][0];
|
|
518
|
+
if (attrs && attrs.startsWith("ZOTERO_ITEM CSL_CITATION")) {
|
|
519
|
+
try {
|
|
520
|
+
// Extract just the JSON portion
|
|
521
|
+
const jsonStr = attrs.replace("ZOTERO_ITEM CSL_CITATION ", "");
|
|
522
|
+
const lastBrace = jsonStr.lastIndexOf("}") + 1;
|
|
523
|
+
const cslData = JSON.parse(jsonStr.substring(0, lastBrace));
|
|
524
|
+
// Create citation references
|
|
525
|
+
const citations = cslData.citationItems.map(item => {
|
|
526
|
+
const id = String(item.itemData.id);
|
|
527
|
+
// find in bibliography
|
|
528
|
+
let [bibKey, _] = Object.entries(this.bibliography).find(([_key, entry]) => entry.entry_key === id) || [];
|
|
529
|
+
if (!bibKey) {
|
|
530
|
+
// Not yet present in bibliography. We'll parse the CSL data and add it.
|
|
531
|
+
const parseData = parseCSL({
|
|
532
|
+
[id]: item.itemData
|
|
533
|
+
});
|
|
534
|
+
const bibEntry = parseData["1"];
|
|
535
|
+
bibKey = `${Object.keys(this.bibliography).length + 1}`;
|
|
536
|
+
this.bibliography[bibKey] = bibEntry;
|
|
537
|
+
}
|
|
538
|
+
return {
|
|
539
|
+
id: bibKey,
|
|
540
|
+
prefix: item.prefix || "",
|
|
541
|
+
locator: item.locator || ""
|
|
542
|
+
};
|
|
543
|
+
});
|
|
544
|
+
return {
|
|
545
|
+
type: "citation",
|
|
546
|
+
attrs: {
|
|
547
|
+
format: "cite",
|
|
548
|
+
references: citations
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
console.warn("Failed to parse CSL citation:", error);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
// If not a citation or parsing failed, fall through to regular text
|
|
557
|
+
return this.convertInlines(inline.c[1]);
|
|
558
|
+
}
|
|
559
|
+
default:
|
|
560
|
+
console.warn(`Unhandled inline type: ${inline.t}`);
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
extractImageWidth(attrs) {
|
|
565
|
+
const widthAttr = attrs.find(attr => attr[0] === "width");
|
|
566
|
+
if (widthAttr) {
|
|
567
|
+
// Convert inch measurement to percentage (assuming max width is 8.5 inches)
|
|
568
|
+
const widthInInches = parseFloat(widthAttr[1]);
|
|
569
|
+
return Math.min(Math.round((widthInInches / 8.5) * 100), 100);
|
|
570
|
+
}
|
|
571
|
+
return 100; // default width
|
|
572
|
+
}
|
|
573
|
+
convertTable(table) {
|
|
574
|
+
const attrs = {
|
|
575
|
+
width: 100,
|
|
576
|
+
aligned: "center",
|
|
577
|
+
layout: "fixed"
|
|
578
|
+
};
|
|
579
|
+
//c[0]: Attr
|
|
580
|
+
//c[0][0]: identifier
|
|
581
|
+
//c[0][1]: classes
|
|
582
|
+
//c[0][2]: key-value pairs
|
|
583
|
+
//c[1]: Caption
|
|
584
|
+
//c[1][0]: Caption
|
|
585
|
+
//c[1][1]: (Maybe ShortCaption)
|
|
586
|
+
//c[2]: [ColSpec] // per table column
|
|
587
|
+
//c[3]: TableHead
|
|
588
|
+
//c[3][0]: Attrs
|
|
589
|
+
//c[3][1]: Row
|
|
590
|
+
//c[4]: [TableBody]
|
|
591
|
+
//c[4][X][0]: Attr
|
|
592
|
+
//c[4][X][1]: RowHeadColumns
|
|
593
|
+
//c[4][X][2]: [Row]
|
|
594
|
+
//c[4][X][3]: [Row]
|
|
595
|
+
//c[5]: TableFoot
|
|
596
|
+
//c[5][0]: Attrs
|
|
597
|
+
//c[5][1]: Row
|
|
598
|
+
//Row
|
|
599
|
+
//c[0]: Attrs
|
|
600
|
+
//c[1]: [Cell]
|
|
601
|
+
//Cell
|
|
602
|
+
//c[0]: Attr
|
|
603
|
+
//c[1]: Alignment
|
|
604
|
+
//c[2]: RowSpan
|
|
605
|
+
//c[3]: ColSpan
|
|
606
|
+
//c[4]: [Block]
|
|
607
|
+
// Extract table attributes
|
|
608
|
+
const tableAttrs = table.c[0][2];
|
|
609
|
+
tableAttrs.forEach(attr => {
|
|
610
|
+
if (attr[0] === "width") {
|
|
611
|
+
attrs.width = parseInt(attr[1]);
|
|
612
|
+
}
|
|
613
|
+
else if (attr[0] === "aligned") {
|
|
614
|
+
attrs.aligned = attr[1];
|
|
615
|
+
}
|
|
616
|
+
else if (attr[0] === "layout") {
|
|
617
|
+
attrs.layout = attr[1];
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
const rows = table.c[3][1]
|
|
621
|
+
.concat(table.c[4]
|
|
622
|
+
.map(tableBody => tableBody[2].concat(tableBody[3]))
|
|
623
|
+
.flat())
|
|
624
|
+
.concat(table.c[5][1]);
|
|
625
|
+
const caption = table.c[1][0] || [];
|
|
626
|
+
return {
|
|
627
|
+
type: "table",
|
|
628
|
+
attrs,
|
|
629
|
+
content: [
|
|
630
|
+
{
|
|
631
|
+
type: "table_caption",
|
|
632
|
+
content: this.convertInlines(caption)
|
|
633
|
+
},
|
|
634
|
+
{
|
|
635
|
+
type: "table_body",
|
|
636
|
+
content: rows.map(row => ({
|
|
637
|
+
type: "table_row",
|
|
638
|
+
content: row[1].map(cell => {
|
|
639
|
+
const cellContent = this.convertBlocks(cell[4]);
|
|
640
|
+
if (cellContent.length === 0) {
|
|
641
|
+
cellContent.push({ type: "paragraph" });
|
|
642
|
+
}
|
|
643
|
+
return {
|
|
644
|
+
type: "table_cell",
|
|
645
|
+
attrs: {
|
|
646
|
+
colspan: cell[3],
|
|
647
|
+
rowspan: cell[2]
|
|
648
|
+
},
|
|
649
|
+
content: cellContent
|
|
650
|
+
};
|
|
651
|
+
})
|
|
652
|
+
}))
|
|
653
|
+
}
|
|
654
|
+
]
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
getImageFileType(filename) {
|
|
658
|
+
const ext = filename.split(".").pop().toLowerCase();
|
|
659
|
+
switch (ext) {
|
|
660
|
+
case "avif":
|
|
661
|
+
case "avifs":
|
|
662
|
+
return "image/avif";
|
|
663
|
+
case "png":
|
|
664
|
+
return "image/png";
|
|
665
|
+
case "jpg":
|
|
666
|
+
case "jpeg":
|
|
667
|
+
return "image/jpeg";
|
|
668
|
+
case "gif":
|
|
669
|
+
return "image/gif";
|
|
670
|
+
case "svg":
|
|
671
|
+
return "image/svg+xml";
|
|
672
|
+
case "webp":
|
|
673
|
+
return "image/webp";
|
|
674
|
+
default:
|
|
675
|
+
return "image/png"; // Default fallback
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
convertFigure(figure) {
|
|
679
|
+
const caption = figure.c[1][1];
|
|
680
|
+
const attrs = {
|
|
681
|
+
aligned: "center",
|
|
682
|
+
width: 100,
|
|
683
|
+
figureCategory: "none",
|
|
684
|
+
caption: Boolean(caption.length)
|
|
685
|
+
};
|
|
686
|
+
// Extract figure attributes
|
|
687
|
+
const figureAttrs = figure.c[0][2];
|
|
688
|
+
figureAttrs.forEach(attr => {
|
|
689
|
+
if (attr[0] === "width") {
|
|
690
|
+
attrs.width = parseInt(attr[1]);
|
|
691
|
+
}
|
|
692
|
+
else if (attr[0] === "aligned") {
|
|
693
|
+
attrs.aligned = attr[1];
|
|
694
|
+
}
|
|
695
|
+
else if (attr[0] === "category") {
|
|
696
|
+
attrs.figureCategory = attr[1];
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
const imagePath = figure.c[2][0].c[0].c[2][0];
|
|
700
|
+
const imageId = Math.floor(Math.random() * 1000000);
|
|
701
|
+
const imageTitle = imagePath.split("/").pop();
|
|
702
|
+
// Store image reference
|
|
703
|
+
this.images[imageId] = {
|
|
704
|
+
id: imageId,
|
|
705
|
+
title: imageTitle,
|
|
706
|
+
copyright: {
|
|
707
|
+
holder: false,
|
|
708
|
+
year: false,
|
|
709
|
+
freeToRead: true,
|
|
710
|
+
licenses: []
|
|
711
|
+
},
|
|
712
|
+
image: imagePath,
|
|
713
|
+
file_type: this.getImageFileType(imageTitle),
|
|
714
|
+
file: null,
|
|
715
|
+
checksum: 0
|
|
716
|
+
};
|
|
717
|
+
return {
|
|
718
|
+
type: "figure",
|
|
719
|
+
attrs,
|
|
720
|
+
content: [
|
|
721
|
+
{
|
|
722
|
+
type: "image",
|
|
723
|
+
attrs: {
|
|
724
|
+
image: imageId
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
type: "figure_caption",
|
|
729
|
+
content: this.convertBlocks(caption)
|
|
730
|
+
.map(block => block.content || [])
|
|
731
|
+
.flat()
|
|
732
|
+
}
|
|
733
|
+
]
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
convertCitation(cite) {
|
|
737
|
+
const references = cite.c[0]
|
|
738
|
+
.map(ref => {
|
|
739
|
+
// Handle empty bibliography case
|
|
740
|
+
if (!this.bibliography ||
|
|
741
|
+
Object.keys(this.bibliography).length === 0) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
const foundEntry = Object.entries(this.bibliography).find(([_id, definition]) => definition.entry_key === ref.citationId);
|
|
745
|
+
if (!foundEntry) {
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
const [bibId, _bibEntry] = foundEntry;
|
|
749
|
+
if (!bibId) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
return {
|
|
753
|
+
id: bibId,
|
|
754
|
+
prefix: ref.citationPrefix
|
|
755
|
+
.map(prefix => prefix.c)
|
|
756
|
+
.join(" "),
|
|
757
|
+
locator: ref.citationSuffix
|
|
758
|
+
.map(suffix => suffix.c)
|
|
759
|
+
.join(" ")
|
|
760
|
+
};
|
|
761
|
+
})
|
|
762
|
+
.filter(ref => ref);
|
|
763
|
+
if (!references.length) {
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
return {
|
|
767
|
+
type: "citation",
|
|
768
|
+
attrs: {
|
|
769
|
+
format: cite.c[0][0].citationMode.t === "AuthorInText"
|
|
770
|
+
? "textcite"
|
|
771
|
+
: "cite",
|
|
772
|
+
references
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
//# sourceMappingURL=convert.js.map
|