@manuscripts/transform 2.10.0-LEAN-3577 → 3.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 (205) hide show
  1. package/dist/cjs/index.js +9 -7
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +286 -416
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +7 -19
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +12 -9
  6. package/dist/cjs/jats/importer/jats-body-transformations.js +22 -1
  7. package/dist/cjs/jats/importer/jats-comments.js +48 -110
  8. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +364 -11
  9. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +11 -1
  10. package/dist/cjs/jats/importer/jats-parser-utils.js +52 -4
  11. package/dist/cjs/jats/importer/jats-transformations.js +389 -0
  12. package/dist/cjs/jats/importer/parse-jats-article.js +43 -100
  13. package/dist/cjs/jats/index.js +7 -7
  14. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  15. package/dist/cjs/lib/utils.js +3 -1
  16. package/dist/cjs/schema/index.js +10 -0
  17. package/dist/cjs/schema/migration/migrate.js +3 -9
  18. package/dist/cjs/schema/migration/migration-script.js +1 -1
  19. package/dist/cjs/schema/migration/migration-scripts/1.2.5.js +2 -2
  20. package/dist/cjs/schema/migration/migration-scripts/2.3.22.js +28 -0
  21. package/dist/cjs/schema/migration/migration-scripts/index.js +3 -2
  22. package/dist/cjs/schema/nodes/author_notes.js +9 -2
  23. package/dist/cjs/schema/nodes/award.js +38 -0
  24. package/dist/cjs/{transformer/serializer.js → schema/nodes/awards.js} +20 -7
  25. package/dist/cjs/schema/nodes/backmatter.js +3 -2
  26. package/dist/cjs/schema/nodes/box_element.js +55 -0
  27. package/dist/cjs/schema/nodes/contributors.js +1 -1
  28. package/dist/cjs/schema/nodes/corresp.js +13 -2
  29. package/dist/cjs/schema/nodes/equation_element.js +0 -1
  30. package/dist/cjs/schema/nodes/figure_element.js +0 -1
  31. package/dist/cjs/schema/nodes/footnote.js +0 -1
  32. package/dist/cjs/schema/nodes/footnotes_section.js +1 -1
  33. package/dist/cjs/schema/nodes/highlight_marker.js +0 -4
  34. package/dist/cjs/schema/nodes/inline_equation.js +0 -1
  35. package/dist/cjs/schema/nodes/inline_footnote.js +1 -0
  36. package/dist/cjs/schema/nodes/keyword.js +0 -1
  37. package/dist/cjs/schema/nodes/listing.js +0 -1
  38. package/dist/cjs/schema/nodes/listing_element.js +0 -1
  39. package/dist/cjs/schema/nodes/manuscript.js +4 -1
  40. package/dist/cjs/schema/nodes/paragraph.js +0 -1
  41. package/dist/cjs/schema/nodes/section.js +0 -1
  42. package/dist/cjs/schema/nodes/table_element.js +1 -2
  43. package/dist/cjs/schema/nodes/title.js +1 -0
  44. package/dist/cjs/transformer/id.js +1 -5
  45. package/dist/cjs/transformer/index.js +0 -18
  46. package/dist/cjs/transformer/node-names.js +1 -0
  47. package/dist/cjs/transformer/node-types.js +1 -0
  48. package/dist/cjs/transformer/section-category.js +8 -0
  49. package/dist/cjs/version.js +1 -1
  50. package/dist/es/index.js +6 -5
  51. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +281 -411
  52. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  53. package/dist/es/{transformer → jats/exporter}/labels.js +7 -19
  54. package/dist/{cjs/transformer/model-map.js → es/jats/importer/create-article-node.js} +10 -10
  55. package/dist/es/jats/importer/jats-body-transformations.js +22 -1
  56. package/dist/es/jats/importer/jats-comments.js +49 -107
  57. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +364 -11
  58. package/dist/es/jats/importer/jats-journal-meta-parser.js +9 -0
  59. package/dist/es/jats/importer/jats-parser-utils.js +54 -6
  60. package/dist/es/jats/importer/jats-transformations.js +370 -0
  61. package/dist/es/jats/importer/parse-jats-article.js +43 -98
  62. package/dist/es/jats/index.js +5 -3
  63. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  64. package/dist/es/lib/utils.js +1 -0
  65. package/dist/es/schema/index.js +10 -0
  66. package/dist/es/schema/migration/migrate.js +3 -9
  67. package/dist/es/schema/migration/migration-script.js +1 -1
  68. package/dist/es/schema/migration/migration-scripts/1.2.5.js +2 -2
  69. package/dist/es/schema/migration/migration-scripts/2.3.22.js +26 -0
  70. package/dist/es/schema/migration/migration-scripts/index.js +3 -2
  71. package/dist/es/schema/nodes/author_notes.js +9 -2
  72. package/dist/es/{transformer/__tests__/__helpers__/doc.js → schema/nodes/award.js} +19 -14
  73. package/dist/es/{transformer/model-map.js → schema/nodes/awards.js} +17 -7
  74. package/dist/es/schema/nodes/backmatter.js +3 -2
  75. package/dist/es/schema/nodes/box_element.js +52 -0
  76. package/dist/es/schema/nodes/contributors.js +1 -1
  77. package/dist/es/schema/nodes/corresp.js +11 -1
  78. package/dist/es/schema/nodes/equation_element.js +0 -1
  79. package/dist/es/schema/nodes/figure_element.js +0 -1
  80. package/dist/es/schema/nodes/footnote.js +0 -1
  81. package/dist/es/schema/nodes/footnotes_section.js +1 -1
  82. package/dist/es/schema/nodes/highlight_marker.js +0 -4
  83. package/dist/es/schema/nodes/inline_equation.js +0 -1
  84. package/dist/es/schema/nodes/inline_footnote.js +1 -0
  85. package/dist/es/schema/nodes/keyword.js +0 -1
  86. package/dist/es/schema/nodes/listing.js +0 -1
  87. package/dist/es/schema/nodes/listing_element.js +0 -1
  88. package/dist/es/schema/nodes/manuscript.js +4 -1
  89. package/dist/es/schema/nodes/paragraph.js +0 -1
  90. package/dist/es/schema/nodes/section.js +0 -1
  91. package/dist/es/schema/nodes/table_element.js +1 -2
  92. package/dist/es/schema/nodes/title.js +1 -0
  93. package/dist/es/transformer/id.js +0 -3
  94. package/dist/es/transformer/index.js +0 -16
  95. package/dist/es/transformer/node-names.js +1 -0
  96. package/dist/es/transformer/node-types.js +1 -0
  97. package/dist/es/transformer/section-category.js +8 -0
  98. package/dist/es/version.js +1 -1
  99. package/dist/types/index.d.ts +6 -5
  100. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
  101. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  102. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -3
  103. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  104. package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -0
  105. package/dist/types/jats/importer/jats-comments.d.ts +2 -15
  106. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  107. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +9 -0
  108. package/dist/types/jats/importer/jats-parser-utils.d.ts +2 -2
  109. package/dist/types/jats/importer/jats-transformations.d.ts +32 -0
  110. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  111. package/dist/types/jats/index.d.ts +5 -3
  112. package/dist/types/jats/types.d.ts +1 -0
  113. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  114. package/dist/types/lib/utils.d.ts +1 -0
  115. package/dist/types/schema/index.d.ts +4 -0
  116. package/dist/types/schema/migration/migration-script.d.ts +1 -1
  117. package/dist/types/schema/migration/migration-scripts/1.2.5.d.ts +1 -1
  118. package/dist/types/schema/migration/migration-scripts/2.3.22.d.ts +8 -0
  119. package/dist/types/schema/migration/migration-scripts/index.d.ts +3 -2
  120. package/dist/types/{transformer/footnotes-order.d.ts → schema/nodes/award.d.ts} +14 -7
  121. package/dist/{cjs/transformer/footnote-category.js → types/schema/nodes/awards.d.ts} +12 -6
  122. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  123. package/dist/{es/transformer/filename.js → types/schema/nodes/box_element.d.ts} +11 -8
  124. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  125. package/dist/types/schema/nodes/contributors.d.ts +8 -0
  126. package/dist/types/schema/nodes/corresp.d.ts +1 -0
  127. package/dist/types/schema/nodes/equation_element.d.ts +0 -2
  128. package/dist/types/schema/nodes/figure_element.d.ts +0 -2
  129. package/dist/types/schema/nodes/footnote.d.ts +0 -2
  130. package/dist/types/schema/nodes/highlight_marker.d.ts +0 -2
  131. package/dist/types/schema/nodes/inline_equation.d.ts +0 -2
  132. package/dist/types/schema/nodes/keyword.d.ts +0 -2
  133. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  134. package/dist/types/schema/nodes/listing.d.ts +0 -2
  135. package/dist/types/schema/nodes/listing_element.d.ts +0 -2
  136. package/dist/types/schema/nodes/manuscript.d.ts +8 -4
  137. package/dist/types/schema/nodes/paragraph.d.ts +0 -2
  138. package/dist/types/schema/nodes/section.d.ts +0 -2
  139. package/dist/types/schema/nodes/table_element.d.ts +0 -2
  140. package/dist/types/schema/nodes/title.d.ts +1 -3
  141. package/dist/types/schema/types.d.ts +1 -1
  142. package/dist/types/transformer/id.d.ts +0 -3
  143. package/dist/types/transformer/index.d.ts +0 -16
  144. package/dist/types/transformer/section-category.d.ts +2 -2
  145. package/dist/types/version.d.ts +1 -1
  146. package/package.json +7 -8
  147. package/dist/cjs/__tests__/data/project-dump.json +0 -824
  148. package/dist/cjs/jats/importer/index.js +0 -22
  149. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  150. package/dist/cjs/jats/importer/jats-reference-parser.js +0 -130
  151. package/dist/cjs/jats/importer/jats-references.js +0 -34
  152. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  153. package/dist/cjs/transformer/builders.js +0 -219
  154. package/dist/cjs/transformer/decode.js +0 -878
  155. package/dist/cjs/transformer/document-object-types.js +0 -31
  156. package/dist/cjs/transformer/encode.js +0 -654
  157. package/dist/cjs/transformer/footnotes-order.js +0 -60
  158. package/dist/cjs/transformer/highlight-markers.js +0 -138
  159. package/dist/cjs/transformer/html.js +0 -401
  160. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  161. package/dist/cjs/transformer/object-types.js +0 -57
  162. package/dist/cjs/transformer/project-bundle.js +0 -94
  163. package/dist/cjs/transformer/timestamp.js +0 -20
  164. package/dist/cjs/transformer/update-identifiers.js +0 -93
  165. package/dist/es/__tests__/data/project-dump.json +0 -824
  166. package/dist/es/jats/importer/index.js +0 -16
  167. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  168. package/dist/es/jats/importer/jats-reference-parser.js +0 -127
  169. package/dist/es/jats/importer/jats-references.js +0 -30
  170. package/dist/es/transformer/builders.js +0 -186
  171. package/dist/es/transformer/decode.js +0 -868
  172. package/dist/es/transformer/document-object-types.js +0 -28
  173. package/dist/es/transformer/encode.js +0 -644
  174. package/dist/es/transformer/footnotes-order.js +0 -55
  175. package/dist/es/transformer/highlight-markers.js +0 -132
  176. package/dist/es/transformer/html.js +0 -394
  177. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  178. package/dist/es/transformer/object-types.js +0 -52
  179. package/dist/es/transformer/project-bundle.js +0 -85
  180. package/dist/es/transformer/serializer.js +0 -17
  181. package/dist/es/transformer/timestamp.js +0 -16
  182. package/dist/es/transformer/update-identifiers.js +0 -87
  183. package/dist/types/jats/importer/index.d.ts +0 -16
  184. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  185. package/dist/types/jats/importer/jats-reference-parser.d.ts +0 -19
  186. package/dist/types/jats/importer/jats-references.d.ts +0 -12
  187. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  188. package/dist/types/transformer/builders.d.ts +0 -61
  189. package/dist/types/transformer/decode.d.ts +0 -50
  190. package/dist/types/transformer/document-object-types.d.ts +0 -17
  191. package/dist/types/transformer/encode.d.ts +0 -29
  192. package/dist/types/transformer/filename.d.ts +0 -16
  193. package/dist/types/transformer/footnote-category.d.ts +0 -17
  194. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  195. package/dist/types/transformer/html.d.ts +0 -36
  196. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  197. package/dist/types/transformer/model-map.d.ts +0 -19
  198. package/dist/types/transformer/models.d.ts +0 -48
  199. package/dist/types/transformer/object-types.d.ts +0 -30
  200. package/dist/types/transformer/project-bundle.d.ts +0 -30
  201. package/dist/types/transformer/serializer.d.ts +0 -19
  202. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  203. package/dist/types/types.d.ts +0 -2
  204. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  205. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -0,0 +1,370 @@
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 { defaultTitle } from '../../lib/deafults';
17
+ import { abstractsType, backmatterType, bodyType, } from '../../lib/section-group-type';
18
+ import { chooseSectionCategoryByType, chooseSecType } from '../../transformer';
19
+ import { htmlFromJatsNode } from './jats-parser-utils';
20
+ const removeNodeFromParent = (node) => node.parentNode && node.parentNode.removeChild(node);
21
+ const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
22
+ const createSectionGroup = (type, createElement) => {
23
+ const sec = createElement('sec');
24
+ sec.setAttribute('sec-type', type._id);
25
+ const title = createElement('title');
26
+ title.textContent = type.title;
27
+ sec.appendChild(title);
28
+ return sec;
29
+ };
30
+ export const ensureSection = (body, createElement) => {
31
+ let section;
32
+ const element = body.firstElementChild;
33
+ if (element && element.tagName === 'sec') {
34
+ section = element;
35
+ }
36
+ else {
37
+ section = createElement('sec');
38
+ body.insertBefore(section, body.firstChild);
39
+ }
40
+ body.childNodes.forEach((child) => {
41
+ if (child.nodeType === Node.ELEMENT_NODE) {
42
+ const element = child;
43
+ if (element.tagName !== 'sec') {
44
+ section.appendChild(element);
45
+ }
46
+ else {
47
+ section = element;
48
+ }
49
+ }
50
+ });
51
+ };
52
+ export const moveTitle = (front, createElement) => {
53
+ var _a, _b;
54
+ let title = front.querySelector('article-meta > title-group > article-title');
55
+ if (title) {
56
+ title.innerHTML = (_a = htmlFromJatsNode(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle;
57
+ }
58
+ else {
59
+ title = createElement('article-title');
60
+ title.innerHTML = defaultTitle;
61
+ }
62
+ (_b = front.parentNode) === null || _b === void 0 ? void 0 : _b.insertBefore(title, front);
63
+ };
64
+ export const moveAuthorNotes = (front, createElement) => {
65
+ var _a;
66
+ const authorNotes = front.querySelector('article-meta > author-notes');
67
+ if (authorNotes) {
68
+ const sectionTitle = createElement('title');
69
+ authorNotes.prepend(sectionTitle);
70
+ (_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(authorNotes, front);
71
+ }
72
+ };
73
+ export const moveContributors = (front, createElement) => {
74
+ var _a;
75
+ const contribs = front.querySelectorAll('contrib-group > contrib[contrib-type="author"]');
76
+ if (contribs.length) {
77
+ const contributors = createElement('contributors');
78
+ contribs.forEach((c) => contributors.appendChild(c));
79
+ (_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(contributors, front);
80
+ }
81
+ };
82
+ export const moveAffiliations = (front, createElement) => {
83
+ var _a;
84
+ const affs = front.querySelectorAll('article-meta > contrib-group > aff');
85
+ if (affs.length) {
86
+ const affiliations = createElement('affiliations');
87
+ affs.forEach((a) => affiliations.appendChild(a));
88
+ (_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(affiliations, front);
89
+ }
90
+ };
91
+ export const moveAbstracts = (doc, group, createElement) => {
92
+ const abstracts = doc.querySelectorAll('front > article-meta > abstract');
93
+ abstracts.forEach((abstract) => {
94
+ const sec = createAbstractSection(abstract, createElement);
95
+ removeNodeFromParent(abstract);
96
+ group.appendChild(sec);
97
+ });
98
+ };
99
+ export const createBoxedElementSection = (body, createElement) => {
100
+ const boxedTexts = body.querySelectorAll('boxed-text');
101
+ for (const boxedText of boxedTexts) {
102
+ const boxElementSec = createElement('sec');
103
+ boxElementSec.setAttribute('sec-type', 'box-element');
104
+ const title = createElement('title');
105
+ title.textContent = 'BoxElement';
106
+ boxElementSec.append(title);
107
+ for (const element of [...boxedText.children]) {
108
+ if ((element === null || element === void 0 ? void 0 : element.tagName) === 'label' || (element === null || element === void 0 ? void 0 : element.tagName) === 'caption') {
109
+ boxElementSec.append(element);
110
+ }
111
+ }
112
+ const containerSection = createElement('sec');
113
+ containerSection.append(...boxedText.children);
114
+ boxElementSec.append(containerSection);
115
+ boxedText.replaceWith(boxElementSec);
116
+ }
117
+ };
118
+ export const createBody = (doc, body, createElement) => {
119
+ const group = createSectionGroup(bodyType, createElement);
120
+ const sections = doc.querySelectorAll('body > sec:not([sec-type="backmatter"]), body > sec:not([sec-type])');
121
+ sections.forEach((section) => {
122
+ removeNodeFromParent(section);
123
+ group.appendChild(section);
124
+ });
125
+ moveFloatsGroupToBody(doc, group, createElement);
126
+ body.append(group);
127
+ };
128
+ export const createAbstracts = (doc, body, createElement) => {
129
+ const group = createSectionGroup(abstractsType, createElement);
130
+ moveAbstracts(doc, group, createElement);
131
+ body.insertBefore(group, body.lastElementChild);
132
+ };
133
+ export const createBackmatter = (doc, body, createElement) => {
134
+ const group = createSectionGroup(backmatterType, createElement);
135
+ moveBackSections(doc, group);
136
+ moveAppendices(doc, group, createElement);
137
+ moveSpecialFootnotes(doc, group, createElement);
138
+ moveFootnotes(doc, group, createElement);
139
+ moveAcknowledgments(doc, group, createElement);
140
+ body.append(group);
141
+ };
142
+ const moveFootnotes = (doc, group, createElement) => {
143
+ var _a;
144
+ const fns = [
145
+ ...doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'),
146
+ ];
147
+ let section = doc.querySelector('sec[sec-type="endnotes"]');
148
+ const fnGroup = (section === null || section === void 0 ? void 0 : section.querySelector('fn-group')) || createElement('fn-group');
149
+ fns.forEach((fn) => {
150
+ if (!fn.getAttribute('fn-type')) {
151
+ fnGroup.appendChild(fn);
152
+ }
153
+ });
154
+ if (!section && fnGroup.innerHTML) {
155
+ section = createFootnotesSection([fnGroup], createElement);
156
+ }
157
+ if (section) {
158
+ group.insertBefore(section, ((_a = group.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling) || group.firstChild);
159
+ }
160
+ };
161
+ const moveSpecialFootnotes = (doc, group, createElement) => {
162
+ var _a;
163
+ const fns = [...doc.querySelectorAll('fn[fn-type]')];
164
+ for (const fn of fns) {
165
+ const type = fn.getAttribute('fn-type') || '';
166
+ const category = chooseSectionCategoryByType(type);
167
+ if (category) {
168
+ const section = createElement('sec');
169
+ const fnTitle = fn.querySelector('p[content-type="fn-title"]');
170
+ if (fnTitle) {
171
+ const title = createElement('title');
172
+ const titleText = (_a = fnTitle.textContent) === null || _a === void 0 ? void 0 : _a.trim();
173
+ if (titleText) {
174
+ title.textContent = titleText;
175
+ }
176
+ removeNodeFromParent(fnTitle);
177
+ section.append(title);
178
+ }
179
+ section.append(...fn.children);
180
+ removeNodeFromParent(fn);
181
+ section.setAttribute('sec-type', chooseSecType(category));
182
+ group.append(section);
183
+ }
184
+ }
185
+ };
186
+ export const moveCaptionsToEnd = (body) => {
187
+ const captions = body.querySelectorAll('caption');
188
+ for (const caption of captions) {
189
+ if (caption.parentNode &&
190
+ caption.parentNode.nodeName !== 'table-wrap' &&
191
+ caption.parentNode.nodeName !== 'boxed-text') {
192
+ caption.parentNode.appendChild(caption);
193
+ }
194
+ }
195
+ };
196
+ const createAbstractSection = (abstract, createElement) => {
197
+ const abstractType = abstract.getAttribute('abstract-type');
198
+ const section = createElement('sec');
199
+ const sectionType = abstractType ? `abstract-${abstractType}` : 'abstract';
200
+ section.setAttribute('sec-type', sectionType);
201
+ if (!abstract.querySelector(':scope > title')) {
202
+ const title = createElement('title');
203
+ title.textContent = abstractType
204
+ ? `${capitalizeFirstLetter(abstractType)} Abstract`
205
+ : 'Abstract';
206
+ section.appendChild(title);
207
+ }
208
+ while (abstract.firstChild) {
209
+ section.appendChild(abstract.firstChild);
210
+ }
211
+ return section;
212
+ };
213
+ const createAcknowledgmentsSection = (ack, createElement) => {
214
+ const section = createElement('sec');
215
+ section.setAttribute('sec-type', 'acknowledgments');
216
+ if (!ack.querySelector('title')) {
217
+ const title = createElement('title');
218
+ title.textContent = 'Acknowledgements';
219
+ section.appendChild(title);
220
+ }
221
+ while (ack.firstChild) {
222
+ section.appendChild(ack.firstChild);
223
+ }
224
+ return section;
225
+ };
226
+ const createFootnotesSection = (fnGroups, createElement) => {
227
+ const section = createElement('sec');
228
+ section.setAttribute('sec-type', 'endnotes');
229
+ const titleNode = fnGroups
230
+ .map((g) => g.querySelector('title'))
231
+ .filter((t) => t !== null)[0];
232
+ if (titleNode) {
233
+ section.appendChild(titleNode);
234
+ }
235
+ else {
236
+ const title = createElement('title');
237
+ title.textContent = 'Footnotes';
238
+ section.appendChild(title);
239
+ }
240
+ for (const fnGroup of fnGroups) {
241
+ section.appendChild(fnGroup);
242
+ }
243
+ return section;
244
+ };
245
+ const createAppendicesSection = (app, createElement) => {
246
+ const section = createElement('sec');
247
+ section.setAttribute('sec-type', 'appendices');
248
+ section.append(...app.children);
249
+ return section;
250
+ };
251
+ const createFloatsGroupSection = (floatsGroup, createElement) => {
252
+ const section = createElement('sec');
253
+ section.setAttribute('sec-type', 'floating-element');
254
+ const title = createElement('title');
255
+ title.textContent = 'Floating Group';
256
+ section.appendChild(title);
257
+ section.append(...floatsGroup.children);
258
+ return section;
259
+ };
260
+ const moveBackSections = (doc, group) => {
261
+ for (const section of doc.querySelectorAll('back > sec')) {
262
+ removeNodeFromParent(section);
263
+ group.appendChild(section);
264
+ }
265
+ };
266
+ const moveAcknowledgments = (doc, group, createElement) => {
267
+ const ack = doc.querySelector('back > ack');
268
+ if (ack) {
269
+ const section = createAcknowledgmentsSection(ack, createElement);
270
+ removeNodeFromParent(ack);
271
+ group.appendChild(section);
272
+ }
273
+ };
274
+ const moveAppendices = (doc, group, createElement) => {
275
+ const apps = doc.querySelectorAll('back > app-group > app');
276
+ for (const app of apps) {
277
+ const section = createAppendicesSection(app, createElement);
278
+ removeNodeFromParent(app);
279
+ group.appendChild(section);
280
+ }
281
+ };
282
+ const moveFloatsGroupToBody = (doc, body, createElement) => {
283
+ const floatsGroup = doc.querySelector('floats-group');
284
+ if (floatsGroup) {
285
+ const sec = createFloatsGroupSection(floatsGroup, createElement);
286
+ removeNodeFromParent(floatsGroup);
287
+ body.appendChild(sec);
288
+ }
289
+ };
290
+ export const createKeywordsSection = (document, body, createElement) => {
291
+ const kwdGroups = [...document.querySelectorAll('kwd-group')];
292
+ if (kwdGroups.length > 0) {
293
+ const section = createElement('sec');
294
+ section.setAttribute('sec-type', 'keywords');
295
+ const title = createElement('title');
296
+ title.textContent = 'Keywords';
297
+ section.append(title);
298
+ const kwdGroupList = createElement('kwd-group-list');
299
+ kwdGroupList.append(kwdGroups[0]);
300
+ section.append(kwdGroupList);
301
+ body.prepend(section);
302
+ }
303
+ };
304
+ export const createSupplementaryMaterialsSection = (document, body, createElement) => {
305
+ const suppls = [
306
+ ...document.querySelectorAll('article-meta > supplementary-material'),
307
+ ];
308
+ if (suppls.length) {
309
+ const section = createElement('sec');
310
+ section.setAttribute('sec-type', 'supplementary-material');
311
+ const title = createElement('title');
312
+ title.textContent = 'Supplementary Material';
313
+ section.append(title);
314
+ section.append(...suppls);
315
+ body.prepend(section);
316
+ }
317
+ };
318
+ export const moveReferencesToBackmatter = (body, back, createElement) => {
319
+ const backmatter = body.querySelector('sec[sec-type="backmatter"]');
320
+ const refList = back.querySelector('ref-list');
321
+ if (!backmatter || !refList) {
322
+ return;
323
+ }
324
+ removeNodeFromParent(refList);
325
+ const section = createElement('sec');
326
+ section.setAttribute('sec-type', 'bibliography');
327
+ const title = createElement('title');
328
+ title.textContent = 'References';
329
+ section.appendChild(title);
330
+ section.appendChild(refList);
331
+ backmatter.appendChild(section);
332
+ };
333
+ export const orderTableFootnote = (doc, body) => {
334
+ const rids = new Set([...body.querySelectorAll('tbody > xref[ref-type="fn"]')].map((xref) => xref.getAttribute('rid')));
335
+ const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
336
+ fnGroups.forEach((fnGroup) => {
337
+ const fns = [...fnGroup.querySelectorAll('fn')].sort((fn) => rids.has(fn.getAttribute('id')) ? -1 : 0);
338
+ fnGroup.replaceChildren(...fns);
339
+ });
340
+ };
341
+ export const fixTables = (doc, body, createElement) => {
342
+ const tableWraps = body.querySelectorAll('table-wrap');
343
+ tableWraps.forEach((tableWrap) => {
344
+ const table = tableWrap.querySelector('table');
345
+ if (!table) {
346
+ return;
347
+ }
348
+ const colgroup = table.querySelector('colgroup');
349
+ const cols = table.querySelectorAll('col');
350
+ if (!colgroup && table.firstChild && cols.length > 0) {
351
+ const colgroup = createElement('colgroup');
352
+ for (const col of cols) {
353
+ colgroup.appendChild(col);
354
+ }
355
+ tableWrap.insertBefore(colgroup, table.nextSibling);
356
+ }
357
+ const tableFootWrap = tableWrap.querySelector('table-wrap-foot');
358
+ if (tableFootWrap) {
359
+ const paragraphs = tableFootWrap.querySelectorAll(':scope > p');
360
+ if (paragraphs.length) {
361
+ const generalTableFootnote = createElement('general-table-footnote');
362
+ for (const paragraph of paragraphs) {
363
+ removeNodeFromParent(paragraph);
364
+ generalTableFootnote.append(paragraph);
365
+ }
366
+ tableFootWrap.prepend(generalTableFootnote);
367
+ }
368
+ }
369
+ });
370
+ };
@@ -13,111 +13,56 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { InvalidInput } from '../../errors';
17
- import { buildBibliographyElement, buildSection, encode, } from '../../transformer';
18
- import { buildManuscript } from '../../transformer/builders';
19
- import { generateID } from '../../transformer/id';
20
- import { findManuscript } from '../../transformer/project-bundle';
21
- import { jatsBodyDOMParser } from './jats-body-dom-parser';
22
- import { jatsBodyTransformations } from './jats-body-transformations';
23
- import { createComments, createReferenceComments, markComments, } from './jats-comments';
24
- import { jatsFrontParser } from './jats-front-parser';
16
+ import { markComments } from './jats-comments';
17
+ import { jatsDOMParser } from './jats-dom-parser';
18
+ import { parseJournal } from './jats-journal-meta-parser';
25
19
  import { updateDocumentIDs } from './jats-parser-utils';
26
- import { jatsReferenceParser } from './jats-reference-parser';
27
- export const parseJATSFront = (doc, front) => {
20
+ import { createAbstracts, createBackmatter, createBody, createBoxedElementSection, createKeywordsSection, createSupplementaryMaterialsSection, ensureSection, fixTables, moveAffiliations, moveAuthorNotes, moveCaptionsToEnd, moveContributors, moveReferencesToBackmatter, moveTitle, orderTableFootnote, } from './jats-transformations';
21
+ const processJATS = (doc) => {
28
22
  const createElement = createElementFn(doc);
29
- const journal = jatsFrontParser.parseJournal(front.querySelector('journal-meta'));
30
- const titles = jatsFrontParser.parseTitles(front.querySelector('article-meta > title-group'), createElement);
31
- const DOI = jatsFrontParser.parseDOI(front);
32
- const { affiliations, affiliationIDs } = jatsFrontParser.parseAffiliations([
33
- ...front.querySelectorAll('article-meta > contrib-group > aff'),
34
- ]);
35
- const { footnotes, footnoteIDs, authorNotes, authorNotesParagraphs, correspondingIDs, correspondingList, } = jatsFrontParser.parseAuthorNotes(front.querySelector('article-meta > author-notes'));
36
- const authors = jatsFrontParser.parseContributors([
37
- ...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
38
- ], affiliationIDs, footnoteIDs, correspondingIDs);
39
- const history = jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
40
- const counts = jatsFrontParser.parseCounts(front.querySelector('article-meta counts'));
41
- const manuscript = Object.assign(Object.assign(Object.assign(Object.assign({}, buildManuscript()), counts), history), { DOI });
42
- return generateIDs([
43
- manuscript,
44
- titles,
45
- journal,
46
- ...authorNotesParagraphs,
47
- ...authorNotes,
48
- ...footnotes,
49
- ...authors,
50
- ...affiliations,
51
- ...correspondingList,
52
- ]);
53
- };
54
- export const parseJATSBody = (doc, body, references) => {
55
- const createElement = createElementFn(doc);
56
- jatsBodyTransformations.ensureSection(body, createElement);
57
- jatsBodyTransformations.moveCaptionsToEnd(body);
58
- jatsBodyTransformations.fixTables(body, createElement);
59
- jatsBodyTransformations.createBody(doc, body, createElement);
60
- jatsBodyTransformations.createAbstracts(doc, body, createElement);
61
- jatsBodyTransformations.createBackmatter(doc, body, createElement);
62
- jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
63
- jatsBodyTransformations.createKeywords(doc, body, createElement);
64
- jatsBodyTransformations.orderTableFootnote(doc, body);
65
- const node = jatsBodyDOMParser.parse(body).firstChild;
66
- if (!node) {
67
- throw new Error('No content was parsed from the JATS article body');
68
- }
69
- const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
70
- updateDocumentIDs(node, replacements);
71
- return encode(node).values();
72
- };
73
- const createBibliographyModels = (references) => {
74
- const models = [];
75
- const bibliographyItems = references.getBibliographyItems();
76
- const bibliographyElement = buildBibliographyElement(bibliographyItems);
77
- const bibliographySection = Object.assign(Object.assign({}, buildSection(99)), { category: 'MPSectionCategory:bibliography', elementIDs: [bibliographyElement._id], title: 'References' });
78
- const comments = createReferenceComments(references);
79
- models.push(bibliographySection);
80
- models.push(bibliographyElement);
81
- models.push(...bibliographyItems);
82
- models.push(...comments);
83
- return models;
84
- };
85
- const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
86
- const generateIDs = (models) => models.map((m) => m._id ? m : Object.assign(Object.assign({}, m), { _id: generateID(m.objectType) }));
87
- export const parseJATSArticle = (doc) => {
88
- const article = doc.querySelector('article');
23
+ markComments(doc);
89
24
  const front = doc.querySelector('front');
90
- const body = doc.querySelector('body');
91
- const back = doc.querySelector('back');
92
25
  if (!front) {
93
- throw new InvalidInput('Invalid JATS format! Missing front element');
26
+ return;
94
27
  }
95
- if (!article) {
96
- throw new InvalidInput('Invalid JATS format! Missing article element');
97
- }
98
- const marks = markComments(doc);
99
- const createElement = createElementFn(doc);
100
- const models = [];
101
- let references;
102
- if (back) {
103
- references = jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
104
- }
105
- models.push(...parseJATSFront(doc, front));
106
- if (body) {
107
- models.push(...parseJATSBody(doc, body, references));
28
+ moveTitle(front, createElement);
29
+ moveContributors(front, createElement);
30
+ moveAffiliations(front, createElement);
31
+ moveAuthorNotes(front, createElement);
32
+ const body = doc.querySelector('body');
33
+ if (!body) {
34
+ return;
108
35
  }
109
- const modelMap = new Map(models.map((model) => [model._id, model]));
110
- const manuscript = findManuscript(modelMap);
111
- if (manuscript) {
112
- const type = article.getAttribute('article-type');
113
- manuscript.articleType = type || 'other';
36
+ ensureSection(body, createElement);
37
+ moveCaptionsToEnd(body);
38
+ createBoxedElementSection(body, createElement);
39
+ createBody(doc, body, createElement);
40
+ createAbstracts(doc, body, createElement);
41
+ createBackmatter(doc, body, createElement);
42
+ createSupplementaryMaterialsSection(doc, body, createElement);
43
+ createKeywordsSection(doc, body, createElement);
44
+ fixTables(doc, body, createElement);
45
+ orderTableFootnote(doc, body);
46
+ const back = doc.querySelector('back');
47
+ if (!back) {
48
+ return;
114
49
  }
115
- if (references && references.items.size) {
116
- models.push(...createBibliographyModels(references));
50
+ moveReferencesToBackmatter(body, back, createElement);
51
+ };
52
+ const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
53
+ export const parseJATSArticle = (doc, template) => {
54
+ const journal = parseJournal(doc);
55
+ processJATS(doc);
56
+ const node = jatsDOMParser.parse(doc).firstChild;
57
+ if (!node) {
58
+ throw new Error('No content was parsed from the JATS article body');
117
59
  }
118
- if (marks.length) {
119
- const comments = createComments(models, marks);
120
- models.push(...comments);
60
+ updateDocumentIDs(node);
61
+ if (template) {
62
+ node.attrs.prototype = template;
121
63
  }
122
- return models;
64
+ return {
65
+ node,
66
+ journal,
67
+ };
123
68
  };
@@ -13,6 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { parseJATSFront, parseJATSBody, parseJATSArticle } from './importer';
17
- export * from './jats-exporter';
18
- export * from './jats-versions';
16
+ export * from './exporter/jats-exporter';
17
+ export * from './exporter/jats-versions';
18
+ export * from './exporter/labels';
19
+ export * from './importer/create-article-node';
20
+ export { parseJATSArticle } from './importer/parse-jats-article';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2019 Atypon Systems LLC
2
+ * © 2024 Atypon Systems LLC
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const timestamp: () => number;
16
+ export const defaultTitle = 'Untitled Manuscript';
@@ -74,3 +74,4 @@ export const getTrimmedTextContent = (node, querySelector) => {
74
74
  }
75
75
  return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
76
76
  };
77
+ export const timestamp = () => Math.floor(Date.now() / 1000);
@@ -20,12 +20,15 @@ import { affiliation } from './nodes/affiliation';
20
20
  import { affiliations } from './nodes/affiliations';
21
21
  import { attribution } from './nodes/attribution';
22
22
  import { authorNotes } from './nodes/author_notes';
23
+ import { award } from './nodes/award';
24
+ import { awards } from './nodes/awards';
23
25
  import { backmatter } from './nodes/backmatter';
24
26
  import { bibliographyElement } from './nodes/bibliography_element';
25
27
  import { bibliographyItem } from './nodes/bibliography_item';
26
28
  import { bibliographySection } from './nodes/bibliography_section';
27
29
  import { blockquoteElement } from './nodes/blockquote_element';
28
30
  import { body } from './nodes/body';
31
+ import { box_element } from './nodes/box_element';
29
32
  import { caption } from './nodes/caption';
30
33
  import { captionTitle } from './nodes/caption_title';
31
34
  import { citation } from './nodes/citation';
@@ -103,7 +106,9 @@ export * from './nodes/footnotes_section';
103
106
  export * from './nodes/graphical_abstract_section';
104
107
  export * from './nodes/hard_break';
105
108
  export * from './nodes/highlight_marker';
109
+ export * from './nodes/inline_equation';
106
110
  export * from './nodes/inline_footnote';
111
+ export * from './nodes/keyword_group';
107
112
  export * from './nodes/keyword';
108
113
  export * from './nodes/keywords_element';
109
114
  export * from './nodes/keywords';
@@ -133,6 +138,8 @@ export * from './nodes/affiliations';
133
138
  export * from './nodes/contributors';
134
139
  export * from './nodes/supplement';
135
140
  export * from './nodes/supplements';
141
+ export * from './nodes/corresp';
142
+ export * from './nodes/author_notes';
136
143
  export const schema = new Schema({
137
144
  marks: {
138
145
  bold,
@@ -216,5 +223,8 @@ export const schema = new Schema({
216
223
  supplement,
217
224
  author_notes: authorNotes,
218
225
  corresp,
226
+ box_element,
227
+ awards,
228
+ award,
219
229
  },
220
230
  });
@@ -23,16 +23,10 @@ export function migrateFor(oldDoc, baseVersion) {
23
23
  console.log('Migrating doc with script to version ' + script.toVersion);
24
24
  migratedDoc = migrate(migratedDoc, script.migrateNode);
25
25
  }
26
- return testDoc(migratedDoc, oldDoc, baseVersion);
26
+ return testDoc(migratedDoc, baseVersion);
27
27
  }
28
- function ensureVersionAscOrder() {
29
- return migrationScripts.sort((a, b) => semver.eq(a.toVersion, b.toVersion)
30
- ? 0
31
- : semver.gt(a.toVersion, b.toVersion)
32
- ? 1
33
- : -1);
34
- }
35
- function testDoc(doc, oldDoc, fromVersion) {
28
+ const ensureVersionAscOrder = () => migrationScripts.sort((a, b) => semver.compare(a.toVersion, b.toVersion));
29
+ function testDoc(doc, fromVersion) {
36
30
  try {
37
31
  const resultDoc = schema.nodeFromJSON(doc);
38
32
  resultDoc.check();
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2019 Atypon Systems LLC
2
+ * © 2024 Atypon Systems LLC
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2019 Atypon Systems LLC
2
+ * © 2024 Atypon Systems LLC
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
16
16
  class Migration125 {
17
17
  constructor() {
18
18
  this.fromVersion = '1.2.3';
19
- this.toVersion = '1.2.4';
19
+ this.toVersion = '1.2.5';
20
20
  }
21
21
  migrateNode(node, doc) {
22
22
  if (node.type === 'paragraph') {
@@ -0,0 +1,26 @@
1
+ class Migration2322 {
2
+ constructor() {
3
+ this.fromVersion = '2.3.21';
4
+ this.toVersion = '2.3.22';
5
+ }
6
+ migrateNode(node) {
7
+ if (node.type === 'table_element' && Array.isArray(node.content)) {
8
+ let figcaptionNode = null;
9
+ const remainingContent = [];
10
+ for (const child of node.content) {
11
+ if (child.type === 'figcaption') {
12
+ figcaptionNode = child;
13
+ }
14
+ else {
15
+ remainingContent.push(child);
16
+ }
17
+ }
18
+ const newContent = figcaptionNode
19
+ ? [figcaptionNode, ...remainingContent]
20
+ : remainingContent;
21
+ return Object.assign(Object.assign({}, node), { content: newContent });
22
+ }
23
+ return node;
24
+ }
25
+ }
26
+ export default Migration2322;