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