@fiduswriter/document 0.1.0-alpha.1

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.
Files changed (110) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +16 -0
  3. package/jest.config.js +23 -0
  4. package/package.json +59 -0
  5. package/schema.json +1 -0
  6. package/scripts/export-schema.js +16 -0
  7. package/src/bibliography/common.js +92 -0
  8. package/src/bibliography/csl_bib.js +139 -0
  9. package/src/citations/citeproc_sys.js +42 -0
  10. package/src/citations/format.js +194 -0
  11. package/src/common/blob.js +10 -0
  12. package/src/common/file.js +25 -0
  13. package/src/common/index.js +12 -0
  14. package/src/common/network.js +79 -0
  15. package/src/common/text.js +44 -0
  16. package/src/editor/e2ee/encryptor.js +228 -0
  17. package/src/exporter/docx/citations.js +177 -0
  18. package/src/exporter/docx/comments.js +165 -0
  19. package/src/exporter/docx/footnotes.js +240 -0
  20. package/src/exporter/docx/images.js +101 -0
  21. package/src/exporter/docx/index.js +185 -0
  22. package/src/exporter/docx/lists.js +260 -0
  23. package/src/exporter/docx/math.js +46 -0
  24. package/src/exporter/docx/metadata.js +289 -0
  25. package/src/exporter/docx/rels.js +193 -0
  26. package/src/exporter/docx/render.js +941 -0
  27. package/src/exporter/docx/richtext.js +1182 -0
  28. package/src/exporter/docx/tables.js +112 -0
  29. package/src/exporter/docx/tools.js +50 -0
  30. package/src/exporter/epub/index.js +142 -0
  31. package/src/exporter/epub/templates.js +140 -0
  32. package/src/exporter/epub/tools.js +96 -0
  33. package/src/exporter/html/citations.js +121 -0
  34. package/src/exporter/html/convert.js +813 -0
  35. package/src/exporter/html/index.js +192 -0
  36. package/src/exporter/html/templates.js +34 -0
  37. package/src/exporter/html/tools.js +50 -0
  38. package/src/exporter/jats/bibliography.js +183 -0
  39. package/src/exporter/jats/citations.js +109 -0
  40. package/src/exporter/jats/convert.js +871 -0
  41. package/src/exporter/jats/index.js +92 -0
  42. package/src/exporter/jats/templates.js +35 -0
  43. package/src/exporter/jats/text.js +72 -0
  44. package/src/exporter/latex/convert.js +934 -0
  45. package/src/exporter/latex/escape_latex.js +21 -0
  46. package/src/exporter/latex/index.js +74 -0
  47. package/src/exporter/latex/readme.js +22 -0
  48. package/src/exporter/native/shrink.js +132 -0
  49. package/src/exporter/odt/citations.js +101 -0
  50. package/src/exporter/odt/footnotes.js +147 -0
  51. package/src/exporter/odt/images.js +115 -0
  52. package/src/exporter/odt/index.js +156 -0
  53. package/src/exporter/odt/math.js +57 -0
  54. package/src/exporter/odt/metadata.js +251 -0
  55. package/src/exporter/odt/render.js +806 -0
  56. package/src/exporter/odt/richtext.js +865 -0
  57. package/src/exporter/odt/styles.js +387 -0
  58. package/src/exporter/odt/track.js +68 -0
  59. package/src/exporter/pandoc/citations.js +98 -0
  60. package/src/exporter/pandoc/convert.js +1017 -0
  61. package/src/exporter/pandoc/index.js +92 -0
  62. package/src/exporter/pandoc/readme.js +8 -0
  63. package/src/exporter/pandoc/tools.js +51 -0
  64. package/src/exporter/print/index.js +177 -0
  65. package/src/exporter/tools/doc_content.js +144 -0
  66. package/src/exporter/tools/file.js +9 -0
  67. package/src/exporter/tools/json.js +73 -0
  68. package/src/exporter/tools/svg.js +29 -0
  69. package/src/exporter/tools/xml.js +531 -0
  70. package/src/exporter/tools/xml_zip.js +95 -0
  71. package/src/exporter/tools/zip.js +90 -0
  72. package/src/exporter/tools/zotero_csl.js +93 -0
  73. package/src/importer/citations.js +129 -0
  74. package/src/importer/docx/citations.js +123 -0
  75. package/src/importer/docx/convert.js +1427 -0
  76. package/src/importer/docx/helpers.js +9 -0
  77. package/src/importer/docx/omml2mathml.js +1448 -0
  78. package/src/importer/docx/parse.js +735 -0
  79. package/src/importer/native/get_images.js +76 -0
  80. package/src/importer/native/update.js +29 -0
  81. package/src/importer/odt/citations.js +87 -0
  82. package/src/importer/odt/convert.js +1855 -0
  83. package/src/importer/pandoc/convert.js +884 -0
  84. package/src/importer/pandoc/helpers.js +84 -0
  85. package/src/importer/zip_analyzer.js +102 -0
  86. package/src/index.js +1 -0
  87. package/src/mathlive/opf_includes.js +24 -0
  88. package/src/schema/common/annotate.js +76 -0
  89. package/src/schema/common/base.js +118 -0
  90. package/src/schema/common/citation.js +62 -0
  91. package/src/schema/common/equation.js +31 -0
  92. package/src/schema/common/figure.js +190 -0
  93. package/src/schema/common/heading.js +43 -0
  94. package/src/schema/common/index.js +40 -0
  95. package/src/schema/common/list.js +95 -0
  96. package/src/schema/common/reference.js +100 -0
  97. package/src/schema/common/table.js +103 -0
  98. package/src/schema/common/track.js +190 -0
  99. package/src/schema/const.js +58 -0
  100. package/src/schema/convert.js +1272 -0
  101. package/src/schema/document/content.js +187 -0
  102. package/src/schema/document/index.js +117 -0
  103. package/src/schema/document/structure.js +452 -0
  104. package/src/schema/export.js +21 -0
  105. package/src/schema/footnotes.js +126 -0
  106. package/src/schema/footnotes_convert.js +31 -0
  107. package/src/schema/i18n.js +595 -0
  108. package/src/schema/index.js +5 -0
  109. package/src/schema/mini_json.js +61 -0
  110. package/src/schema/text.js +22 -0
