@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,644 @@
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 mime from 'mime';
17
+ import { DOMParser, Fragment } from 'prosemirror-model';
18
+ import { convertMathMLToSVG } from '../../mathjax/mathml-to-svg';
19
+ import { convertTeXToSVG } from '../../mathjax/tex-to-svg';
20
+ import { schema } from '../../schema';
21
+ import { chooseSectionCategory, xmlSerializer } from '../../transformer';
22
+ const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
23
+ const chooseContentType = (graphicNode) => {
24
+ if (graphicNode) {
25
+ const mimetype = graphicNode.getAttribute('mimetype');
26
+ const subtype = graphicNode.getAttribute('mime-subtype');
27
+ if (mimetype && subtype) {
28
+ return [mimetype, subtype].join('/');
29
+ }
30
+ const href = graphicNode.getAttributeNS(XLINK_NAMESPACE, 'href');
31
+ if (href) {
32
+ return mime.getType(href) || undefined;
33
+ }
34
+ }
35
+ };
36
+ const marks = [
37
+ {
38
+ tag: 'bold',
39
+ mark: 'bold',
40
+ },
41
+ {
42
+ tag: 'code',
43
+ mark: 'code',
44
+ },
45
+ {
46
+ tag: 'italic',
47
+ mark: 'italic',
48
+ },
49
+ {
50
+ tag: 'sc',
51
+ mark: 'smallcaps',
52
+ },
53
+ {
54
+ tag: 'strike',
55
+ mark: 'strikethrough',
56
+ },
57
+ {
58
+ tag: 'styled-content',
59
+ mark: 'styled',
60
+ getAttrs: (node) => ({
61
+ style: node.getAttribute('style'),
62
+ }),
63
+ },
64
+ {
65
+ tag: 'sub',
66
+ mark: 'subscript',
67
+ },
68
+ {
69
+ tag: 'sup',
70
+ mark: 'superscript',
71
+ },
72
+ {
73
+ tag: 'underline',
74
+ mark: 'underline',
75
+ },
76
+ ];
77
+ const nodes = [
78
+ {
79
+ tag: 'attrib',
80
+ node: 'attribution',
81
+ },
82
+ {
83
+ tag: 'back',
84
+ ignore: true,
85
+ },
86
+ {
87
+ tag: 'body',
88
+ node: 'manuscript',
89
+ },
90
+ {
91
+ tag: 'break',
92
+ node: 'hard_break',
93
+ },
94
+ {
95
+ tag: 'caption',
96
+ node: 'figcaption',
97
+ context: 'figure/',
98
+ },
99
+ {
100
+ tag: 'caption',
101
+ node: 'figcaption',
102
+ context: 'figure_element/',
103
+ getContent: (node, schema) => {
104
+ const element = node;
105
+ const content = [];
106
+ const title = element.querySelector('title');
107
+ if (title) {
108
+ const captionTitle = schema.nodes.caption_title.create();
109
+ content.push(jatsBodyDOMParser.parse(title, { topNode: captionTitle }));
110
+ }
111
+ const paragraphs = element.querySelectorAll('p');
112
+ if (paragraphs.length) {
113
+ const figcaption = schema.nodes.caption.create();
114
+ for (const paragraph of paragraphs) {
115
+ content.push(jatsBodyDOMParser.parse(paragraph, { topNode: figcaption }));
116
+ }
117
+ }
118
+ return Fragment.from(content);
119
+ },
120
+ },
121
+ {
122
+ tag: 'caption',
123
+ node: 'figcaption',
124
+ context: 'table_element/',
125
+ },
126
+ {
127
+ tag: 'code',
128
+ node: 'listing',
129
+ context: 'listing_element/',
130
+ getAttrs: (node) => {
131
+ var _a, _b, _c;
132
+ const element = node;
133
+ return {
134
+ id: element.getAttribute('id'),
135
+ language: (_a = element.getAttribute('language')) !== null && _a !== void 0 ? _a : '',
136
+ contents: (_c = (_b = element.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '',
137
+ };
138
+ },
139
+ },
140
+ {
141
+ tag: 'inline-formula',
142
+ node: 'inline_equation',
143
+ getAttrs: (node) => {
144
+ var _a, _b, _c, _d, _e;
145
+ const element = node;
146
+ const attrs = {
147
+ id: element.getAttribute('id'),
148
+ MathMLRepresentation: '',
149
+ SVGRepresentation: '',
150
+ TeXRepresentation: '',
151
+ };
152
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
153
+ for (const child of container.childNodes) {
154
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
155
+ switch (nodeName) {
156
+ case 'tex-math':
157
+ attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
158
+ if (attrs.TeXRepresentation) {
159
+ attrs.SVGRepresentation =
160
+ (_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
161
+ }
162
+ break;
163
+ case 'mml:math':
164
+ ;
165
+ child.removeAttribute('id');
166
+ attrs.MathMLRepresentation = xmlSerializer.serializeToString(child);
167
+ if (attrs.MathMLRepresentation) {
168
+ attrs.SVGRepresentation =
169
+ (_e = convertMathMLToSVG(attrs.MathMLRepresentation, true)) !== null && _e !== void 0 ? _e : '';
170
+ }
171
+ break;
172
+ }
173
+ }
174
+ return attrs;
175
+ },
176
+ },
177
+ {
178
+ tag: 'disp-formula',
179
+ node: 'equation_element',
180
+ getAttrs: (node) => {
181
+ const element = node;
182
+ const caption = element.querySelector('figcaption');
183
+ return {
184
+ id: element.getAttribute('id'),
185
+ suppressCaption: !caption,
186
+ };
187
+ },
188
+ getContent: (node, schema) => {
189
+ var _a, _b, _c, _d, _e;
190
+ const element = node;
191
+ const attrs = {
192
+ MathMLStringRepresentation: '',
193
+ SVGStringRepresentation: '',
194
+ TeXRepresentation: '',
195
+ };
196
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
197
+ for (const child of container.childNodes) {
198
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
199
+ switch (nodeName) {
200
+ case 'tex-math':
201
+ attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
202
+ if (attrs.TeXRepresentation) {
203
+ attrs.SVGStringRepresentation =
204
+ (_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
205
+ }
206
+ break;
207
+ case 'mml:math':
208
+ ;
209
+ child.removeAttribute('id');
210
+ attrs.MathMLStringRepresentation =
211
+ xmlSerializer.serializeToString(child);
212
+ if (attrs.MathMLStringRepresentation) {
213
+ attrs.SVGStringRepresentation =
214
+ (_e = convertMathMLToSVG(attrs.MathMLStringRepresentation, true)) !== null && _e !== void 0 ? _e : '';
215
+ }
216
+ break;
217
+ }
218
+ }
219
+ const caption = element.querySelector('figcaption');
220
+ const figcaption = schema.nodes.figcaption.create();
221
+ return Fragment.from([
222
+ schema.nodes.equation.createChecked(attrs),
223
+ caption
224
+ ?
225
+ jatsBodyDOMParser.parse(caption, {
226
+ topNode: figcaption,
227
+ })
228
+ : figcaption,
229
+ ]);
230
+ },
231
+ },
232
+ {
233
+ tag: 'disp-quote[content-type=quote]',
234
+ node: 'blockquote_element',
235
+ getAttrs: (node) => {
236
+ const element = node;
237
+ return {
238
+ id: element.getAttribute('id'),
239
+ };
240
+ },
241
+ },
242
+ {
243
+ tag: 'disp-quote[content-type=pullquote]',
244
+ node: 'pullquote_element',
245
+ getAttrs: (node) => {
246
+ const element = node;
247
+ return {
248
+ id: element.getAttribute('id'),
249
+ };
250
+ },
251
+ },
252
+ {
253
+ tag: 'ext-link',
254
+ node: 'link',
255
+ getAttrs: (node) => {
256
+ const element = node;
257
+ return {
258
+ href: element.getAttributeNS(XLINK_NAMESPACE, 'href') || '',
259
+ title: element.getAttributeNS(XLINK_NAMESPACE, 'title') || '',
260
+ };
261
+ },
262
+ },
263
+ {
264
+ tag: 'fig[fig-type=equation]',
265
+ node: 'equation_element',
266
+ getAttrs: (node) => {
267
+ const element = node;
268
+ return {
269
+ id: element.getAttribute('id'),
270
+ };
271
+ },
272
+ },
273
+ {
274
+ tag: 'fig[fig-type=listing]',
275
+ node: 'listing_element',
276
+ getAttrs: (node) => {
277
+ const element = node;
278
+ return {
279
+ id: element.getAttribute('id'),
280
+ };
281
+ },
282
+ },
283
+ {
284
+ tag: 'graphic[specific-use=MISSING]',
285
+ node: 'missing_figure',
286
+ context: 'figure_element/',
287
+ getAttrs: (node) => {
288
+ const element = node;
289
+ return {
290
+ id: element.getAttribute('id'),
291
+ };
292
+ },
293
+ },
294
+ {
295
+ tag: 'graphic',
296
+ node: 'figure',
297
+ context: 'figure_element/',
298
+ getAttrs: (node) => {
299
+ const element = node;
300
+ const position = element.getAttribute('position');
301
+ const src = element.getAttributeNS(XLINK_NAMESPACE, 'href');
302
+ return {
303
+ id: element.getAttribute('id'),
304
+ contentType: chooseContentType(element || undefined) || '',
305
+ src,
306
+ position,
307
+ };
308
+ },
309
+ },
310
+ {
311
+ tag: 'fig',
312
+ node: 'figure_element',
313
+ getAttrs: (node) => {
314
+ var _a, _b, _c, _d;
315
+ const element = node;
316
+ const labelNode = element.querySelector('label');
317
+ if (labelNode) {
318
+ element.removeChild(labelNode);
319
+ }
320
+ const attrib = element.querySelector('attrib');
321
+ const position = element.getAttribute('position');
322
+ const attribution = attrib
323
+ ? {
324
+ literal: (_b = (_a = attrib.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '',
325
+ }
326
+ : undefined;
327
+ return {
328
+ id: element.getAttribute('id'),
329
+ label: (_d = (_c = labelNode === null || labelNode === void 0 ? void 0 : labelNode.textContent) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : '',
330
+ attribution: attribution,
331
+ position,
332
+ };
333
+ },
334
+ },
335
+ {
336
+ tag: 'ref',
337
+ node: 'bibliography_item',
338
+ context: 'bibliography_element/',
339
+ getAttrs: (node) => {
340
+ const element = node;
341
+ const ref = {
342
+ id: element.getAttribute('id'),
343
+ type: element.getAttribute('type'),
344
+ };
345
+ const author = element.getAttribute('author');
346
+ if (author) {
347
+ ref.author = author;
348
+ }
349
+ const issued = element.getAttribute('issued');
350
+ if (issued) {
351
+ ref.issued = issued;
352
+ }
353
+ const containerTitle = element.getAttribute('container-title');
354
+ if (containerTitle) {
355
+ ref.containerTitle = containerTitle;
356
+ }
357
+ const doi = element.getAttribute('doi');
358
+ if (doi) {
359
+ ref.doi = doi;
360
+ }
361
+ const volume = element.getAttribute('volume');
362
+ if (volume) {
363
+ ref.volume = volume;
364
+ }
365
+ const issue = element.getAttribute('issue');
366
+ if (issue) {
367
+ ref.issue = issue;
368
+ }
369
+ const supplement = element.getAttribute('supplement');
370
+ if (supplement) {
371
+ ref.supplement = supplement;
372
+ }
373
+ const page = element.getAttribute('page');
374
+ if (page) {
375
+ ref.page = page;
376
+ }
377
+ const title = element.getAttribute('title');
378
+ if (title) {
379
+ ref.title = title;
380
+ }
381
+ const literal = element.getAttribute('literal');
382
+ if (literal) {
383
+ ref.literal = literal;
384
+ }
385
+ return ref;
386
+ },
387
+ },
388
+ {
389
+ tag: 'ref-list',
390
+ node: 'bibliography_element',
391
+ context: 'bibliography_section/',
392
+ getAttrs: (node) => {
393
+ const element = node;
394
+ const titleNode = element.querySelector('title');
395
+ if (titleNode) {
396
+ element.removeChild(titleNode);
397
+ }
398
+ return {
399
+ id: element.getAttribute('id'),
400
+ contents: '',
401
+ };
402
+ },
403
+ },
404
+ {
405
+ tag: 'fn-group',
406
+ node: 'footnotes_element',
407
+ context: 'footnotes_section/',
408
+ getAttrs: (node) => {
409
+ const element = node;
410
+ return {
411
+ id: element.getAttribute('id'),
412
+ kind: 'footnote',
413
+ };
414
+ },
415
+ },
416
+ {
417
+ tag: 'table-wrap-foot',
418
+ node: 'footnotes_element',
419
+ getAttrs: (node) => {
420
+ const element = node;
421
+ return {
422
+ id: element.getAttribute('id'),
423
+ kind: 'table_footnote',
424
+ };
425
+ },
426
+ },
427
+ {
428
+ tag: 'fn',
429
+ node: 'footnote',
430
+ context: 'footnotes_element/',
431
+ getAttrs: (node) => {
432
+ const element = node;
433
+ return {
434
+ id: element.getAttribute('id'),
435
+ kind: 'footnote',
436
+ };
437
+ },
438
+ },
439
+ {
440
+ tag: 'front',
441
+ ignore: true,
442
+ },
443
+ {
444
+ tag: 'list[list-type=bullet]',
445
+ node: 'bullet_list',
446
+ getAttrs: (node) => {
447
+ const element = node;
448
+ return {
449
+ id: element.getAttribute('id'),
450
+ };
451
+ },
452
+ },
453
+ {
454
+ tag: 'list[list-type=order]',
455
+ node: 'ordered_list',
456
+ getAttrs: (node) => {
457
+ const element = node;
458
+ return {
459
+ id: element.getAttribute('id'),
460
+ };
461
+ },
462
+ },
463
+ {
464
+ tag: 'list-item',
465
+ node: 'list_item',
466
+ },
467
+ {
468
+ tag: 'p',
469
+ node: 'paragraph',
470
+ context: 'section/',
471
+ getAttrs: (node) => {
472
+ const element = node;
473
+ return {
474
+ id: element.getAttribute('id'),
475
+ };
476
+ },
477
+ },
478
+ {
479
+ tag: 'p',
480
+ node: 'paragraph',
481
+ },
482
+ {
483
+ tag: 'sec[sec-type="endnotes"]',
484
+ node: 'footnotes_section',
485
+ getAttrs: (node) => {
486
+ const element = node;
487
+ return {
488
+ id: element.getAttribute('id'),
489
+ };
490
+ },
491
+ },
492
+ {
493
+ tag: 'sec[sec-type="bibliography"]',
494
+ node: 'bibliography_section',
495
+ getAttrs: (node) => {
496
+ const element = node;
497
+ return {
498
+ id: element.getAttribute('id'),
499
+ };
500
+ },
501
+ },
502
+ {
503
+ tag: 'sec',
504
+ node: 'section',
505
+ getAttrs: (node) => {
506
+ const element = node;
507
+ return {
508
+ id: element.getAttribute('id'),
509
+ category: chooseSectionCategory(element),
510
+ };
511
+ },
512
+ },
513
+ {
514
+ tag: 'label',
515
+ context: 'section/',
516
+ node: 'section_label',
517
+ },
518
+ {
519
+ tag: 'label',
520
+ context: 'table_element/',
521
+ ignore: true,
522
+ },
523
+ {
524
+ tag: 'label',
525
+ context: 'figure/',
526
+ ignore: true,
527
+ },
528
+ {
529
+ tag: 'table',
530
+ node: 'table',
531
+ getAttrs: (node) => {
532
+ const element = node;
533
+ return {
534
+ id: element.getAttribute('id'),
535
+ };
536
+ },
537
+ },
538
+ {
539
+ tag: 'table-wrap',
540
+ node: 'table_element',
541
+ getAttrs: (node) => {
542
+ const element = node;
543
+ return {
544
+ id: element.getAttribute('id'),
545
+ suppressFooter: !element.querySelector('table > tfoot > tr'),
546
+ suppressHeader: !element.querySelector('table > thead > tr'),
547
+ };
548
+ },
549
+ },
550
+ {
551
+ tag: 'tbody',
552
+ skip: true,
553
+ },
554
+ {
555
+ tag: 'tfoot',
556
+ skip: true,
557
+ },
558
+ {
559
+ tag: 'thead',
560
+ skip: true,
561
+ },
562
+ {
563
+ tag: 'title',
564
+ node: 'section_title',
565
+ context: 'section/|footnotes_section/|bibliography_section/',
566
+ },
567
+ {
568
+ tag: 'title',
569
+ node: 'caption_title',
570
+ context: 'figcaption/',
571
+ },
572
+ {
573
+ tag: 'tr',
574
+ node: 'table_row',
575
+ },
576
+ {
577
+ tag: 'td',
578
+ node: 'table_cell',
579
+ getAttrs: (node) => {
580
+ const element = node;
581
+ const colspan = element.getAttribute('colspan');
582
+ const rowspan = element.getAttribute('rowspan');
583
+ return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
584
+ },
585
+ },
586
+ {
587
+ tag: 'th',
588
+ node: 'table_cell',
589
+ getAttrs: (node) => {
590
+ const element = node;
591
+ const colspan = element.getAttribute('colspan');
592
+ const rowspan = element.getAttribute('rowspan');
593
+ return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
594
+ },
595
+ },
596
+ {
597
+ tag: 'col',
598
+ node: 'table_col',
599
+ getAttrs: (node) => {
600
+ const element = node;
601
+ return {
602
+ width: element.getAttribute('width'),
603
+ };
604
+ },
605
+ },
606
+ {
607
+ tag: 'colgroup',
608
+ node: 'table_colgroup',
609
+ },
610
+ {
611
+ tag: 'xref[ref-type="bibr"]',
612
+ node: 'citation',
613
+ getAttrs: (node) => {
614
+ const element = node;
615
+ return {
616
+ rid: element.getAttribute('rid'),
617
+ contents: element.textContent,
618
+ };
619
+ },
620
+ },
621
+ {
622
+ tag: 'xref[ref-type="fn"]',
623
+ node: 'inline_footnote',
624
+ getAttrs: (node) => {
625
+ const element = node;
626
+ return {
627
+ rid: element.getAttribute('rid'),
628
+ contents: element.textContent,
629
+ };
630
+ },
631
+ },
632
+ {
633
+ tag: 'xref',
634
+ node: 'cross_reference',
635
+ getAttrs: (node) => {
636
+ const element = node;
637
+ return {
638
+ rid: element.getAttribute('rid'),
639
+ label: element.textContent,
640
+ };
641
+ },
642
+ },
643
+ ];
644
+ export const jatsBodyDOMParser = new DOMParser(schema, [...marks, ...nodes]);