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