@manuscripts/transform 1.5.8 → 2.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 (133) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/jats/importer/index.js +1 -3
  3. package/dist/cjs/jats/importer/jats-body-dom-parser.js +23 -227
  4. package/dist/cjs/jats/importer/jats-body-transformations.js +110 -201
  5. package/dist/cjs/jats/importer/jats-comments.js +100 -98
  6. package/dist/cjs/jats/importer/jats-front-parser.js +87 -81
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +51 -39
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +17 -56
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +24 -79
  10. package/dist/cjs/jats/importer/jats-references.js +34 -0
  11. package/dist/cjs/jats/importer/parse-jats-article.js +67 -173
  12. package/dist/cjs/jats/index.js +1 -3
  13. package/dist/cjs/jats/jats-exporter.js +34 -55
  14. package/dist/cjs/lib/section-group-type.js +30 -0
  15. package/dist/cjs/lib/utils.js +1 -25
  16. package/dist/cjs/schema/index.js +20 -17
  17. package/dist/cjs/schema/nodes/abstracts.js +27 -0
  18. package/dist/cjs/schema/nodes/affiliations.js +27 -0
  19. package/dist/cjs/schema/nodes/backmatter.js +27 -0
  20. package/dist/cjs/schema/nodes/body.js +27 -0
  21. package/dist/cjs/schema/nodes/citation.js +10 -15
  22. package/dist/cjs/schema/nodes/{comment_list.js → comments.js} +4 -4
  23. package/dist/cjs/schema/nodes/contributors.js +27 -0
  24. package/dist/cjs/schema/nodes/{meta_section.js → core_section.js} +6 -5
  25. package/dist/cjs/schema/nodes/cross_reference.js +4 -3
  26. package/dist/cjs/schema/nodes/inline_footnote.js +6 -5
  27. package/dist/cjs/schema/nodes/keyword.js +0 -1
  28. package/dist/cjs/schema/nodes/{keywords_group.js → keyword_group.js} +6 -6
  29. package/dist/cjs/schema/nodes/{keywords_section.js → keywords.js} +7 -7
  30. package/dist/cjs/schema/nodes/keywords_element.js +1 -1
  31. package/dist/cjs/schema/nodes/manuscript.js +5 -2
  32. package/dist/cjs/transformer/builders.js +9 -86
  33. package/dist/cjs/transformer/decode.js +147 -176
  34. package/dist/cjs/transformer/encode.js +66 -67
  35. package/dist/cjs/transformer/highlight-markers.js +48 -36
  36. package/dist/cjs/transformer/html.js +7 -23
  37. package/dist/cjs/transformer/labels.js +3 -17
  38. package/dist/cjs/transformer/node-names.js +1 -1
  39. package/dist/cjs/transformer/node-title.js +1 -1
  40. package/dist/cjs/transformer/node-types.js +7 -6
  41. package/dist/cjs/transformer/object-types.js +1 -2
  42. package/dist/cjs/transformer/section-category.js +31 -31
  43. package/dist/es/index.js +1 -1
  44. package/dist/es/jats/importer/index.js +1 -1
  45. package/dist/es/jats/importer/jats-body-dom-parser.js +23 -227
  46. package/dist/es/jats/importer/jats-body-transformations.js +111 -202
  47. package/dist/es/jats/importer/jats-comments.js +97 -96
  48. package/dist/es/jats/importer/jats-front-parser.js +88 -82
  49. package/dist/es/jats/importer/jats-journal-meta-parser.js +51 -39
  50. package/dist/es/jats/importer/jats-parser-utils.js +16 -54
  51. package/dist/es/jats/importer/jats-reference-parser.js +27 -82
  52. package/dist/es/jats/importer/jats-references.js +30 -0
  53. package/dist/es/jats/importer/parse-jats-article.js +70 -174
  54. package/dist/es/jats/index.js +1 -1
  55. package/dist/es/jats/jats-exporter.js +34 -55
  56. package/dist/es/lib/section-group-type.js +27 -0
  57. package/dist/es/lib/utils.js +0 -22
  58. package/dist/es/schema/index.js +21 -18
  59. package/dist/es/schema/nodes/abstracts.js +24 -0
  60. package/dist/es/schema/nodes/affiliations.js +24 -0
  61. package/dist/es/schema/nodes/backmatter.js +24 -0
  62. package/dist/es/schema/nodes/body.js +24 -0
  63. package/dist/es/schema/nodes/citation.js +10 -15
  64. package/dist/es/schema/nodes/{comment_list.js → comments.js} +3 -3
  65. package/dist/es/schema/nodes/contributors.js +24 -0
  66. package/dist/es/schema/nodes/{meta_section.js → core_section.js} +5 -4
  67. package/dist/es/schema/nodes/cross_reference.js +4 -3
  68. package/dist/es/schema/nodes/inline_footnote.js +6 -5
  69. package/dist/es/schema/nodes/keyword.js +0 -1
  70. package/dist/es/schema/nodes/{keywords_group.js → keyword_group.js} +4 -4
  71. package/dist/es/schema/nodes/{keywords_section.js → keywords.js} +5 -5
  72. package/dist/es/schema/nodes/keywords_element.js +1 -1
  73. package/dist/es/schema/nodes/manuscript.js +3 -1
  74. package/dist/es/transformer/builders.js +6 -73
  75. package/dist/es/transformer/decode.js +147 -175
  76. package/dist/es/transformer/encode.js +70 -71
  77. package/dist/es/transformer/highlight-markers.js +44 -32
  78. package/dist/es/transformer/html.js +7 -23
  79. package/dist/es/transformer/labels.js +3 -17
  80. package/dist/es/transformer/node-names.js +1 -1
  81. package/dist/es/transformer/node-title.js +1 -1
  82. package/dist/es/transformer/node-types.js +7 -6
  83. package/dist/es/transformer/object-types.js +0 -1
  84. package/dist/es/transformer/section-category.js +29 -29
  85. package/dist/types/index.d.ts +1 -1
  86. package/dist/types/jats/importer/index.d.ts +1 -1
  87. package/dist/types/jats/importer/jats-body-transformations.d.ts +16 -19
  88. package/dist/types/jats/importer/jats-comments.d.ts +13 -9
  89. package/dist/types/jats/importer/jats-front-parser.d.ts +35 -12
  90. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +4 -4
  91. package/dist/types/jats/importer/jats-parser-utils.d.ts +1 -6
  92. package/dist/types/jats/importer/jats-reference-parser.d.ts +2 -6
  93. package/dist/types/jats/importer/jats-references.d.ts +12 -0
  94. package/dist/types/jats/importer/parse-jats-article.d.ts +5 -17
  95. package/dist/types/jats/index.d.ts +1 -1
  96. package/dist/types/lib/section-group-type.d.ts +23 -0
  97. package/dist/types/lib/utils.d.ts +1 -4
  98. package/dist/types/schema/index.d.ts +4 -5
  99. package/dist/types/schema/nodes/{meta_section.d.ts → abstracts.d.ts} +1 -9
  100. package/dist/types/schema/nodes/affiliations.d.ts +17 -0
  101. package/dist/types/schema/nodes/backmatter.d.ts +17 -0
  102. package/dist/types/schema/nodes/body.d.ts +17 -0
  103. package/dist/types/schema/nodes/citation.d.ts +3 -5
  104. package/dist/types/schema/nodes/comments.d.ts +17 -0
  105. package/dist/types/schema/nodes/contributors.d.ts +17 -0
  106. package/dist/types/schema/nodes/core_section.d.ts +17 -0
  107. package/dist/types/schema/nodes/cross_reference.d.ts +1 -1
  108. package/dist/types/schema/nodes/inline_footnote.d.ts +1 -1
  109. package/dist/types/schema/nodes/keyword.d.ts +0 -1
  110. package/dist/types/schema/nodes/{contributors_element.d.ts → keyword_group.d.ts} +3 -4
  111. package/dist/types/schema/nodes/{comment_list.d.ts → keywords.d.ts} +3 -2
  112. package/dist/types/schema/nodes/manuscript.d.ts +1 -0
  113. package/dist/types/schema/types.d.ts +1 -1
  114. package/dist/types/transformer/builders.d.ts +2 -14
  115. package/dist/types/transformer/decode.d.ts +5 -9
  116. package/dist/types/transformer/encode.d.ts +4 -4
  117. package/dist/types/transformer/highlight-markers.d.ts +7 -2
  118. package/dist/types/transformer/object-types.d.ts +1 -2
  119. package/dist/types/transformer/section-category.d.ts +4 -3
  120. package/package.json +1 -6
  121. package/dist/cjs/lib/core-section-categories.js +0 -29
  122. package/dist/cjs/schema/nodes/affiliations_section.js +0 -36
  123. package/dist/cjs/schema/nodes/contributors_element.js +0 -49
  124. package/dist/cjs/schema/nodes/contributors_section.js +0 -36
  125. package/dist/es/lib/core-section-categories.js +0 -26
  126. package/dist/es/schema/nodes/affiliations_section.js +0 -32
  127. package/dist/es/schema/nodes/contributors_element.js +0 -46
  128. package/dist/es/schema/nodes/contributors_section.js +0 -32
  129. package/dist/types/lib/core-section-categories.d.ts +0 -8
  130. package/dist/types/schema/nodes/affiliations_section.d.ts +0 -11
  131. package/dist/types/schema/nodes/contributors_section.d.ts +0 -12
  132. package/dist/types/schema/nodes/keywords_group.d.ts +0 -26
  133. package/dist/types/schema/nodes/keywords_section.d.ts +0 -26
