@manuscripts/transform 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +193 -0
  3. package/dist/cjs/errors.js +17 -0
  4. package/dist/cjs/index.js +27 -0
  5. package/dist/cjs/jats/importer/index.js +24 -0
  6. package/dist/cjs/jats/importer/jats-body-dom-parser.js +650 -0
  7. package/dist/cjs/jats/importer/jats-body-transformations.js +269 -0
  8. package/dist/cjs/jats/importer/jats-comments.js +131 -0
  9. package/dist/cjs/jats/importer/jats-front-parser.js +341 -0
  10. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +77 -0
  11. package/dist/cjs/jats/importer/jats-parser-utils.js +145 -0
  12. package/dist/cjs/jats/importer/jats-reference-parser.js +180 -0
  13. package/dist/cjs/jats/importer/parse-jats-article.js +237 -0
  14. package/dist/cjs/jats/index.js +40 -0
  15. package/dist/cjs/jats/jats-exporter.js +1569 -0
  16. package/dist/cjs/jats/jats-versions.js +41 -0
  17. package/dist/cjs/lib/attributes.js +26 -0
  18. package/dist/cjs/lib/html.js +48 -0
  19. package/dist/cjs/lib/styled-content.js +28 -0
  20. package/dist/cjs/lib/table-cell-styles.js +52 -0
  21. package/dist/cjs/lib/utils.js +66 -0
  22. package/dist/cjs/mathjax/index.js +41 -0
  23. package/dist/cjs/mathjax/mathjax-packages.js +20 -0
  24. package/dist/cjs/mathjax/mathml-to-svg.js +56 -0
  25. package/dist/cjs/mathjax/tex-to-mathml.js +49 -0
  26. package/dist/cjs/mathjax/tex-to-svg.js +59 -0
  27. package/dist/cjs/schema/groups.js +31 -0
  28. package/dist/cjs/schema/index.js +195 -0
  29. package/dist/cjs/schema/marks.js +159 -0
  30. package/dist/cjs/schema/nodes/attribution.js +32 -0
  31. package/dist/cjs/schema/nodes/bibliography_element.js +44 -0
  32. package/dist/cjs/schema/nodes/bibliography_item.js +101 -0
  33. package/dist/cjs/schema/nodes/bibliography_section.js +46 -0
  34. package/dist/cjs/schema/nodes/blockquote_element.js +62 -0
  35. package/dist/cjs/schema/nodes/caption.js +52 -0
  36. package/dist/cjs/schema/nodes/caption_title.js +51 -0
  37. package/dist/cjs/schema/nodes/citation.js +52 -0
  38. package/dist/cjs/schema/nodes/comment.js +26 -0
  39. package/dist/cjs/schema/nodes/cross_reference.js +58 -0
  40. package/dist/cjs/schema/nodes/doc.js +21 -0
  41. package/dist/cjs/schema/nodes/equation.js +55 -0
  42. package/dist/cjs/schema/nodes/equation_element.js +52 -0
  43. package/dist/cjs/schema/nodes/figcaption.js +31 -0
  44. package/dist/cjs/schema/nodes/figure.js +52 -0
  45. package/dist/cjs/schema/nodes/figure_element.js +78 -0
  46. package/dist/cjs/schema/nodes/footnote.js +67 -0
  47. package/dist/cjs/schema/nodes/footnotes_element.js +54 -0
  48. package/dist/cjs/schema/nodes/footnotes_section.js +45 -0
  49. package/dist/cjs/schema/nodes/graphical_abstract_section.js +46 -0
  50. package/dist/cjs/schema/nodes/hard_break.js +30 -0
  51. package/dist/cjs/schema/nodes/highlight_marker.js +53 -0
  52. package/dist/cjs/schema/nodes/inline_equation.js +58 -0
  53. package/dist/cjs/schema/nodes/inline_footnote.js +51 -0
  54. package/dist/cjs/schema/nodes/keywords_element.js +52 -0
  55. package/dist/cjs/schema/nodes/keywords_section.js +46 -0
  56. package/dist/cjs/schema/nodes/link.js +61 -0
  57. package/dist/cjs/schema/nodes/list.js +121 -0
  58. package/dist/cjs/schema/nodes/listing.js +73 -0
  59. package/dist/cjs/schema/nodes/listing_element.js +52 -0
  60. package/dist/cjs/schema/nodes/manuscript.js +46 -0
  61. package/dist/cjs/schema/nodes/missing_figure.js +50 -0
  62. package/dist/cjs/schema/nodes/paragraph.js +63 -0
  63. package/dist/cjs/schema/nodes/placeholder.js +49 -0
  64. package/dist/cjs/schema/nodes/placeholder_element.js +48 -0
  65. package/dist/cjs/schema/nodes/pullquote_element.js +65 -0
  66. package/dist/cjs/schema/nodes/section.js +94 -0
  67. package/dist/cjs/schema/nodes/section_label.js +30 -0
  68. package/dist/cjs/schema/nodes/section_title.js +48 -0
  69. package/dist/cjs/schema/nodes/table.js +70 -0
  70. package/dist/cjs/schema/nodes/table_col.js +57 -0
  71. package/dist/cjs/schema/nodes/table_element.js +62 -0
  72. package/dist/cjs/schema/nodes/table_row.js +123 -0
  73. package/dist/cjs/schema/nodes/text.js +21 -0
  74. package/dist/cjs/schema/nodes/toc_element.js +52 -0
  75. package/dist/cjs/schema/nodes/toc_section.js +46 -0
  76. package/dist/cjs/schema/types.js +17 -0
  77. package/dist/cjs/tests.js +30 -0
  78. package/dist/cjs/transformer/builders.js +305 -0
  79. package/dist/cjs/transformer/bundles-data.js +36 -0
  80. package/dist/cjs/transformer/bundles.js +32 -0
  81. package/dist/cjs/transformer/decode.js +619 -0
  82. package/dist/cjs/transformer/document-object-types.js +31 -0
  83. package/dist/cjs/transformer/encode.js +545 -0
  84. package/dist/cjs/transformer/filename.js +27 -0
  85. package/dist/cjs/transformer/footnote-category.js +20 -0
  86. package/dist/cjs/transformer/footnotes-order.js +59 -0
  87. package/dist/cjs/transformer/highlight-markers.js +126 -0
  88. package/dist/cjs/transformer/html.js +414 -0
  89. package/dist/cjs/transformer/id.js +28 -0
  90. package/dist/cjs/transformer/index.js +54 -0
  91. package/dist/cjs/transformer/labels.js +85 -0
  92. package/dist/cjs/transformer/manuscript-dependencies.js +74 -0
  93. package/dist/cjs/transformer/model-map.js +26 -0
  94. package/dist/cjs/transformer/models.js +17 -0
  95. package/dist/cjs/transformer/node-names.js +42 -0
  96. package/dist/cjs/transformer/node-title.js +87 -0
  97. package/dist/cjs/transformer/node-types.js +62 -0
  98. package/dist/cjs/transformer/object-types.js +57 -0
  99. package/dist/cjs/transformer/project-bundle.js +86 -0
  100. package/dist/cjs/transformer/section-category.js +222 -0
  101. package/dist/cjs/transformer/serializer.js +23 -0
  102. package/dist/cjs/transformer/shared-data.js +31 -0
  103. package/dist/cjs/transformer/tei-grobid-importer.js +121 -0
  104. package/dist/cjs/transformer/timestamp.js +20 -0
  105. package/dist/cjs/transformer/update-identifiers.js +93 -0
  106. package/dist/cjs/types.js +2 -0
  107. package/dist/es/errors.js +12 -0
  108. package/dist/es/index.js +9 -0
  109. package/dist/es/jats/importer/index.js +16 -0
  110. package/dist/es/jats/importer/jats-body-dom-parser.js +644 -0
  111. package/dist/es/jats/importer/jats-body-transformations.js +266 -0
  112. package/dist/es/jats/importer/jats-comments.js +124 -0
  113. package/dist/es/jats/importer/jats-front-parser.js +335 -0
  114. package/dist/es/jats/importer/jats-journal-meta-parser.js +70 -0
  115. package/dist/es/jats/importer/jats-parser-utils.js +139 -0
  116. package/dist/es/jats/importer/jats-reference-parser.js +177 -0
  117. package/dist/es/jats/importer/parse-jats-article.js +229 -0
  118. package/dist/es/jats/index.js +18 -0
  119. package/dist/es/jats/jats-exporter.js +1561 -0
  120. package/dist/es/jats/jats-versions.js +36 -0
  121. package/dist/es/lib/attributes.js +22 -0
  122. package/dist/es/lib/html.js +43 -0
  123. package/dist/es/lib/styled-content.js +23 -0
  124. package/dist/es/lib/table-cell-styles.js +47 -0
  125. package/dist/es/lib/utils.js +59 -0
  126. package/dist/es/mathjax/index.js +12 -0
  127. package/dist/es/mathjax/mathjax-packages.js +17 -0
  128. package/dist/es/mathjax/mathml-to-svg.js +52 -0
  129. package/dist/es/mathjax/tex-to-mathml.js +45 -0
  130. package/dist/es/mathjax/tex-to-svg.js +55 -0
  131. package/dist/es/schema/groups.js +27 -0
  132. package/dist/es/schema/index.js +178 -0
  133. package/dist/es/schema/marks.js +156 -0
  134. package/dist/es/schema/nodes/attribution.js +29 -0
  135. package/dist/es/schema/nodes/bibliography_element.js +41 -0
  136. package/dist/es/schema/nodes/bibliography_item.js +98 -0
  137. package/dist/es/schema/nodes/bibliography_section.js +42 -0
  138. package/dist/es/schema/nodes/blockquote_element.js +58 -0
  139. package/dist/es/schema/nodes/caption.js +49 -0
  140. package/dist/es/schema/nodes/caption_title.js +48 -0
  141. package/dist/es/schema/nodes/citation.js +48 -0
  142. package/dist/es/schema/nodes/comment.js +23 -0
  143. package/dist/es/schema/nodes/cross_reference.js +55 -0
  144. package/dist/es/schema/nodes/doc.js +18 -0
  145. package/dist/es/schema/nodes/equation.js +52 -0
  146. package/dist/es/schema/nodes/equation_element.js +49 -0
  147. package/dist/es/schema/nodes/figcaption.js +28 -0
  148. package/dist/es/schema/nodes/figure.js +49 -0
  149. package/dist/es/schema/nodes/figure_element.js +74 -0
  150. package/dist/es/schema/nodes/footnote.js +63 -0
  151. package/dist/es/schema/nodes/footnotes_element.js +50 -0
  152. package/dist/es/schema/nodes/footnotes_section.js +41 -0
  153. package/dist/es/schema/nodes/graphical_abstract_section.js +42 -0
  154. package/dist/es/schema/nodes/hard_break.js +27 -0
  155. package/dist/es/schema/nodes/highlight_marker.js +49 -0
  156. package/dist/es/schema/nodes/inline_equation.js +55 -0
  157. package/dist/es/schema/nodes/inline_footnote.js +47 -0
  158. package/dist/es/schema/nodes/keywords_element.js +49 -0
  159. package/dist/es/schema/nodes/keywords_section.js +42 -0
  160. package/dist/es/schema/nodes/link.js +58 -0
  161. package/dist/es/schema/nodes/list.js +117 -0
  162. package/dist/es/schema/nodes/listing.js +69 -0
  163. package/dist/es/schema/nodes/listing_element.js +49 -0
  164. package/dist/es/schema/nodes/manuscript.js +43 -0
  165. package/dist/es/schema/nodes/missing_figure.js +47 -0
  166. package/dist/es/schema/nodes/paragraph.js +59 -0
  167. package/dist/es/schema/nodes/placeholder.js +46 -0
  168. package/dist/es/schema/nodes/placeholder_element.js +45 -0
  169. package/dist/es/schema/nodes/pullquote_element.js +61 -0
  170. package/dist/es/schema/nodes/section.js +90 -0
  171. package/dist/es/schema/nodes/section_label.js +26 -0
  172. package/dist/es/schema/nodes/section_title.js +44 -0
  173. package/dist/es/schema/nodes/table.js +67 -0
  174. package/dist/es/schema/nodes/table_col.js +54 -0
  175. package/dist/es/schema/nodes/table_element.js +59 -0
  176. package/dist/es/schema/nodes/table_row.js +120 -0
  177. package/dist/es/schema/nodes/text.js +18 -0
  178. package/dist/es/schema/nodes/toc_element.js +49 -0
  179. package/dist/es/schema/nodes/toc_section.js +42 -0
  180. package/dist/es/schema/types.js +16 -0
  181. package/dist/es/tests.js +28 -0
  182. package/dist/es/transformer/builders.js +261 -0
  183. package/dist/es/transformer/bundles-data.js +8 -0
  184. package/dist/es/transformer/bundles.js +27 -0
  185. package/dist/es/transformer/decode.js +608 -0
  186. package/dist/es/transformer/document-object-types.js +28 -0
  187. package/dist/es/transformer/encode.js +535 -0
  188. package/dist/es/transformer/filename.js +23 -0
  189. package/dist/es/transformer/footnote-category.js +16 -0
  190. package/dist/es/transformer/footnotes-order.js +53 -0
  191. package/dist/es/transformer/highlight-markers.js +120 -0
  192. package/dist/es/transformer/html.js +407 -0
  193. package/dist/es/transformer/id.js +23 -0
  194. package/dist/es/transformer/index.js +38 -0
  195. package/dist/es/transformer/labels.js +81 -0
  196. package/dist/es/transformer/manuscript-dependencies.js +64 -0
  197. package/dist/es/transformer/model-map.js +22 -0
  198. package/dist/es/transformer/models.js +16 -0
  199. package/dist/es/transformer/node-names.js +39 -0
  200. package/dist/es/transformer/node-title.js +82 -0
  201. package/dist/es/transformer/node-types.js +55 -0
  202. package/dist/es/transformer/object-types.js +52 -0
  203. package/dist/es/transformer/project-bundle.js +77 -0
  204. package/dist/es/transformer/section-category.js +210 -0
  205. package/dist/es/transformer/serializer.js +17 -0
  206. package/dist/es/transformer/shared-data.js +1 -0
  207. package/dist/es/transformer/tei-grobid-importer.js +115 -0
  208. package/dist/es/transformer/timestamp.js +16 -0
  209. package/dist/es/transformer/update-identifiers.js +87 -0
  210. package/dist/es/types.js +1 -0
  211. package/dist/types/errors.d.ts +6 -0
  212. package/dist/types/index.d.ts +9 -0
  213. package/dist/types/jats/importer/index.d.ts +16 -0
  214. package/dist/types/jats/importer/jats-body-dom-parser.d.ts +24 -0
  215. package/dist/types/jats/importer/jats-body-transformations.d.ts +31 -0
  216. package/dist/types/jats/importer/jats-comments.d.ts +26 -0
  217. package/dist/types/jats/importer/jats-front-parser.d.ts +62 -0
  218. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +37 -0
  219. package/dist/types/jats/importer/jats-parser-utils.d.ts +23 -0
  220. package/dist/types/jats/importer/jats-reference-parser.d.ts +23 -0
  221. package/dist/types/jats/importer/parse-jats-article.d.ts +30 -0
  222. package/dist/types/jats/index.d.ts +18 -0
  223. package/dist/types/jats/jats-exporter.d.ts +72 -0
  224. package/dist/types/jats/jats-versions.d.ts +23 -0
  225. package/dist/types/lib/attributes.d.ts +20 -0
  226. package/dist/types/lib/html.d.ts +17 -0
  227. package/dist/types/lib/styled-content.d.ts +22 -0
  228. package/dist/types/lib/table-cell-styles.d.ts +27 -0
  229. package/dist/types/lib/utils.d.ts +26 -0
  230. package/dist/types/mathjax/index.d.ts +3 -0
  231. package/dist/types/mathjax/mathjax-packages.d.ts +16 -0
  232. package/dist/types/mathjax/mathml-to-svg.d.ts +17 -0
  233. package/dist/types/mathjax/tex-to-mathml.d.ts +17 -0
  234. package/dist/types/mathjax/tex-to-svg.d.ts +17 -0
  235. package/dist/types/schema/groups.d.ts +22 -0
  236. package/dist/types/schema/index.d.ts +65 -0
  237. package/dist/types/schema/marks.d.ts +27 -0
  238. package/dist/types/schema/nodes/attribution.d.ts +21 -0
  239. package/dist/types/schema/nodes/bibliography_element.d.ts +26 -0
  240. package/dist/types/schema/nodes/bibliography_item.d.ts +36 -0
  241. package/dist/types/schema/nodes/bibliography_section.d.ts +26 -0
  242. package/dist/types/schema/nodes/blockquote_element.d.ts +28 -0
  243. package/dist/types/schema/nodes/caption.d.ts +25 -0
  244. package/dist/types/schema/nodes/caption_title.d.ts +25 -0
  245. package/dist/types/schema/nodes/citation.d.ts +27 -0
  246. package/dist/types/schema/nodes/comment.d.ts +31 -0
  247. package/dist/types/schema/nodes/cross_reference.d.ts +26 -0
  248. package/dist/types/schema/nodes/doc.d.ts +17 -0
  249. package/dist/types/schema/nodes/equation.d.ts +28 -0
  250. package/dist/types/schema/nodes/equation_element.d.ts +29 -0
  251. package/dist/types/schema/nodes/figcaption.d.ts +21 -0
  252. package/dist/types/schema/nodes/figure.d.ts +25 -0
  253. package/dist/types/schema/nodes/figure_element.d.ts +44 -0
  254. package/dist/types/schema/nodes/footnote.d.ts +32 -0
  255. package/dist/types/schema/nodes/footnotes_element.d.ts +28 -0
  256. package/dist/types/schema/nodes/footnotes_section.d.ts +26 -0
  257. package/dist/types/schema/nodes/graphical_abstract_section.d.ts +26 -0
  258. package/dist/types/schema/nodes/hard_break.d.ts +21 -0
  259. package/dist/types/schema/nodes/highlight_marker.d.ts +29 -0
  260. package/dist/types/schema/nodes/inline_equation.d.ts +28 -0
  261. package/dist/types/schema/nodes/inline_footnote.d.ts +27 -0
  262. package/dist/types/schema/nodes/keywords_element.d.ts +27 -0
  263. package/dist/types/schema/nodes/keywords_section.d.ts +26 -0
  264. package/dist/types/schema/nodes/link.d.ts +26 -0
  265. package/dist/types/schema/nodes/list.d.ts +39 -0
  266. package/dist/types/schema/nodes/listing.d.ts +33 -0
  267. package/dist/types/schema/nodes/listing_element.d.ts +29 -0
  268. package/dist/types/schema/nodes/manuscript.d.ts +23 -0
  269. package/dist/types/schema/nodes/missing_figure.d.ts +23 -0
  270. package/dist/types/schema/nodes/paragraph.d.ts +30 -0
  271. package/dist/types/schema/nodes/placeholder.d.ts +26 -0
  272. package/dist/types/schema/nodes/placeholder_element.d.ts +25 -0
  273. package/dist/types/schema/nodes/pullquote_element.d.ts +28 -0
  274. package/dist/types/schema/nodes/section.d.ts +36 -0
  275. package/dist/types/schema/nodes/section_label.d.ts +22 -0
  276. package/dist/types/schema/nodes/section_title.d.ts +22 -0
  277. package/dist/types/schema/nodes/table.d.ts +27 -0
  278. package/dist/types/schema/nodes/table_col.d.ts +24 -0
  279. package/dist/types/schema/nodes/table_element.d.ts +35 -0
  280. package/dist/types/schema/nodes/table_row.d.ts +41 -0
  281. package/dist/types/schema/nodes/text.d.ts +17 -0
  282. package/dist/types/schema/nodes/toc_element.d.ts +27 -0
  283. package/dist/types/schema/nodes/toc_section.d.ts +26 -0
  284. package/dist/types/schema/types.d.ts +45 -0
  285. package/dist/types/tests.d.ts +16 -0
  286. package/dist/types/transformer/builders.d.ts +74 -0
  287. package/dist/types/transformer/bundles-data.d.ts +3 -0
  288. package/dist/types/transformer/bundles.d.ts +3 -0
  289. package/dist/types/transformer/decode.d.ts +38 -0
  290. package/dist/types/transformer/document-object-types.d.ts +17 -0
  291. package/dist/types/transformer/encode.d.ts +29 -0
  292. package/dist/types/transformer/filename.d.ts +16 -0
  293. package/dist/types/transformer/footnote-category.d.ts +17 -0
  294. package/dist/types/transformer/footnotes-order.d.ts +23 -0
  295. package/dist/types/transformer/highlight-markers.d.ts +26 -0
  296. package/dist/types/transformer/html.d.ts +36 -0
  297. package/dist/types/transformer/id.d.ts +20 -0
  298. package/dist/types/transformer/index.d.ts +38 -0
  299. package/dist/types/transformer/labels.d.ts +24 -0
  300. package/dist/types/transformer/manuscript-dependencies.d.ts +12 -0
  301. package/dist/types/transformer/model-map.d.ts +19 -0
  302. package/dist/types/transformer/models.d.ts +48 -0
  303. package/dist/types/transformer/node-names.d.ts +17 -0
  304. package/dist/types/transformer/node-title.d.ts +19 -0
  305. package/dist/types/transformer/node-types.d.ts +22 -0
  306. package/dist/types/transformer/object-types.d.ts +29 -0
  307. package/dist/types/transformer/project-bundle.d.ts +30 -0
  308. package/dist/types/transformer/section-category.d.ts +28 -0
  309. package/dist/types/transformer/serializer.d.ts +19 -0
  310. package/dist/types/transformer/shared-data.d.ts +2 -0
  311. package/dist/types/transformer/tei-grobid-importer.d.ts +20 -0
  312. package/dist/types/transformer/timestamp.d.ts +16 -0
  313. package/dist/types/transformer/update-identifiers.d.ts +23 -0
  314. package/dist/types/types.d.ts +2 -0
  315. package/package.json +89 -0