@@ -0,0 +1,92 @@
1
+ import download from "downloadjs"
2
+ import pretty from "pretty"
3
+
4
+ import {shortFileTitle} from "../../common/index.js"
5
+ import {createSlug} from "../tools/file.js"
6
+ import {ZipFileCreator} from "../tools/zip.js"
7
+ import {JATSExporterConverter} from "./convert.js"
8
+ import {
9
+ articleTemplate,
10
+ bookPartWrapperTemplate,
11
+ darManifest
12
+ } from "./templates.js"
13
+ /*
14
+ Exporter to JATS
15
+ */
16
+
17
+ export class JATSExporter {
18
+ constructor(doc, bibDB, imageDB, csl, updated, type) {
19
+ this.doc = doc
20
+ this.docTitle = shortFileTitle(this.doc.title, this.doc.path)
21
+ this.bibDB = bibDB
22
+ this.imageDB = imageDB
23
+ this.csl = csl
24
+ this.updated = updated
25
+ this.type = type // "article", "book-part-wrapper" (for documents) or "book" (for document collections)
26
+
27
+ this.zipFileName = false
28
+ this.textFiles = []
29
+ this.httpFiles = []
30
+ }
31
+
32
+ init() {
33
+ const fileFormat = this.type === "article" ? "jats" : "bits"
34
+ this.zipFileName = `${createSlug(this.docTitle)}.${fileFormat}.zip`
35
+ this.converter = new JATSExporterConverter(
36
+ this.type,
37
+ this.doc,
38
+ this.csl,
39
+ this.imageDB,
40
+ this.bibDB
41
+ )
42
+ return this.converter.init().then(({front, body, back, imageIds}) => {
43
+ const jats =
44
+ this.type === "article"
45
+ ? articleTemplate({front, body, back})
46
+ : bookPartWrapperTemplate({front, body, back})
47
+ this.textFiles.push({
48
+ filename: "manuscript.xml",
49
+ contents: pretty(jats, {ocd: true})
50
+ })
51
+ const images = imageIds.map(id => {
52
+ const imageEntry = this.imageDB.db[id]
53
+ return {
54
+ title: imageEntry.title,
55
+ filename: imageEntry.image.split("/").pop(),
56
+ url: imageEntry.image
57
+ }
58
+ })
59
+ this.textFiles.push({
60
+ filename: "manifest.xml",
61
+ contents: pretty(
62
+ darManifest({
63
+ title: this.docTitle,
64
+ type: this.type,
65
+ images
66
+ }),
67
+ {ocd: true}
68
+ )
69
+ })
70
+ images.forEach(image => {
71
+ this.httpFiles.push({filename: image.filename, url: image.url})
72
+ })
73
+
74
+ return this.createZip()
75
+ })
76
+ }
77
+
78
+ createZip() {
79
+ const zipper = new ZipFileCreator(
80
+ this.textFiles,
81
+ this.httpFiles,
82
+ undefined,
83
+ undefined,
84
+ this.updated
85
+ )
86
+ return zipper.init().then(blob => this.download(blob))
87
+ }
88
+
89
+ download(blob) {
90
+ return download(blob, this.zipFileName, "application/zip")
91
+ }
92
+ }
@@ -0,0 +1,35 @@
1
+ import {escapeText, noSpaceTmp} from "../../common/index.js"
2
+
3
+ export const articleTemplate = ({front, body, back}) =>
4
+ `<?xml version="1.0" encoding="UTF-8"?>
5
+ <!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.3 20210610//EN" "https://jats.nlm.nih.gov/archiving/1.3/JATS-archivearticle1-3.dtd">
6
+ <article xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" xmlns:mml="http://www.w3.org/1998/Math/MathML">${front}${body}${back}</article>`
7
+
8
+ export const bookPartWrapperTemplate = ({front, body, back}) =>
9
+ `<?xml version="1.0" encoding="UTF-8"?>
10
+ <!DOCTYPE book-part-wrapper PUBLIC "-//NLM//DTD BITS Book Interchange DTD v2.1 20220202//EN" "https://jats.nlm.nih.gov/extensions/bits/2.1/BITS-book2-1.dtd">
11
+ <book-part-wrapper dtd-version="2.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/">
12
+ <book-part book-part-type="chapter" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ali="http://www.niso.org/schemas/ali/1.0/" xmlns:mml="http://www.w3.org/1998/Math/MathML">${front}${body}${back}</book-part>
13
+ </book-part-wrapper>`
14
+
15
+ export const darManifest = ({images, title, type}) =>
16
+ noSpaceTmp`<?xml version="1.0" encoding="UTF-8"?>
17
+ <!DOCTYPE manifest PUBLIC "DarManifest 0.1.0" "http://darformat.org/DarManifest-0.1.0.dtd">
18
+ <dar>
19
+ <!-- Generated by Fidus Writer -->
20
+ <documents>
21
+ <document id="manuscript" name="${escapeText(title)}" type="${type}" path="manuscript.xml" />
22
+ </documents>
23
+ <assets>${images
24
+ .map(
25
+ image =>
26
+ `<asset id="${image.filename.split(".")[0]}" mime-type="image/${
27
+ image.filename.split(".")[1] === "png"
28
+ ? "png"
29
+ : image.filename.split(".")[1] === "svg"
30
+ ? "svg+xml"
31
+ : "jpeg"
32
+ }" name="${image.title}" path="${image.filename}"/>`
33
+ )
34
+ .join("")}</assets>
35
+ </dar>`
@@ -0,0 +1,72 @@
1
+ import {escapeText} from "../../common/index.js"
2
+
3
+ export function convertTexts(nodeList) {
4
+ return nodeList.map(node => convertText(node)).join("")
5
+ }
6
+
7
+ export function convertText(node) {
8
+ let start = ""
9
+ let end = ""
10
+ let strong, em, underline, hyperlink, anchor, sup, sub, code
11
+ // Check for hyperlink, bold/strong, italic/em and underline
12
+ if (node.marks) {
13
+ strong = node.marks.find(mark => mark.type === "strong")
14
+ em = node.marks.find(mark => mark.type === "em")
15
+ underline = node.marks.find(mark => mark.type === "underline")
16
+ hyperlink = node.marks.find(mark => mark.type === "link")
17
+ anchor = node.marks.find(mark => mark.type === "anchor")
18
+ sup = node.marks.find(mark => mark.type === "sup")
19
+ sub = node.marks.find(mark => mark.type === "sub")
20
+ code = node.marks.find(mark => mark.type === "code")
21
+ }
22
+ let attrs = anchor ? ` id="${anchor.attrs.id}"` : ""
23
+ if (em) {
24
+ start += `<italic${attrs}>`
25
+ end = "</italic>" + end
26
+ attrs = ""
27
+ }
28
+ if (strong) {
29
+ start += `<bold${attrs}>`
30
+ end = "</bold>" + end
31
+ attrs = ""
32
+ }
33
+ if (underline) {
34
+ start += `<underline${attrs}>`
35
+ end = "</underline>" + end
36
+ attrs = ""
37
+ }
38
+ if (sup) {
39
+ start += `<sup${attrs}>`
40
+ end = "</sup>" + end
41
+ attrs = ""
42
+ }
43
+ if (sub) {
44
+ start += `<sub${attrs}>`
45
+ end = "</sub>" + end
46
+ attrs = ""
47
+ }
48
+ if (code) {
49
+ start += `<monospace${attrs}>`
50
+ end = "</monospace>" + end
51
+ attrs = ""
52
+ }
53
+ if (hyperlink) {
54
+ const href = hyperlink.attrs.href
55
+ if (href[0] === "#") {
56
+ // Internal link
57
+ start += `<xref rid="${href.substring(1)}"${attrs}>`
58
+ end = "</xref>" + end
59
+ } else {
60
+ // External link
61
+ start += `<ext-link xlink:href="${escapeText(href)}" ext-link-type="uri" xlink:title="${escapeText(hyperlink.attrs.title)}"${attrs}>`
62
+ end = "</ext-link>" + end
63
+ }
64
+ attrs = ""
65
+ }
66
+ if (attrs) {
67
+ start += `<named-content${attrs}>`
68
+ end = "</named-content>" + end
69
+ attrs = ""
70
+ }
71
+ return start + escapeText(node.text) + end
72
+ }