@@ -13,34 +13,27 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { chooseSectionCategoryByType, chooseSecType, getCoreSectionTitles, } from '../../transformer';
16
+ import { abstractsType, backmatterType, bodyType, } from '../../lib/section-group-type';
17
+ import { chooseSectionCategoryByType, chooseSecType } from '../../transformer';
17
18
  const removeNodeFromParent = (node) => node.parentNode && node.parentNode.removeChild(node);
18
19
  const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
19
- const createSectionContainer = (type, createElement) => {
20
- const sectionContainer = createElement('sec');
21
- const sectionCategory = chooseSectionCategoryByType(type);
22
- sectionContainer.setAttribute('sec-type', sectionCategory ? chooseSecType(sectionCategory) : '');
20
+ const createSectionGroup = (type, createElement) => {
21
+ const sec = createElement('sec');
22
+ sec.setAttribute('sec-type', type._id);
23
23
  const title = createElement('title');
24
- title.textContent = sectionCategory
25
- ? getCoreSectionTitles(sectionCategory)[0]
26
- : ' ';
27
- sectionContainer.appendChild(title);
28
- return sectionContainer;
24
+ title.textContent = type.title;
25
+ sec.appendChild(title);
26
+ return sec;
29
27
  };
30
28
  export const jatsBodyTransformations = {
31
29
  ensureSection(body, createElement) {
32
- let section = createElement('sec');
33
- const title = section.querySelector('title');
34
- if (!title) {
35
- const title = createElement('title');
36
- title.textContent = '';
37
- section.appendChild(title);
38
- }
39
- const { firstElementChild } = body;
40
- if (firstElementChild && firstElementChild.tagName === 'sec') {
41
- section = firstElementChild;
30
+ let section;
31
+ const element = body.firstElementChild;
32
+ if (element && element.tagName === 'sec') {
33
+ section = element;
42
34
  }
43
35
  else {
36
+ section = createElement('sec');
44
37
  body.insertBefore(section, body.firstChild);
45
38
  }
46
39
  body.childNodes.forEach((child) => {
@@ -55,7 +48,7 @@ export const jatsBodyTransformations = {
55
48
  }
56
49
  });
57
50
  },
58
- createAbstract(abstractNode, createElement) {
51
+ createAbstractSection(abstractNode, createElement) {
59
52
  const abstractType = abstractNode.getAttribute('abstract-type');
60
53
  const section = createElement('sec');
61
54
  const sectionType = abstractType ? `abstract-${abstractType}` : 'abstract';
@@ -72,7 +65,7 @@ export const jatsBodyTransformations = {
72
65
  }
73
66
  return section;
74
67
  },
75
- createAcknowledgments(ackNode, createElement) {
68
+ createAcknowledgmentsSection(ackNode, createElement) {
76
69
  const section = createElement('sec');
77
70
  section.setAttribute('sec-type', 'acknowledgments');
78
71
  const titleNode = ackNode.querySelector('title');
@@ -89,40 +82,7 @@ export const jatsBodyTransformations = {
89
82
  }
90
83
  return section;
91
84
  },
92
- createBibliography(doc, references, createElement) {
93
- const bibSec = doc.createElement('sec');
94
- bibSec.setAttribute('sec-type', 'bibliography');
95
- const titleNode = doc.querySelector('back > ref-list > title');
96
- if (titleNode) {
97
- bibSec.appendChild(titleNode);
98
- }
99
- else {
100
- const title = createElement('title');
101
- title.textContent = 'References';
102
- bibSec.appendChild(title);
103
- }
104
- const refList = doc.createElement('ref-list');
105
- for (const ref of references) {
106
- const item = doc.createElement('ref');
107
- item.setAttribute('id', ref._id);
108
- item.setAttribute('type', ref.type);
109
- item.setAttribute('author', JSON.stringify(ref.author));
110
- item.setAttribute('issued', JSON.stringify(ref.issued));
111
- ref['container-title'] &&
112
- item.setAttribute('container-title', ref['container-title']);
113
- ref.DOI && item.setAttribute('doi', ref.DOI);
114
- ref.volume && item.setAttribute('volume', ref.volume.toString());
115
- ref.issue && item.setAttribute('issue', ref.issue.toString());
116
- ref.supplement && item.setAttribute('supplement', ref.supplement);
117
- ref.page && item.setAttribute('page', ref.page.toString());
118
- ref.title && item.setAttribute('title', ref.title);
119
- ref.literal && item.setAttribute('literal', ref.literal);
120
- refList.appendChild(item);
121
- }
122
- bibSec.appendChild(refList);
123
- return bibSec;
124
- },
125
- createFootnotes(footnoteGroups, createElement) {
85
+ createFootnotesSection(footnoteGroups, createElement) {
126
86
  const section = createElement('sec');
127
87
  section.setAttribute('sec-type', 'endnotes');
128
88
  const titleNode = footnoteGroups
@@ -147,81 +107,81 @@ export const jatsBodyTransformations = {
147
107
  section.append(...app.children);
148
108
  return section;
149
109
  },
150
- createFloatsGroupSection(floatsGroup, createElement) {
110
+ createFloatsGroupSection(group, createElement) {
151
111
  const section = createElement('sec');
152
112
  section.setAttribute('sec-type', 'floating-element');
153
113
  const title = createElement('title');
154
114
  title.textContent = 'Floating Group';
155
115
  section.appendChild(title);
156
- section.append(...floatsGroup.children);
116
+ section.append(...group.children);
157
117
  return section;
158
118
  },
159
- moveAbstractsIntoContainer(doc, abstractsContainer, createElement) {
160
- const abstractNodes = doc.querySelectorAll('front > article-meta > abstract');
161
- abstractNodes.forEach((abstractNode) => {
162
- const abstract = this.createAbstract(abstractNode, createElement);
163
- removeNodeFromParent(abstractNode);
164
- abstractsContainer.appendChild(abstract);
119
+ moveAbstracts(doc, group, createElement) {
120
+ const abstracts = doc.querySelectorAll('front > article-meta > abstract');
121
+ abstracts.forEach((abstract) => {
122
+ const sec = this.createAbstractSection(abstract, createElement);
123
+ removeNodeFromParent(abstract);
124
+ group.appendChild(sec);
165
125
  });
166
126
  },
167
- wrapBodySections(doc, bodyContainer) {
127
+ wrapBodySections(doc, group) {
168
128
  const bodySections = doc.querySelectorAll('body > sec:not([sec-type="backmatter"]), body > sec:not([sec-type])');
169
129
  bodySections.forEach((section) => {
170
130
  removeNodeFromParent(section);
171
- bodyContainer.appendChild(section);
131
+ group.appendChild(section);
172
132
  });
173
133
  },
174
- moveBackSectionsIntoContainer(doc, backmatterContainer) {
134
+ moveBackSections(doc, group) {
175
135
  for (const section of doc.querySelectorAll('back > sec')) {
176
136
  removeNodeFromParent(section);
177
- backmatterContainer.appendChild(section);
137
+ group.appendChild(section);
178
138
  }
179
139
  },
180
- moveAcknowledgmentsIntoContainer(doc, backmatterContainer, createElement) {
181
- const ackNode = doc.querySelector('back > ack');
182
- if (ackNode) {
183
- const acknowledgements = this.createAcknowledgments(ackNode, createElement);
184
- removeNodeFromParent(ackNode);
185
- backmatterContainer.appendChild(acknowledgements);
140
+ moveAcknowledgments(doc, group, createElement) {
141
+ const ack = doc.querySelector('back > ack');
142
+ if (ack) {
143
+ const sec = this.createAcknowledgmentsSection(ack, createElement);
144
+ removeNodeFromParent(ack);
145
+ group.appendChild(sec);
186
146
  }
187
147
  },
188
- moveAppendicesIntoContainer(doc, backmatterContainer, createElement) {
189
- const appGroup = doc.querySelectorAll('back > app-group > app');
190
- for (const app of appGroup) {
191
- const appendix = this.createAppendixSection(app, createElement);
148
+ moveAppendices(doc, group, createElement) {
149
+ const apps = doc.querySelectorAll('back > app-group > app');
150
+ for (const app of apps) {
151
+ const sec = this.createAppendixSection(app, createElement);
192
152
  removeNodeFromParent(app);
193
- backmatterContainer.appendChild(appendix);
153
+ group.appendChild(sec);
194
154
  }
195
155
  },
196
- moveBibliographyIntoContainer(doc, backmatterContainer, references, createElement) {
197
- if (references && references.length) {
198
- backmatterContainer.appendChild(this.createBibliography(doc, references, createElement));
199
- }
156
+ createBody(doc, body, createElement) {
157
+ const group = createSectionGroup(bodyType, createElement);
158
+ this.wrapBodySections(doc, group);
159
+ this.moveFloatsGroupToBody(doc, group, createElement);
160
+ body.append(group);
161
+ },
162
+ createAbstracts(doc, body, createElement) {
163
+ const group = createSectionGroup(abstractsType, createElement);
164
+ this.moveAbstracts(doc, group, createElement);
165
+ body.insertBefore(group, body.lastElementChild);
200
166
  },
201
- moveSectionsToBody(doc, body, references, createElement) {
202
- const bodyContainer = createSectionContainer('body', createElement);
203
- const abstractsContainer = createSectionContainer('abstracts', createElement);
204
- const backmatterContainer = createSectionContainer('backmatter', createElement);
205
- this.mapFootnotesToSections(doc, backmatterContainer, createElement);
206
- this.wrapBodySections(doc, bodyContainer);
207
- this.moveAbstractsIntoContainer(doc, abstractsContainer, createElement);
208
- this.moveBackSectionsIntoContainer(doc, backmatterContainer);
209
- this.moveAcknowledgmentsIntoContainer(doc, backmatterContainer, createElement);
210
- this.moveAppendicesIntoContainer(doc, backmatterContainer, createElement);
211
- this.moveBibliographyIntoContainer(doc, backmatterContainer, references, createElement);
212
- body.insertBefore(abstractsContainer, body.firstChild);
213
- body.insertBefore(bodyContainer, abstractsContainer.nextSibling);
214
- body.append(backmatterContainer);
167
+ createBackmatter(doc, body, createElement) {
168
+ const group = createSectionGroup(backmatterType, createElement);
169
+ this.moveBackSections(doc, group);
170
+ this.moveAppendices(doc, group, createElement);
171
+ this.moveSpecialFootnotes(doc, group, createElement);
172
+ this.moveFootnotes(doc, group, createElement);
173
+ this.moveAcknowledgments(doc, group, createElement);
174
+ body.append(group);
215
175
  },
216
- mapFootnotesToSections(doc, backmatterContainer, createElement) {
176
+ moveSpecialFootnotes(doc, group, createElement) {
217
177
  var _a;
218
- const footnoteGroups = [...doc.querySelectorAll('fn[fn-type]')];
219
- for (const footnote of footnoteGroups) {
220
- const type = footnote.getAttribute('fn-type') || '';
178
+ const fns = [...doc.querySelectorAll('fn[fn-type]')];
179
+ for (const fn of fns) {
180
+ const type = fn.getAttribute('fn-type') || '';
221
181
  const category = chooseSectionCategoryByType(type);
222
182
  if (category) {
223
183
  const section = createElement('sec');
224
- const title = footnote.querySelector('p[content-type="fn-title"]');
184
+ const title = fn.querySelector('p[content-type="fn-title"]');
225
185
  if (title) {
226
186
  const sectionTitleElement = createElement('title');
227
187
  const titleTextContent = (_a = title.textContent) === null || _a === void 0 ? void 0 : _a.trim();
@@ -231,12 +191,14 @@ export const jatsBodyTransformations = {
231
191
  removeNodeFromParent(title);
232
192
  section.append(sectionTitleElement);
233
193
  }
234
- section.append(...footnote.children);
235
- removeNodeFromParent(footnote);
194
+ section.append(...fn.children);
195
+ removeNodeFromParent(fn);
236
196
  section.setAttribute('sec-type', chooseSecType(category));
237
- backmatterContainer.append(section);
197
+ group.append(section);
238
198
  }
239
199
  }
200
+ },
201
+ moveFootnotes(doc, group, createElement) {
240
202
  const footnotes = [...doc.querySelectorAll('fn:not(table-wrap-foot fn)')];
241
203
  const footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
242
204
  const footnotesSectionGroup = footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group');
@@ -248,8 +210,8 @@ export const jatsBodyTransformations = {
248
210
  }
249
211
  }
250
212
  if (!footnotesSection && containingGroup.innerHTML) {
251
- const section = this.createFootnotes([containingGroup], createElement);
252
- backmatterContainer.append(section);
213
+ const section = this.createFootnotesSection([containingGroup], createElement);
214
+ group.append(section);
253
215
  }
254
216
  let regularFootnoteGroups = [
255
217
  ...doc.querySelectorAll('back > fn-group:not([fn-type])'),
@@ -261,8 +223,8 @@ export const jatsBodyTransformations = {
261
223
  });
262
224
  if (regularFootnoteGroups.length > 0) {
263
225
  regularFootnoteGroups.map((g) => removeNodeFromParent(g));
264
- const footnotes = this.createFootnotes(regularFootnoteGroups, createElement);
265
- backmatterContainer.appendChild(footnotes);
226
+ const footnotes = this.createFootnotesSection(regularFootnoteGroups, createElement);
227
+ group.appendChild(footnotes);
266
228
  }
267
229
  },
268
230
  moveCaptionsToEnd(body) {
@@ -273,103 +235,50 @@ export const jatsBodyTransformations = {
273
235
  }
274
236
  }
275
237
  },
276
- moveTableFooterToEnd(body) {
277
- const tableFooters = body.querySelectorAll('table-wrap-foot');
278
- for (const tableFooter of tableFooters) {
279
- if (tableFooter.parentNode) {
280
- tableFooter.parentNode.appendChild(tableFooter);
238
+ fixTables(body, createElement) {
239
+ const tables = body.querySelectorAll('table-wrap > table');
240
+ tables.forEach((table) => {
241
+ const colgroup = table.querySelector('colgroup');
242
+ const cols = table.querySelectorAll('col');
243
+ if (!colgroup && table.firstChild && cols.length > 0) {
244
+ const colgroup = createElement('colgroup');
245
+ for (const col of cols) {
246
+ colgroup.appendChild(col);
247
+ }
248
+ table.insertBefore(colgroup, table.firstChild);
281
249
  }
282
- }
283
- },
284
- moveAffiliationsToBody(doc, affiliations, body, createElement) {
285
- if (affiliations === null || affiliations === void 0 ? void 0 : affiliations.length) {
286
- const section = createElement('sec');
287
- section.setAttribute('sec-type', 'affiliations');
288
- affiliations.forEach((affiliation) => {
289
- const item = doc.createElement('aff');
290
- item.setAttribute('id', affiliation._id);
291
- affiliation.institution &&
292
- item.setAttribute('institution', affiliation.institution);
293
- affiliation.email &&
294
- item.setAttribute('email', JSON.stringify(affiliation.email));
295
- affiliation.department &&
296
- item.setAttribute('department', affiliation.department);
297
- affiliation.addressLine1 &&
298
- item.setAttribute('addressLine1', affiliation.addressLine1);
299
- affiliation.addressLine2 &&
300
- item.setAttribute('addressLine2', affiliation.addressLine2);
301
- affiliation.addressLine3 &&
302
- item.setAttribute('addressLine3', affiliation.addressLine3);
303
- affiliation.postCode &&
304
- item.setAttribute('postCode', affiliation.postCode);
305
- affiliation.country && item.setAttribute('country', affiliation.country);
306
- (affiliation.priority === 0 || affiliation.priority) &&
307
- item.setAttribute('priority', affiliation.priority.toString());
308
- section.appendChild(item);
309
- });
310
- body.prepend(section);
311
- }
250
+ const tbody = table.querySelector('tbody');
251
+ if (tbody) {
252
+ const headerRow = table.querySelector('thead > tr');
253
+ if (!headerRow) {
254
+ const tr = createElement('tr');
255
+ tbody.insertBefore(tr, tbody.firstElementChild);
256
+ }
257
+ const footerRow = table.querySelector('tfoot > tr');
258
+ if (!footerRow) {
259
+ const tr = createElement('tr');
260
+ tbody.appendChild(tr);
261
+ }
262
+ }
263
+ });
312
264
  },
313
- moveAuthorsToBody(doc, authors, body, createElement) {
314
- if (authors === null || authors === void 0 ? void 0 : authors.length) {
315
- const section = createElement('sec');
316
- section.setAttribute('sec-type', 'contributors');
317
- authors.forEach((author) => {
318
- const item = doc.createElement('contrib');
319
- item.setAttribute('id', author._id);
320
- author.role && item.setAttribute('role', author.role);
321
- author.affiliations &&
322
- item.setAttribute('affiliations', JSON.stringify(author.affiliations));
323
- author.footnote &&
324
- item.setAttribute('footnote', JSON.stringify(author.footnote));
325
- author.corresp &&
326
- item.setAttribute('corresp', JSON.stringify(author.corresp));
327
- author.bibliographicName &&
328
- item.setAttribute('bibliographicName', JSON.stringify(author.bibliographicName));
329
- author.userID && item.setAttribute('userID', author.userID);
330
- author.invitationID &&
331
- item.setAttribute('invitationID', author.invitationID);
332
- author.isCorresponding &&
333
- item.setAttribute('isCorresponding', JSON.stringify(author.isCorresponding));
334
- author.ORCIDIdentifier &&
335
- item.setAttribute('ORCIDIdentifier', author.ORCIDIdentifier);
336
- (author.priority === 0 || author.priority) &&
337
- item.setAttribute('priority', author.priority.toString());
338
- section.appendChild(item);
339
- });
340
- body.prepend(section);
265
+ moveTableFooterToEnd(body) {
266
+ const footers = body.querySelectorAll('table-wrap-foot');
267
+ for (const footer of footers) {
268
+ if (footer.parentNode) {
269
+ footer.parentNode.appendChild(footer);
270
+ }
341
271
  }
342
272
  },
343
273
  moveFloatsGroupToBody(doc, body, createElement) {
344
- const floatsGroup = doc.querySelector('floats-group');
345
- if (floatsGroup) {
346
- const floatsGroupSection = this.createFloatsGroupSection(floatsGroup, createElement);
347
- removeNodeFromParent(floatsGroup);
348
- body.appendChild(floatsGroupSection);
274
+ const group = doc.querySelector('floats-group');
275
+ if (group) {
276
+ const sec = this.createFloatsGroupSection(group, createElement);
277
+ removeNodeFromParent(group);
278
+ body.appendChild(sec);
349
279
  }
350
280
  },
351
- moveBlockNodesFromParagraph(doc, body, createElement) {
352
- const blockNodes = ['disp-formula'];
353
- const paragraphs = [...body.querySelectorAll('sec > p')].filter((node) => blockNodes.find((node_name) => node.querySelector(`:scope > ${node_name}`)));
354
- paragraphs.map((paragraph) => {
355
- let newParagraph = createElement('p');
356
- const parent = doc.createDocumentFragment();
357
- while (paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild) {
358
- if (blockNodes.includes(paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild.nodeName)) {
359
- if (newParagraph.innerHTML.trim().length > 0) {
360
- parent.append(newParagraph);
361
- newParagraph = createElement('p');
362
- }
363
- parent.append(paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild);
364
- }
365
- else {
366
- newParagraph.append(paragraph === null || paragraph === void 0 ? void 0 : paragraph.firstChild);
367
- }
368
- }
369
- paragraph === null || paragraph === void 0 ? void 0 : paragraph.replaceWith(parent);
370
- });
371
- },
372
- moveKeywordsToBody(document, body, createElement) {
281
+ createKeywords(document, body, createElement) {
373
282
  const keywordGroups = [...document.querySelectorAll('kwd-group')];
374
283
  if (keywordGroups.length > 0) {
375
284
  const section = createElement('sec');
@@ -377,9 +286,9 @@ export const jatsBodyTransformations = {
377
286
  const title = createElement('title');
378
287
  title.textContent = 'Keywords';
379
288
  section.append(title);
380
- const kwdGroupsEl = createElement('kwd-group-list');
381
- kwdGroupsEl.append(keywordGroups[0]);
382
- section.append(kwdGroupsEl);
289
+ const keywordsElement = createElement('kwd-group-list');
290
+ keywordsElement.append(keywordGroups[0]);
291
+ section.append(keywordsElement);
383
292
  body.prepend(section);
384
293
  }
385
294
  },