@@ -0,0 +1,335 @@
1
+ /*!
2
+ * © 2020 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import debug from 'debug';
17
+ import { buildAffiliation, buildBibliographicName, buildContributor, buildCorresp, buildFootnote, buildKeyword, buildKeywordGroup, buildSupplementaryMaterial, } from '../../transformer/builders';
18
+ import { createNewBundle, createParentBundle } from '../../transformer/bundles';
19
+ import { loadBundlesMap, loadIssnBundleIndex, } from '../../transformer/bundles-data';
20
+ import { parseJournalMeta } from './jats-journal-meta-parser';
21
+ const warn = debug('manuscripts-transform');
22
+ const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
23
+ const chooseBundle = async (issns) => {
24
+ const issnBundleIndex = await loadIssnBundleIndex();
25
+ for (const { ISSN } of issns) {
26
+ const normalizedIssn = ISSN.toUpperCase().replace(/[^0-9X]/g, '');
27
+ if (normalizedIssn in issnBundleIndex) {
28
+ return issnBundleIndex[normalizedIssn];
29
+ }
30
+ }
31
+ };
32
+ export const jatsFrontParser = {
33
+ async loadJournalBundles(issns) {
34
+ if (issns.length === 0) {
35
+ return {
36
+ manuscript_bundle: undefined,
37
+ bundleNodes: [],
38
+ };
39
+ }
40
+ const bundleID = await chooseBundle(issns);
41
+ const bundlesMap = bundleID ? await loadBundlesMap() : undefined;
42
+ const bundle = bundleID && bundlesMap ? createNewBundle(bundleID, bundlesMap) : undefined;
43
+ const parentBundle = bundle && bundleID && bundlesMap
44
+ ? createParentBundle(bundle, bundlesMap)
45
+ : undefined;
46
+ return {
47
+ manuscript_bundle: bundle === null || bundle === void 0 ? void 0 : bundle._id,
48
+ bundleNodes: [parentBundle, bundle].filter((v) => v !== undefined),
49
+ };
50
+ },
51
+ parseCounts(counts) {
52
+ var _a, _b, _c, _d, _e;
53
+ if (counts) {
54
+ const parseCount = (count) => {
55
+ if (count && /^-?\d+$/.test(count)) {
56
+ return parseInt(count);
57
+ }
58
+ else if (count) {
59
+ warn(`Invalid count number for ${count}`);
60
+ }
61
+ };
62
+ const genericCounts = [];
63
+ const countElements = counts.querySelectorAll('count');
64
+ for (const element of countElements.values()) {
65
+ const countType = element.getAttribute('count-type');
66
+ const count = parseCount(element.getAttribute('count'));
67
+ if (countType && typeof count === 'number') {
68
+ const genericCount = { count, countType };
69
+ genericCounts.push(genericCount);
70
+ }
71
+ }
72
+ return {
73
+ wordCount: parseCount((_a = counts.querySelector('word-count')) === null || _a === void 0 ? void 0 : _a.getAttribute('count')),
74
+ figureCount: parseCount((_b = counts.querySelector('fig-count')) === null || _b === void 0 ? void 0 : _b.getAttribute('count')),
75
+ tableCount: parseCount((_c = counts.querySelector('table-count')) === null || _c === void 0 ? void 0 : _c.getAttribute('count')),
76
+ equationCount: parseCount((_d = counts.querySelector('equation-count')) === null || _d === void 0 ? void 0 : _d.getAttribute('count')),
77
+ referencesCount: parseCount((_e = counts.querySelector('ref-count')) === null || _e === void 0 ? void 0 : _e.getAttribute('count')),
78
+ genericCounts: genericCounts.length > 0 ? genericCounts : undefined,
79
+ };
80
+ }
81
+ },
82
+ parseJournal(journalMeta) {
83
+ if (!journalMeta) {
84
+ return {
85
+ journalIdentifiers: [],
86
+ abbreviatedTitles: [],
87
+ ISSNs: [],
88
+ publisherName: undefined,
89
+ title: undefined,
90
+ };
91
+ }
92
+ return parseJournalMeta(journalMeta);
93
+ },
94
+ parseKeywords(keywordGroupNodes) {
95
+ var _a, _b;
96
+ if (!keywordGroupNodes) {
97
+ return { groups: [], keywords: [] };
98
+ }
99
+ let keywordPriority = 1;
100
+ const keywordGroups = { groups: [], keywords: [] };
101
+ for (const keywordGroupNode of keywordGroupNodes) {
102
+ const manuscriptKeywordGroup = buildKeywordGroup({
103
+ title: ((_a = keywordGroupNode.querySelector('title')) === null || _a === void 0 ? void 0 : _a.textContent) || undefined,
104
+ label: ((_b = keywordGroupNode.querySelector('label')) === null || _b === void 0 ? void 0 : _b.textContent) || undefined,
105
+ type: keywordGroupNode.getAttribute('kwd-group-type') || undefined,
106
+ });
107
+ keywordGroups.groups.push(manuscriptKeywordGroup);
108
+ for (const keywordNode of keywordGroupNode.querySelectorAll('kwd')) {
109
+ if (keywordNode.textContent) {
110
+ const keyword = buildKeyword(keywordNode.textContent);
111
+ keyword.priority = keywordPriority++;
112
+ keyword.containedGroup = manuscriptKeywordGroup._id;
113
+ keywordGroups.keywords.push(keyword);
114
+ }
115
+ }
116
+ }
117
+ return keywordGroups;
118
+ },
119
+ parseDates(historyNode) {
120
+ if (!historyNode) {
121
+ return undefined;
122
+ }
123
+ const history = {};
124
+ const dateToTimestamp = (dateElement) => {
125
+ var _a, _b;
126
+ const selectors = ['year', 'month', 'day'];
127
+ const values = [];
128
+ for (const selector of selectors) {
129
+ const value = (_b = (_a = dateElement.querySelector(selector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
130
+ if (!value || isNaN(+value)) {
131
+ return;
132
+ }
133
+ values.push(+value);
134
+ }
135
+ return Date.UTC(values[0], values[1], values[2]) / 1000;
136
+ };
137
+ for (const date of historyNode.children) {
138
+ const dateType = date.getAttribute('date-type');
139
+ switch (dateType) {
140
+ case 'received': {
141
+ history.receiveDate = dateToTimestamp(date);
142
+ break;
143
+ }
144
+ case 'rev-recd': {
145
+ history.revisionReceiveDate = dateToTimestamp(date);
146
+ break;
147
+ }
148
+ case 'accepted': {
149
+ history.acceptanceDate = dateToTimestamp(date);
150
+ break;
151
+ }
152
+ case 'rev-request': {
153
+ history.revisionRequestDate = dateToTimestamp(date);
154
+ break;
155
+ }
156
+ case 'retracted': {
157
+ history.retractionDate = dateToTimestamp(date);
158
+ break;
159
+ }
160
+ case 'corrected': {
161
+ history.correctionDate = dateToTimestamp(date);
162
+ break;
163
+ }
164
+ }
165
+ }
166
+ return history;
167
+ },
168
+ parseSupplements(supplementNodes) {
169
+ var _a, _b, _c, _d, _e;
170
+ if (!supplementNodes || supplementNodes.length === 0) {
171
+ return [];
172
+ }
173
+ const supplements = [];
174
+ for (const supplementNode of supplementNodes) {
175
+ const supplTitle = (_b = (_a = supplementNode.querySelector('caption > title')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '';
176
+ const href = (_c = supplementNode.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _c !== void 0 ? _c : '';
177
+ const supplementaryMaterial = buildSupplementaryMaterial(supplTitle, href);
178
+ const mimeType = (_d = supplementNode.getAttribute('mimetype')) !== null && _d !== void 0 ? _d : '';
179
+ const mimeSubtype = (_e = supplementNode.getAttribute('mime-subtype')) !== null && _e !== void 0 ? _e : '';
180
+ if (mimeType && mimeSubtype) {
181
+ supplementaryMaterial.MIME = [mimeType, mimeSubtype].join('/');
182
+ }
183
+ supplements.push(supplementaryMaterial);
184
+ }
185
+ return supplements;
186
+ },
187
+ parseAffiliationNodes(affiliationNodes) {
188
+ const affiliationIDs = new Map();
189
+ const affiliations = affiliationNodes.map((affiliationNode, priority) => {
190
+ var _a, _b, _c, _d, _e;
191
+ const affiliation = buildAffiliation('', priority);
192
+ for (const node of affiliationNode.querySelectorAll('institution')) {
193
+ const content = node.textContent;
194
+ if (!content) {
195
+ continue;
196
+ }
197
+ const contentType = node.getAttribute('content-type');
198
+ switch (contentType) {
199
+ case null:
200
+ affiliation.institution = content;
201
+ break;
202
+ case 'dept':
203
+ affiliation.department = content;
204
+ break;
205
+ }
206
+ }
207
+ affiliation.addressLine1 =
208
+ ((_a = affiliationNode.querySelector('addr-line:nth-of-type(1)')) === null || _a === void 0 ? void 0 : _a.textContent) || undefined;
209
+ affiliation.addressLine2 =
210
+ ((_b = affiliationNode.querySelector('addr-line:nth-of-type(2)')) === null || _b === void 0 ? void 0 : _b.textContent) || undefined;
211
+ affiliation.addressLine3 =
212
+ ((_c = affiliationNode.querySelector('addr-line:nth-of-type(3)')) === null || _c === void 0 ? void 0 : _c.textContent) || undefined;
213
+ const emailNode = affiliationNode.querySelector('email');
214
+ if (emailNode) {
215
+ affiliation.email = {
216
+ href: emailNode.getAttributeNS(XLINK_NAMESPACE, 'href') || undefined,
217
+ text: emailNode.textContent || undefined,
218
+ };
219
+ }
220
+ affiliation.postCode =
221
+ ((_d = affiliationNode.querySelector('postal-code')) === null || _d === void 0 ? void 0 : _d.textContent) || undefined;
222
+ affiliation.country =
223
+ ((_e = affiliationNode.querySelector('country')) === null || _e === void 0 ? void 0 : _e.textContent) || undefined;
224
+ const id = affiliationNode.getAttribute('id');
225
+ if (id) {
226
+ affiliationIDs.set(id, affiliation._id);
227
+ }
228
+ return affiliation;
229
+ });
230
+ return {
231
+ affiliations,
232
+ affiliationIDs,
233
+ };
234
+ },
235
+ parseFootnoteNodes(footnoteNodes) {
236
+ const footnoteIDs = new Map();
237
+ const footnotes = footnoteNodes.map((footnoteNode) => {
238
+ const fn = buildFootnote('', footnoteNode.innerHTML);
239
+ const id = footnoteNode.getAttribute('id');
240
+ if (id) {
241
+ footnoteIDs.set(id, fn._id);
242
+ }
243
+ return fn;
244
+ });
245
+ return {
246
+ footnotes,
247
+ footnoteIDs,
248
+ };
249
+ },
250
+ parseCorrespNodes(correspNodes) {
251
+ const correspondingIDs = new Map();
252
+ const correspondingList = correspNodes.map((correspNode) => {
253
+ var _a;
254
+ const label = correspNode.querySelector('label');
255
+ if (label) {
256
+ label.remove();
257
+ }
258
+ const corresponding = buildCorresp((_a = correspNode.textContent) !== null && _a !== void 0 ? _a : '');
259
+ corresponding.label = (label === null || label === void 0 ? void 0 : label.textContent) || undefined;
260
+ const id = correspNode.getAttribute('id');
261
+ if (id) {
262
+ correspondingIDs.set(id, corresponding._id);
263
+ }
264
+ return corresponding;
265
+ });
266
+ return {
267
+ correspondingList,
268
+ correspondingIDs,
269
+ };
270
+ },
271
+ parseAuthorNodes(authorNodes, affiliationIDs, footnoteIDs, correspondingIDs) {
272
+ return authorNodes.map((authorNode, priority) => {
273
+ var _a, _b, _c;
274
+ const name = buildBibliographicName({});
275
+ const given = (_a = authorNode.querySelector('name > given-names')) === null || _a === void 0 ? void 0 : _a.textContent;
276
+ if (given) {
277
+ name.given = given;
278
+ }
279
+ const surname = (_b = authorNode.querySelector('name > surname')) === null || _b === void 0 ? void 0 : _b.textContent;
280
+ if (surname) {
281
+ name.family = surname;
282
+ }
283
+ const contributor = buildContributor(name, 'author', priority);
284
+ const corresponding = authorNode.getAttribute('corresp') === 'yes';
285
+ if (corresponding) {
286
+ contributor.isCorresponding = corresponding;
287
+ }
288
+ const orcid = (_c = authorNode.querySelector('contrib-id[contrib-id-type="orcid"]')) === null || _c === void 0 ? void 0 : _c.textContent;
289
+ if (orcid) {
290
+ contributor.ORCIDIdentifier = orcid;
291
+ }
292
+ const xrefNodes = authorNode.querySelectorAll('xref');
293
+ for (const xrefNode of xrefNodes) {
294
+ if (xrefNode) {
295
+ const rid = xrefNode.getAttribute('rid');
296
+ const rtype = xrefNode.getAttribute('ref-type');
297
+ if (rid) {
298
+ if (rtype === 'fn') {
299
+ contributor.footnote = [];
300
+ const footnoteId = footnoteIDs.get(rid);
301
+ if (footnoteId) {
302
+ const authorFootNoteRef = {
303
+ noteID: footnoteId,
304
+ noteLabel: xrefNode.textContent || '',
305
+ };
306
+ contributor.footnote.push(authorFootNoteRef);
307
+ }
308
+ }
309
+ else if (rtype === 'corresp') {
310
+ contributor.corresp = [];
311
+ const correspId = correspondingIDs.get(rid);
312
+ if (correspId) {
313
+ const authorCorrespRef = {
314
+ correspID: correspId,
315
+ correspLabel: xrefNode.textContent || '',
316
+ };
317
+ contributor.corresp.push(authorCorrespRef);
318
+ }
319
+ }
320
+ else if (rtype === 'aff') {
321
+ const rids = rid
322
+ .split(/\s+/)
323
+ .filter((id) => affiliationIDs.has(id))
324
+ .map((id) => affiliationIDs.get(id));
325
+ if (rids.length) {
326
+ contributor.affiliations = rids;
327
+ }
328
+ }
329
+ }
330
+ }
331
+ }
332
+ return contributor;
333
+ });
334
+ },
335
+ };
@@ -0,0 +1,70 @@
1
+ /*!
2
+ * © 2020 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export const parseJournalIdentifiers = (journalMeta) => {
17
+ const output = [];
18
+ const elements = journalMeta.querySelectorAll('journal-id');
19
+ for (const element of elements) {
20
+ const journalIDType = element.getAttribute('journal-id-type');
21
+ const journalID = element.textContent;
22
+ if (journalID !== null && journalIDType != null) {
23
+ output.push({ journalIDType, journalID });
24
+ }
25
+ else if (journalID !== null) {
26
+ output.push({ journalID });
27
+ }
28
+ }
29
+ return output;
30
+ };
31
+ export const parseJournalAbbreviatedTitles = (journalMeta) => {
32
+ const output = [];
33
+ const elements = journalMeta.querySelectorAll('journal-title-group > abbrev-journal-title');
34
+ for (const element of elements) {
35
+ const abbrevType = element.getAttribute('abbrev-type');
36
+ const abbreviatedTitle = element.textContent;
37
+ if (abbreviatedTitle !== null && abbrevType !== null) {
38
+ output.push({ abbreviatedTitle, abbrevType });
39
+ }
40
+ else if (abbreviatedTitle !== null) {
41
+ output.push({ abbreviatedTitle });
42
+ }
43
+ }
44
+ return output;
45
+ };
46
+ export const parseJournalISSNs = (journalMeta) => {
47
+ const output = [];
48
+ const elements = journalMeta.querySelectorAll('issn');
49
+ for (const element of elements) {
50
+ const publicationType = element.getAttribute('pub-type');
51
+ const ISSN = element.textContent;
52
+ if (publicationType !== null && ISSN !== null) {
53
+ output.push({ publicationType, ISSN });
54
+ }
55
+ else if (ISSN !== null) {
56
+ output.push({ ISSN });
57
+ }
58
+ }
59
+ return output;
60
+ };
61
+ export const parseJournalMeta = (journalMeta) => {
62
+ var _a, _b, _c, _d;
63
+ return {
64
+ abbreviatedTitles: parseJournalAbbreviatedTitles(journalMeta),
65
+ journalIdentifiers: parseJournalIdentifiers(journalMeta),
66
+ ISSNs: parseJournalISSNs(journalMeta),
67
+ publisherName: (_b = (_a = journalMeta.querySelector('publisher > publisher-name')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : undefined,
68
+ title: (_d = (_c = journalMeta.querySelector('journal-title-group > journal-title')) === null || _c === void 0 ? void 0 : _c.textContent) !== null && _d !== void 0 ? _d : undefined,
69
+ };
70
+ };
@@ -0,0 +1,139 @@
1
+ /*!
2
+ * © 2020 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { ObjectTypes, } from '@manuscripts/manuscripts-json-schema';
17
+ import { generateID, hasObjectType, nodeTypesMap } from '../../transformer';
18
+ const isAuxiliaryObjectReference = hasObjectType(ObjectTypes.AuxiliaryObjectReference);
19
+ export function flatten(arrays) {
20
+ return [].concat(...arrays);
21
+ }
22
+ export const fixBodyPMNode = (output, models, referenceIdsMap = new Map()) => {
23
+ const replacements = referenceIdsMap;
24
+ const warnings = [];
25
+ recurseDoc(output, (n) => addMissingID(n, replacements, warnings));
26
+ recurseDoc(output, (n) => addMissingRID(n, replacements, warnings));
27
+ return {
28
+ warnings: [...warnings, ...fixReferences(models, replacements)],
29
+ replacements,
30
+ };
31
+ };
32
+ function recurseDoc(node, fn) {
33
+ fn(node);
34
+ if (node.content) {
35
+ node.content.forEach((n) => recurseDoc(n, fn));
36
+ }
37
+ }
38
+ const addMissingID = (node, replacements, warnings) => {
39
+ if (!('id' in node.attrs)) {
40
+ return;
41
+ }
42
+ const objectType = nodeTypesMap.get(node.type);
43
+ if (!objectType) {
44
+ warnings.push(`Unknown object type for node type ${node.type.name}`);
45
+ return;
46
+ }
47
+ const previousID = node.attrs.id;
48
+ const nextID = generateID(objectType);
49
+ if (previousID) {
50
+ if (replacements.has(previousID) ||
51
+ Array.from(replacements.values()).includes(previousID)) {
52
+ warnings.push(`node.attrs.id ${previousID} exists twice!`);
53
+ return;
54
+ }
55
+ replacements.set(previousID, nextID);
56
+ }
57
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { id: nextID });
58
+ };
59
+ const addMissingRID = (node, replacements, warnings) => {
60
+ const previousRID = node.attrs.rid;
61
+ if (!('rid' in node.attrs) || !previousRID) {
62
+ return;
63
+ }
64
+ if (!replacements.has(previousRID)) {
65
+ }
66
+ else {
67
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { rid: replacements.get(previousRID) });
68
+ }
69
+ };
70
+ const fixReferences = (models, replacements) => {
71
+ const warnings = [];
72
+ const getReferenceId = (referencedObject) => {
73
+ const newReferencedId = replacements.get(referencedObject);
74
+ if (newReferencedId) {
75
+ return newReferencedId;
76
+ }
77
+ else {
78
+ warnings.push(`Missing replacement for model.referencedObject ${referencedObject}`);
79
+ }
80
+ };
81
+ models.forEach((model) => {
82
+ var _a;
83
+ if (isAuxiliaryObjectReference(model)) {
84
+ if (model.referencedObject) {
85
+ model.referencedObject = getReferenceId(model.referencedObject);
86
+ }
87
+ else {
88
+ const referencedObjects = [];
89
+ (_a = model.referencedObjects) === null || _a === void 0 ? void 0 : _a.map((reference) => {
90
+ const referenceId = getReferenceId(reference);
91
+ if (referenceId) {
92
+ referencedObjects.push(referenceId);
93
+ }
94
+ });
95
+ model.referencedObjects = referencedObjects;
96
+ }
97
+ }
98
+ });
99
+ return warnings;
100
+ };
101
+ const JATS_TO_HTML_MAPPING = new Map([
102
+ ['bold', 'b'],
103
+ ['italic', 'i'],
104
+ ['sc', 'style'],
105
+ ['sub', 'sub'],
106
+ ['sup', 'sup'],
107
+ ]);
108
+ const renameJatsNodesToHTML = (node, container, createElement) => {
109
+ node.childNodes.forEach((childNode) => {
110
+ switch (childNode.nodeType) {
111
+ case Node.ELEMENT_NODE: {
112
+ const newNodeName = JATS_TO_HTML_MAPPING.get(childNode.nodeName);
113
+ if (newNodeName) {
114
+ const newNode = createElement(newNodeName);
115
+ renameJatsNodesToHTML(childNode, newNode, createElement);
116
+ container.appendChild(newNode);
117
+ }
118
+ else {
119
+ console.warn(`Unhandled node name: ${newNodeName}`);
120
+ container.appendChild(childNode.cloneNode());
121
+ }
122
+ break;
123
+ }
124
+ case Node.TEXT_NODE:
125
+ default: {
126
+ container.appendChild(childNode.cloneNode());
127
+ break;
128
+ }
129
+ }
130
+ });
131
+ };
132
+ export const htmlFromJatsNode = (element, createElement) => {
133
+ if (!element) {
134
+ return undefined;
135
+ }
136
+ const temp = createElement('template');
137
+ renameJatsNodesToHTML(element, temp.content, createElement);
138
+ return temp.innerHTML;
139
+ };