@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,535 @@
1
+ /*!
2
+ * © 2019 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 { DOMSerializer } from 'prosemirror-model';
17
+ import serializeToXML from 'w3c-xmlserializer';
18
+ import { iterateChildren } from '../lib/utils';
19
+ import { isHighlightMarkerNode, isSectionNode, schema, } from '../schema';
20
+ import { buildAttribution, buildComment } from './builders';
21
+ import { extractHighlightMarkers, isHighlightableModel, } from './highlight-markers';
22
+ import { nodeTypesMap } from './node-types';
23
+ import { buildSectionCategory } from './section-category';
24
+ const serializer = DOMSerializer.fromSchema(schema);
25
+ const contents = (node) => {
26
+ const output = serializer.serializeNode(node);
27
+ return serializeToXML(output);
28
+ };
29
+ const footnoteContents = (node) => {
30
+ const output = serializer.serializeNode(node);
31
+ output.querySelectorAll('p').forEach((element) => {
32
+ element.removeAttribute('class');
33
+ element.removeAttribute('data-object-type');
34
+ });
35
+ return serializeToXML(output);
36
+ };
37
+ export const inlineContents = (node) => serializer.serializeNode(node).innerHTML;
38
+ export const inlineText = (node) => {
39
+ const text = serializer.serializeNode(node).textContent;
40
+ return text === null ? '' : text;
41
+ };
42
+ const listContents = (node) => {
43
+ const output = serializer.serializeNode(node);
44
+ for (const p of output.querySelectorAll('li > p')) {
45
+ const parent = p.parentNode;
46
+ while (p.firstChild) {
47
+ parent.insertBefore(p.firstChild, p);
48
+ }
49
+ parent.removeChild(p);
50
+ }
51
+ return serializeToXML(output);
52
+ };
53
+ const svgDefs = (svg) => {
54
+ const template = document.createElement('template');
55
+ template.innerHTML = svg.trim();
56
+ const defs = template.content.querySelector('defs');
57
+ return defs ? serializeToXML(defs) : undefined;
58
+ };
59
+ const tableRowDisplayStyle = (tagName, parent) => {
60
+ switch (tagName) {
61
+ case 'thead':
62
+ return parent.attrs.suppressHeader ? 'none' : 'table-header-group';
63
+ case 'tfoot':
64
+ return parent.attrs.suppressFooter ? 'none' : 'table-footer-group';
65
+ default:
66
+ return null;
67
+ }
68
+ };
69
+ const buildTableSection = (tagName, inputRows, parent) => {
70
+ const section = document.createElement(tagName);
71
+ for (const sectionRow of inputRows) {
72
+ const row = section.appendChild(document.createElement('tr'));
73
+ for (const child of sectionRow.children) {
74
+ const cellType = tagName === 'thead' ? 'th' : 'td';
75
+ const cell = row.appendChild(document.createElement(cellType));
76
+ while (child.firstChild) {
77
+ cell.appendChild(child.firstChild);
78
+ }
79
+ for (const attribute of child.attributes) {
80
+ cell.setAttribute(attribute.name, attribute.value);
81
+ }
82
+ }
83
+ }
84
+ const displayStyle = tableRowDisplayStyle(tagName, parent);
85
+ if (displayStyle) {
86
+ section.style.display = displayStyle;
87
+ }
88
+ return section;
89
+ };
90
+ function buildTableColGroup(cols) {
91
+ if (cols.length === 0) {
92
+ return undefined;
93
+ }
94
+ const colgroup = document.createElement('colgroup');
95
+ for (const inputCol of cols) {
96
+ const col = document.createElement('col');
97
+ for (const attribute of inputCol.attributes) {
98
+ col.setAttribute(attribute.name, attribute.value);
99
+ }
100
+ colgroup.appendChild(inputCol);
101
+ }
102
+ return colgroup;
103
+ }
104
+ const tableContents = (node, parent) => {
105
+ const input = serializer.serializeNode(node);
106
+ const output = document.createElement('table');
107
+ const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
108
+ if (colgroup) {
109
+ output.appendChild(colgroup);
110
+ }
111
+ output.setAttribute('id', parent.attrs.id);
112
+ output.classList.add('MPElement');
113
+ if (parent.attrs.tableStyle) {
114
+ output.classList.add(parent.attrs.tableStyle.replace(/:/g, '_'));
115
+ }
116
+ if (parent.attrs.paragraphStyle) {
117
+ output.classList.add(parent.attrs.paragraphStyle.replace(/:/g, '_'));
118
+ }
119
+ output.setAttribute('data-contained-object-id', node.attrs.id);
120
+ const rows = Array.from(input.querySelectorAll('tr'));
121
+ let headerCount = 0;
122
+ for (const row of rows) {
123
+ const th = row.querySelector('th[scope="col"], th[scope="colgroup"]');
124
+ th && headerCount++;
125
+ }
126
+ const thead = rows.splice(0, headerCount || 1);
127
+ const tfoot = rows.splice(-1, 1);
128
+ output.appendChild(buildTableSection('thead', thead, parent));
129
+ output.appendChild(buildTableSection('tbody', rows, parent));
130
+ output.appendChild(buildTableSection('tfoot', tfoot, parent));
131
+ return serializeToXML(output);
132
+ };
133
+ const elementContents = (node) => {
134
+ const input = serializer.serializeNode(node);
135
+ input.classList.add('MPElement');
136
+ if (node.attrs.paragraphStyle) {
137
+ input.classList.add(node.attrs.paragraphStyle.replace(/:/g, '_'));
138
+ }
139
+ if (node.attrs.id) {
140
+ input.setAttribute('id', node.attrs.id);
141
+ }
142
+ return serializeToXML(input);
143
+ };
144
+ const childElements = (node) => {
145
+ const nodes = [];
146
+ node.forEach((childNode) => {
147
+ if (!isSectionNode(childNode)) {
148
+ nodes.push(childNode);
149
+ }
150
+ });
151
+ return nodes;
152
+ };
153
+ const attributeOfNodeType = (node, type, attribute) => {
154
+ for (const child of iterateChildren(node)) {
155
+ if (child.type.name === type) {
156
+ return child.attrs[attribute];
157
+ }
158
+ }
159
+ return '';
160
+ };
161
+ const inlineContentsOfNodeType = (node, nodeType) => {
162
+ for (let i = 0; i < node.childCount; i++) {
163
+ const child = node.child(i);
164
+ if (child.type === nodeType) {
165
+ return inlineContents(child);
166
+ }
167
+ }
168
+ return '';
169
+ };
170
+ const inlineContentOfChildNodeType = (node, parentNodeType, childNodeType, empty = true) => {
171
+ const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
172
+ const content = parentNode && inlineContentsOfNodeType(parentNode, childNodeType);
173
+ return content && content.length > 1 ? content : empty ? content : undefined;
174
+ };
175
+ const wrappedContentOfChildrenNodeType = (node, parentNodeType, childNodeType) => {
176
+ const parentNode = childElements(node).find((node) => node.type === parentNodeType && node);
177
+ const content = parentNode &&
178
+ childElements(parentNode)
179
+ .filter((node) => node.type === childNodeType && node)
180
+ .map((node) => serializer.serializeNode(node).outerHTML)
181
+ .join('');
182
+ return content;
183
+ };
184
+ const containedFigureIDs = (node) => {
185
+ const figureNodeType = node.type.schema.nodes.figure;
186
+ const missingFigureNodeType = node.type.schema.nodes.missing_figure;
187
+ return containedObjectIDs(node, [figureNodeType, missingFigureNodeType]);
188
+ };
189
+ const containedParagraphIDs = (node) => {
190
+ const paragraphNodeType = node.type.schema.nodes.paragraph;
191
+ return containedObjectIDs(node, [paragraphNodeType]);
192
+ };
193
+ const containedBibliographyItemIDs = (node) => {
194
+ const bibliographyItemNodeType = node.type.schema.nodes.bibliography_item;
195
+ return containedObjectIDs(node, [bibliographyItemNodeType]);
196
+ };
197
+ const containedObjectIDs = (node, nodeTypes) => {
198
+ const ids = [];
199
+ for (let i = 0; i < node.childCount; i++) {
200
+ const childNode = node.child(i);
201
+ if (nodeTypes.includes(childNode.type)) {
202
+ ids.push(childNode.attrs.id);
203
+ }
204
+ }
205
+ return ids;
206
+ };
207
+ const attribution = (node) => {
208
+ if (node.attrs.attribution) {
209
+ return Object.assign(Object.assign({}, node.attrs.attribution), buildAttribution());
210
+ }
211
+ return undefined;
212
+ };
213
+ const fromJson = (json) => {
214
+ let obj;
215
+ try {
216
+ obj = JSON.parse(json);
217
+ }
218
+ catch (e) {
219
+ }
220
+ return obj;
221
+ };
222
+ function figureElementEncoder(node) {
223
+ var _a;
224
+ return {
225
+ containedObjectIDs: (_a = containedParagraphIDs(node)) === null || _a === void 0 ? void 0 : _a.concat(containedFigureIDs(node)),
226
+ caption: wrappedContentOfChildrenNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
227
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
228
+ label: node.attrs.label,
229
+ elementType: 'figure',
230
+ attribution: attribution(node),
231
+ alternatives: node.attrs.alternatives,
232
+ listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
233
+ alignment: node.attrs.alignment || undefined,
234
+ sizeFraction: node.attrs.sizeFraction || undefined,
235
+ suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
236
+ suppressTitle: node.attrs.suppressTitle === undefined ||
237
+ node.attrs.suppressTitle === true
238
+ ? undefined
239
+ : false,
240
+ figureStyle: node.attrs.figureStyle || undefined,
241
+ figureLayout: node.attrs.figureLayout || undefined,
242
+ };
243
+ }
244
+ const encoders = {
245
+ bibliography_element: (node) => ({
246
+ elementType: 'div',
247
+ contents: '',
248
+ containedObjectIDs: containedBibliographyItemIDs(node),
249
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
250
+ }),
251
+ bibliography_item: (node) => {
252
+ const { type, containerTitle, doi, volume, issue, supplement, page, title, literal, } = node.attrs;
253
+ const author = fromJson(node.attrs.author);
254
+ const issued = fromJson(node.attrs.issued);
255
+ const ref = {
256
+ type,
257
+ };
258
+ if (author) {
259
+ ref.author = author;
260
+ }
261
+ if (issued) {
262
+ ref.issued = issued;
263
+ }
264
+ if (containerTitle) {
265
+ ref['container-title'] = containerTitle;
266
+ }
267
+ if (doi) {
268
+ ref.DOI = doi;
269
+ }
270
+ if (volume) {
271
+ ref.volume = volume;
272
+ }
273
+ if (issue) {
274
+ ref.issue = issue;
275
+ }
276
+ if (supplement) {
277
+ ref.supplement = supplement;
278
+ }
279
+ if (page) {
280
+ ref.page = page;
281
+ }
282
+ if (title) {
283
+ ref.title = title;
284
+ }
285
+ if (literal) {
286
+ ref.literal = literal;
287
+ }
288
+ return ref;
289
+ },
290
+ bibliography_section: (node, parent, path, priority) => ({
291
+ category: buildSectionCategory(node),
292
+ priority: priority.value++,
293
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
294
+ path: path.concat([node.attrs.id]),
295
+ elementIDs: childElements(node)
296
+ .map((childNode) => childNode.attrs.id)
297
+ .filter((id) => id),
298
+ }),
299
+ blockquote_element: (node) => ({
300
+ contents: contents(node),
301
+ elementType: 'div',
302
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
303
+ placeholderInnerHTML: node.attrs.placeholder || '',
304
+ quoteType: 'block',
305
+ }),
306
+ bullet_list: (node) => ({
307
+ elementType: 'ul',
308
+ contents: listContents(node),
309
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
310
+ }),
311
+ listing: (node) => ({
312
+ contents: inlineText(node),
313
+ language: node.attrs.language || undefined,
314
+ languageKey: node.attrs.languageKey || 'null',
315
+ }),
316
+ listing_element: (node) => ({
317
+ containedObjectID: attributeOfNodeType(node, 'listing', 'id'),
318
+ caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
319
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
320
+ elementType: 'figure',
321
+ suppressCaption: node.attrs.suppressCaption === true ? undefined : false,
322
+ suppressTitle: node.attrs.suppressTitle === undefined ||
323
+ node.attrs.suppressTitle === true
324
+ ? undefined
325
+ : false,
326
+ }),
327
+ equation: (node) => ({
328
+ MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
329
+ TeXRepresentation: node.attrs.TeXRepresentation,
330
+ SVGStringRepresentation: node.attrs.SVGStringRepresentation,
331
+ }),
332
+ equation_element: (node) => ({
333
+ containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
334
+ caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
335
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
336
+ elementType: 'p',
337
+ suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
338
+ suppressTitle: node.attrs.suppressTitle === undefined ||
339
+ node.attrs.suppressTitle === true
340
+ ? undefined
341
+ : false,
342
+ }),
343
+ figure: (node) => ({
344
+ contentType: node.attrs.contentType || undefined,
345
+ src: node.attrs.src || undefined,
346
+ position: node.attrs.position || undefined,
347
+ }),
348
+ figure_element: (node) => figureElementEncoder(node),
349
+ comment: (node) => ({
350
+ selector: node.attrs.selector,
351
+ target: node.attrs.target,
352
+ contents: node.attrs.contents,
353
+ }),
354
+ footnote: (node, parent) => ({
355
+ containingObject: parent.attrs.id,
356
+ contents: footnoteContents(node),
357
+ kind: node.attrs.kind || 'footnote',
358
+ }),
359
+ footnotes_element: (node) => ({
360
+ contents: '<div></div>',
361
+ elementType: 'div',
362
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
363
+ }),
364
+ footnotes_section: (node, parent, path, priority) => ({
365
+ category: buildSectionCategory(node),
366
+ priority: priority.value++,
367
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
368
+ path: path.concat([node.attrs.id]),
369
+ elementIDs: childElements(node)
370
+ .map((childNode) => childNode.attrs.id)
371
+ .filter((id) => id),
372
+ }),
373
+ graphical_abstract_section: (node, parent, path, priority) => ({
374
+ category: buildSectionCategory(node),
375
+ priority: priority.value++,
376
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
377
+ path: path.concat([node.attrs.id]),
378
+ elementIDs: childElements(node)
379
+ .map((childNode) => childNode.attrs.id)
380
+ .filter((id) => id),
381
+ }),
382
+ inline_equation: (node, parent) => ({
383
+ containingObject: parent.attrs.id,
384
+ TeXRepresentation: node.attrs.TeXRepresentation,
385
+ SVGRepresentation: node.attrs.SVGRepresentation,
386
+ SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
387
+ }),
388
+ keywords_element: (node) => ({
389
+ contents: elementContents(node),
390
+ elementType: 'div',
391
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
392
+ }),
393
+ keywords_section: (node, parent, path, priority) => ({
394
+ category: buildSectionCategory(node),
395
+ priority: priority.value++,
396
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
397
+ path: path.concat([node.attrs.id]),
398
+ elementIDs: childElements(node)
399
+ .map((childNode) => childNode.attrs.id)
400
+ .filter((id) => id),
401
+ }),
402
+ missing_figure: (node) => ({
403
+ position: node.attrs.position || undefined,
404
+ }),
405
+ ordered_list: (node) => ({
406
+ elementType: 'ol',
407
+ contents: listContents(node),
408
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
409
+ }),
410
+ paragraph: (node) => ({
411
+ elementType: 'p',
412
+ contents: contents(node),
413
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
414
+ placeholderInnerHTML: node.attrs.placeholder || '',
415
+ }),
416
+ placeholder_element: () => ({
417
+ elementType: 'p',
418
+ }),
419
+ pullquote_element: (node) => ({
420
+ contents: contents(node),
421
+ elementType: 'div',
422
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
423
+ placeholderInnerHTML: node.attrs.placeholder || '',
424
+ quoteType: 'pull',
425
+ }),
426
+ section: (node, parent, path, priority) => ({
427
+ category: buildSectionCategory(node),
428
+ priority: priority.value++,
429
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
430
+ label: inlineContentsOfNodeType(node, node.type.schema.nodes.section_label) ||
431
+ undefined,
432
+ path: path.concat([node.attrs.id]),
433
+ elementIDs: childElements(node)
434
+ .map((childNode) => childNode.attrs.id)
435
+ .filter((id) => id),
436
+ titleSuppressed: node.attrs.titleSuppressed || undefined,
437
+ generatedLabel: node.attrs.generatedLabel || undefined,
438
+ pageBreakStyle: node.attrs.pageBreakStyle || undefined,
439
+ }),
440
+ table: (node, parent) => ({
441
+ contents: tableContents(node, parent),
442
+ listingAttachment: node.attrs.listingAttachment || undefined,
443
+ }),
444
+ table_element: (node) => ({
445
+ containedObjectID: attributeOfNodeType(node, 'table', 'id'),
446
+ caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
447
+ title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
448
+ elementType: 'table',
449
+ listingID: attributeOfNodeType(node, 'listing', 'id') || undefined,
450
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
451
+ suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
452
+ suppressTitle: node.attrs.suppressTitle === undefined ||
453
+ node.attrs.suppressTitle === true
454
+ ? undefined
455
+ : false,
456
+ suppressFooter: Boolean(node.attrs.suppressFooter) || undefined,
457
+ suppressHeader: Boolean(node.attrs.suppressHeader) || undefined,
458
+ tableStyle: node.attrs.tableStyle || undefined,
459
+ }),
460
+ toc_element: (node) => ({
461
+ contents: elementContents(node),
462
+ elementType: 'div',
463
+ paragraphStyle: node.attrs.paragraphStyle || undefined,
464
+ }),
465
+ toc_section: (node, parent, path, priority) => ({
466
+ category: buildSectionCategory(node),
467
+ priority: priority.value++,
468
+ title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
469
+ path: path.concat([node.attrs.id]),
470
+ elementIDs: childElements(node)
471
+ .map((childNode) => childNode.attrs.id)
472
+ .filter((id) => id),
473
+ }),
474
+ };
475
+ const modelData = (node, parent, path, priority) => {
476
+ const encoder = encoders[node.type.name];
477
+ if (!encoder) {
478
+ throw new Error(`Unhandled model: ${node.type.name}`);
479
+ }
480
+ return encoder(node, parent, path, priority);
481
+ };
482
+ export const modelFromNode = (node, parent, path, priority) => {
483
+ const commentAnnotationsMap = new Map();
484
+ const objectType = nodeTypesMap.get(node.type);
485
+ if (!objectType) {
486
+ throw new Error(`No objectType is defined for ${node.type.name}`);
487
+ }
488
+ const { id } = node.attrs;
489
+ if (!id) {
490
+ throw new Error(`No id is defined for this ${node.type.name}`);
491
+ }
492
+ const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
493
+ const model = data;
494
+ if (isHighlightableModel(model)) {
495
+ extractHighlightMarkers(model, commentAnnotationsMap);
496
+ if (node.attrs.comments) {
497
+ const commentNodes = node.attrs.comments;
498
+ commentNodes
499
+ .filter((commentNode) => !commentNode.attrs.selector)
500
+ .forEach((c) => {
501
+ const commentAnnotation = buildComment(model._id, c.attrs.contents, c.attrs.selector);
502
+ commentAnnotation._id = c.attrs.id;
503
+ commentAnnotationsMap.set(commentAnnotation._id, commentAnnotation);
504
+ });
505
+ }
506
+ }
507
+ return { model, commentAnnotationsMap };
508
+ };
509
+ export const encode = (node) => {
510
+ const models = new Map();
511
+ const priority = {
512
+ value: 1,
513
+ };
514
+ const placeholders = ['placeholder', 'placeholder_element'];
515
+ const addModel = (path, parent) => (child) => {
516
+ if (!child.attrs.id) {
517
+ return;
518
+ }
519
+ if (isHighlightMarkerNode(child)) {
520
+ return;
521
+ }
522
+ if (placeholders.includes(child.type.name)) {
523
+ return;
524
+ }
525
+ const { model, commentAnnotationsMap } = modelFromNode(child, parent, path, priority);
526
+ if (models.has(model._id)) {
527
+ throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
528
+ }
529
+ models.set(model._id, model);
530
+ commentAnnotationsMap.forEach((val, key) => models.set(key, val));
531
+ child.forEach(addModel(path.concat(child.attrs.id), child));
532
+ };
533
+ node.forEach(addModel([], node));
534
+ return models;
535
+ };
@@ -0,0 +1,23 @@
1
+ /*!
2
+ * © 2019 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 generateAttachmentFilename = (id, contentType) => {
17
+ const basename = id.replace(':', '_');
18
+ if (!contentType) {
19
+ return basename;
20
+ }
21
+ const [, mimeSubType] = contentType.split('/');
22
+ return `${basename}.${mimeSubType}`;
23
+ };
@@ -0,0 +1,16 @@
1
+ /*!
2
+ * © 2021 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 buildFootnoteCategory = (category) => (category && `MPFootnoteCategory:${category}`) || undefined;
@@ -0,0 +1,53 @@
1
+ /*!
2
+ * © 2022 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 { buildFootnotesOrder } from './builders';
17
+ export const createOrderedFootnotesIDs = (doc) => {
18
+ const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
19
+ const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
20
+ const authorNotesIDs = [...doc.querySelectorAll('author-notes > fn')].map((an) => an.getAttribute('id'));
21
+ const orderedFootnotesIDs = [];
22
+ footnotesRefs.forEach((ref) => {
23
+ const refID = ref.getAttribute('rid');
24
+ if (refID) {
25
+ orderedFootnotesIDs.push(refID);
26
+ }
27
+ });
28
+ footnotes.forEach((footnote) => {
29
+ const id = footnote.getAttribute('id');
30
+ if (id &&
31
+ !authorNotesIDs.includes(id) &&
32
+ !orderedFootnotesIDs.includes(id)) {
33
+ orderedFootnotesIDs.push(id);
34
+ }
35
+ });
36
+ return orderedFootnotesIDs;
37
+ };
38
+ export const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnotesOrder) => {
39
+ const footnotesList = [];
40
+ let index = 0;
41
+ orderedFootnotesIDs.forEach((refID) => {
42
+ const fnID = replacements.get(refID);
43
+ if (fnID) {
44
+ footnotesList.push({
45
+ index,
46
+ id: fnID,
47
+ });
48
+ index++;
49
+ }
50
+ });
51
+ footnotesOrder.footnotesList = footnotesList;
52
+ };
53
+ export const createEmptyFootnotesOrder = () => buildFootnotesOrder([]);