@manuscripts/transform 2.1.3 → 2.1.5-LEAN-3376-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 (68) hide show
  1. package/dist/cjs/index.js +0 -1
  2. package/dist/cjs/jats/importer/jats-body-dom-parser.js +29 -88
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +10 -17
  4. package/dist/cjs/jats/importer/jats-front-parser.js +39 -1
  5. package/dist/cjs/jats/importer/jats-parser-utils.js +6 -0
  6. package/dist/cjs/jats/importer/parse-jats-article.js +3 -6
  7. package/dist/cjs/jats/jats-exporter.js +116 -86
  8. package/dist/cjs/schema/index.js +5 -6
  9. package/dist/cjs/{mathjax/mathjax-packages.js → schema/nodes/author_notes.js} +10 -3
  10. package/dist/cjs/schema/nodes/contributors.js +1 -1
  11. package/dist/cjs/schema/nodes/equation.js +12 -14
  12. package/dist/cjs/schema/nodes/equation_element.js +4 -5
  13. package/dist/cjs/schema/nodes/inline_equation.js +13 -15
  14. package/dist/cjs/schema/nodes/table.js +52 -30
  15. package/dist/cjs/schema/nodes/table_element.js +1 -1
  16. package/dist/cjs/transformer/builders.js +11 -14
  17. package/dist/cjs/transformer/decode.js +43 -25
  18. package/dist/cjs/transformer/encode.js +10 -26
  19. package/dist/cjs/transformer/node-types.js +2 -1
  20. package/dist/cjs/transformer/object-types.js +0 -1
  21. package/dist/es/index.js +0 -1
  22. package/dist/es/jats/importer/jats-body-dom-parser.js +30 -89
  23. package/dist/es/jats/importer/jats-body-transformations.js +10 -17
  24. package/dist/es/jats/importer/jats-front-parser.js +40 -2
  25. package/dist/es/jats/importer/jats-parser-utils.js +6 -0
  26. package/dist/es/jats/importer/parse-jats-article.js +3 -6
  27. package/dist/es/jats/jats-exporter.js +119 -89
  28. package/dist/es/schema/index.js +4 -5
  29. package/dist/{types/mathjax/mathjax-packages.d.ts → es/schema/nodes/author_notes.js} +9 -1
  30. package/dist/es/schema/nodes/contributors.js +1 -1
  31. package/dist/es/schema/nodes/equation.js +12 -14
  32. package/dist/es/schema/nodes/equation_element.js +4 -5
  33. package/dist/es/schema/nodes/inline_equation.js +13 -15
  34. package/dist/es/schema/nodes/table.js +51 -29
  35. package/dist/es/schema/nodes/table_element.js +1 -1
  36. package/dist/es/transformer/builders.js +9 -12
  37. package/dist/es/transformer/decode.js +43 -25
  38. package/dist/es/transformer/encode.js +10 -26
  39. package/dist/es/transformer/node-types.js +2 -1
  40. package/dist/es/transformer/object-types.js +0 -1
  41. package/dist/types/index.d.ts +0 -1
  42. package/dist/types/jats/importer/jats-front-parser.d.ts +10 -1
  43. package/dist/types/jats/jats-exporter.d.ts +5 -0
  44. package/dist/types/schema/index.d.ts +0 -2
  45. package/dist/{es/mathjax/mathjax-packages.js → types/schema/nodes/author_notes.d.ts} +10 -2
  46. package/dist/types/schema/nodes/equation.d.ts +3 -4
  47. package/dist/types/schema/nodes/equation_element.d.ts +1 -2
  48. package/dist/types/schema/nodes/inline_equation.d.ts +4 -3
  49. package/dist/types/schema/nodes/table.d.ts +5 -12
  50. package/dist/types/schema/types.d.ts +1 -1
  51. package/dist/types/transformer/builders.d.ts +3 -3
  52. package/dist/types/transformer/decode.d.ts +1 -0
  53. package/package.json +5 -5
  54. package/dist/cjs/mathjax/index.js +0 -41
  55. package/dist/cjs/mathjax/mathml-to-svg.js +0 -70
  56. package/dist/cjs/mathjax/tex-to-mathml.js +0 -49
  57. package/dist/cjs/mathjax/tex-to-svg.js +0 -59
  58. package/dist/cjs/schema/nodes/table_row.js +0 -123
  59. package/dist/es/mathjax/index.js +0 -12
  60. package/dist/es/mathjax/mathml-to-svg.js +0 -66
  61. package/dist/es/mathjax/tex-to-mathml.js +0 -45
  62. package/dist/es/mathjax/tex-to-svg.js +0 -55
  63. package/dist/es/schema/nodes/table_row.js +0 -120
  64. package/dist/types/mathjax/index.d.ts +0 -3
  65. package/dist/types/mathjax/mathml-to-svg.d.ts +0 -17
  66. package/dist/types/mathjax/tex-to-mathml.d.ts +0 -17
  67. package/dist/types/mathjax/tex-to-svg.d.ts +0 -17
  68. package/dist/types/schema/nodes/table_row.d.ts +0 -41
package/dist/cjs/index.js CHANGED
@@ -18,7 +18,6 @@ exports.isSectionLabelNode = void 0;
18
18
  __exportStar(require("./lib/section-group-type"), exports);
19
19
  __exportStar(require("./lib/table-cell-styles"), exports);
20
20
  __exportStar(require("./lib/utils"), exports);
21
- __exportStar(require("./mathjax"), exports);
22
21
  __exportStar(require("./schema"), exports);
23
22
  __exportStar(require("./transformer"), exports);
24
23
  __exportStar(require("./jats"), exports);
@@ -21,8 +21,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.jatsBodyDOMParser = void 0;
22
22
  const mime_1 = __importDefault(require("mime"));
23
23
  const prosemirror_model_1 = require("prosemirror-model");
24
- const mathml_to_svg_1 = require("../../mathjax/mathml-to-svg");
25
- const tex_to_svg_1 = require("../../mathjax/tex-to-svg");
26
24
  const schema_1 = require("../../schema");
27
25
  const transformer_1 = require("../../transformer");
28
26
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
@@ -39,6 +37,28 @@ const chooseContentType = (graphicNode) => {
39
37
  }
40
38
  }
41
39
  };
40
+ const getEquationContent = (p) => {
41
+ var _a;
42
+ const element = p;
43
+ const id = element.getAttribute('id');
44
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
45
+ let contents = '';
46
+ let format = '';
47
+ for (const child of container.childNodes) {
48
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
49
+ switch (nodeName) {
50
+ case 'tex-math':
51
+ contents = child.innerHTML;
52
+ format = 'tex';
53
+ break;
54
+ case 'mml:math':
55
+ contents = child.outerHTML;
56
+ format = 'mathml';
57
+ break;
58
+ }
59
+ }
60
+ return { id, format, contents };
61
+ };
42
62
  const marks = [
43
63
  {
44
64
  tag: 'bold',
@@ -147,91 +167,26 @@ const nodes = [
147
167
  tag: 'inline-formula',
148
168
  node: 'inline_equation',
149
169
  getAttrs: (node) => {
150
- var _a, _b, _c, _d, _e;
151
170
  const element = node;
152
- const attrs = {
153
- id: element.getAttribute('id'),
154
- MathMLRepresentation: '',
155
- SVGRepresentation: '',
156
- TeXRepresentation: '',
157
- };
158
- const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
159
- for (const child of container.childNodes) {
160
- const nodeName = child.nodeName.replace(/^[a-z]:/, '');
161
- switch (nodeName) {
162
- case 'tex-math':
163
- attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
164
- if (attrs.TeXRepresentation) {
165
- attrs.SVGRepresentation =
166
- (_d = (0, tex_to_svg_1.convertTeXToSVG)(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
167
- }
168
- break;
169
- case 'mml:math':
170
- ;
171
- child.removeAttribute('id');
172
- attrs.MathMLRepresentation = transformer_1.xmlSerializer.serializeToString(child);
173
- if (attrs.MathMLRepresentation) {
174
- attrs.SVGRepresentation =
175
- (_e = (0, mathml_to_svg_1.convertMathMLToSVG)(attrs.MathMLRepresentation, true)) !== null && _e !== void 0 ? _e : '';
176
- }
177
- break;
178
- }
179
- }
180
- return attrs;
171
+ return getEquationContent(element);
181
172
  },
182
173
  },
183
174
  {
184
175
  tag: 'disp-formula',
185
176
  node: 'equation_element',
186
177
  getAttrs: (node) => {
178
+ var _a, _b;
187
179
  const element = node;
188
- const caption = element.querySelector('figcaption');
189
180
  return {
190
181
  id: element.getAttribute('id'),
191
- suppressCaption: !caption,
182
+ label: (_b = (_a = element.querySelector('label')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '',
192
183
  };
193
184
  },
194
185
  getContent: (node, schema) => {
195
- var _a, _b, _c, _d, _e;
196
186
  const element = node;
197
- const attrs = {
198
- MathMLStringRepresentation: '',
199
- SVGStringRepresentation: '',
200
- TeXRepresentation: '',
201
- };
202
- const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
203
- for (const child of container.childNodes) {
204
- const nodeName = child.nodeName.replace(/^[a-z]:/, '');
205
- switch (nodeName) {
206
- case 'tex-math':
207
- attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
208
- if (attrs.TeXRepresentation) {
209
- attrs.SVGStringRepresentation =
210
- (_d = (0, tex_to_svg_1.convertTeXToSVG)(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
211
- }
212
- break;
213
- case 'mml:math':
214
- ;
215
- child.removeAttribute('id');
216
- attrs.MathMLStringRepresentation =
217
- transformer_1.xmlSerializer.serializeToString(child);
218
- if (attrs.MathMLStringRepresentation) {
219
- attrs.SVGStringRepresentation =
220
- (_e = (0, mathml_to_svg_1.convertMathMLToSVG)(attrs.MathMLStringRepresentation, true)) !== null && _e !== void 0 ? _e : '';
221
- }
222
- break;
223
- }
224
- }
225
- const caption = element.querySelector('figcaption');
226
- const figcaption = schema.nodes.figcaption.create();
187
+ const attrs = getEquationContent(element);
227
188
  return prosemirror_model_1.Fragment.from([
228
- schema.nodes.equation.createChecked(attrs),
229
- caption
230
- ?
231
- exports.jatsBodyDOMParser.parse(caption, {
232
- topNode: figcaption,
233
- })
234
- : figcaption,
189
+ schema.nodes.equation.createChecked(Object.assign({}, attrs)),
235
190
  ]);
236
191
  },
237
192
  },
@@ -525,23 +480,9 @@ const nodes = [
525
480
  const element = node;
526
481
  return {
527
482
  id: element.getAttribute('id'),
528
- suppressFooter: !element.querySelector('table > tfoot > tr'),
529
- suppressHeader: !element.querySelector('table > thead > tr'),
530
483
  };
531
484
  },
532
485
  },
533
- {
534
- tag: 'tbody',
535
- skip: true,
536
- },
537
- {
538
- tag: 'tfoot',
539
- skip: true,
540
- },
541
- {
542
- tag: 'thead',
543
- skip: true,
544
- },
545
486
  {
546
487
  tag: 'title',
547
488
  node: 'section_title',
@@ -568,12 +509,12 @@ const nodes = [
568
509
  },
569
510
  {
570
511
  tag: 'th',
571
- node: 'table_cell',
512
+ node: 'table_header',
572
513
  getAttrs: (node) => {
573
514
  const element = node;
574
515
  const colspan = element.getAttribute('colspan');
575
516
  const rowspan = element.getAttribute('rowspan');
576
- return Object.assign(Object.assign(Object.assign({ celltype: 'th' }, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
517
+ return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
577
518
  },
578
519
  },
579
520
  {
@@ -202,7 +202,9 @@ exports.jatsBodyTransformations = {
202
202
  }
203
203
  },
204
204
  moveFootnotes(doc, group, createElement) {
205
- const footnotes = [...doc.querySelectorAll('fn:not(table-wrap-foot fn)')];
205
+ const footnotes = [
206
+ ...doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'),
207
+ ];
206
208
  const footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
207
209
  const footnotesSectionGroup = footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group');
208
210
  const containingGroup = footnotesSectionGroup || createElement('fn-group');
@@ -239,8 +241,12 @@ exports.jatsBodyTransformations = {
239
241
  }
240
242
  },
241
243
  fixTables(body, createElement) {
242
- const tables = body.querySelectorAll('table-wrap > table');
243
- tables.forEach((table) => {
244
+ const tableWraps = body.querySelectorAll('table-wrap');
245
+ tableWraps.forEach((tableWrap) => {
246
+ const table = tableWrap.querySelector('table');
247
+ if (!table) {
248
+ return;
249
+ }
244
250
  const colgroup = table.querySelector('colgroup');
245
251
  const cols = table.querySelectorAll('col');
246
252
  if (!colgroup && table.firstChild && cols.length > 0) {
@@ -248,20 +254,7 @@ exports.jatsBodyTransformations = {
248
254
  for (const col of cols) {
249
255
  colgroup.appendChild(col);
250
256
  }
251
- table.insertBefore(colgroup, table.firstChild);
252
- }
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
- }
257
+ tableWrap.insertBefore(colgroup, table.nextSibling);
265
258
  }
266
259
  });
267
260
  },
@@ -179,7 +179,45 @@ exports.jatsFrontParser = {
179
179
  affiliationIDs,
180
180
  };
181
181
  },
182
- parseAuthorNotes(elements) {
182
+ parseAuthorNotes(element) {
183
+ if (!element) {
184
+ return {
185
+ footnotes: [],
186
+ footnoteIDs: new Map(),
187
+ authorNotes: [],
188
+ authorNotesParagraphs: [],
189
+ correspondingIDs: new Map(),
190
+ correspondingList: [],
191
+ };
192
+ }
193
+ const { footnotes, footnoteIDs } = this.parseFootnotes([
194
+ ...element.querySelectorAll('fn:not([fn-type])'),
195
+ ]);
196
+ const authorNotesParagraphs = this.parseParagraphs([
197
+ ...element.querySelectorAll(':scope > p'),
198
+ ]);
199
+ const { correspondingList, correspondingIDs } = this.parseCorresp([
200
+ ...element.querySelectorAll('corresp'),
201
+ ]);
202
+ const authorNotes = [
203
+ (0, transformer_1.buildAuthorNotes)([
204
+ ...footnoteIDs.values(),
205
+ ...authorNotesParagraphs.map((p) => p._id),
206
+ ]),
207
+ ];
208
+ return {
209
+ footnotes,
210
+ footnoteIDs,
211
+ authorNotesParagraphs,
212
+ authorNotes,
213
+ correspondingIDs,
214
+ correspondingList,
215
+ };
216
+ },
217
+ parseParagraphs(elements) {
218
+ return elements.map((p) => (0, transformer_1.buildParagraph)(p.innerHTML));
219
+ },
220
+ parseFootnotes(elements) {
183
221
  const footnoteIDs = new Map();
184
222
  const footnotes = elements.map((element) => {
185
223
  const fn = (0, transformer_1.buildFootnote)('', element.innerHTML);
@@ -16,6 +16,8 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.htmlFromJatsNode = exports.updateDocumentIDs = void 0;
19
+ const uuid_1 = require("uuid");
20
+ const schema_1 = require("../../schema");
19
21
  const transformer_1 = require("../../transformer");
20
22
  const updateDocumentIDs = (node, replacements) => {
21
23
  const warnings = [];
@@ -30,6 +32,10 @@ function recurseDoc(node, fn) {
30
32
  node.descendants((n) => fn(n));
31
33
  }
32
34
  const updateNodeID = (node, replacements, warnings) => {
35
+ if (node.type === schema_1.schema.nodes.inline_equation) {
36
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${(0, uuid_1.v4)()}` });
37
+ return;
38
+ }
33
39
  if (!('id' in node.attrs)) {
34
40
  return;
35
41
  }
@@ -35,12 +35,7 @@ const parseJATSFront = (doc, front) => {
35
35
  const { affiliations, affiliationIDs } = jats_front_parser_1.jatsFrontParser.parseAffiliations([
36
36
  ...front.querySelectorAll('article-meta > contrib-group > aff'),
37
37
  ]);
38
- const { footnotes, footnoteIDs } = jats_front_parser_1.jatsFrontParser.parseAuthorNotes([
39
- ...front.querySelectorAll('article-meta > author-notes > fn:not([fn-type])'),
40
- ]);
41
- const { correspondingList, correspondingIDs } = jats_front_parser_1.jatsFrontParser.parseCorresp([
42
- ...front.querySelectorAll('article-meta > author-notes > corresp'),
43
- ]);
38
+ const { footnotes, footnoteIDs, authorNotes, authorNotesParagraphs, correspondingIDs, correspondingList, } = jats_front_parser_1.jatsFrontParser.parseAuthorNotes(front.querySelector('article-meta > author-notes'));
44
39
  const authors = jats_front_parser_1.jatsFrontParser.parseContributors([
45
40
  ...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
46
41
  ], affiliationIDs, footnoteIDs, correspondingIDs);
@@ -51,6 +46,8 @@ const parseJATSFront = (doc, front) => {
51
46
  manuscript,
52
47
  titles,
53
48
  journal,
49
+ ...authorNotesParagraphs,
50
+ ...authorNotes,
54
51
  ...footnotes,
55
52
  ...authors,
56
53
  ...affiliations,
@@ -95,7 +95,7 @@ const createDefaultIdGenerator = () => {
95
95
  const counter = (0, exports.createCounter)();
96
96
  return async (element) => {
97
97
  const value = String(counter.increment(element.nodeName));
98
- return `${element.nodeName}-${value}`;
98
+ return `${element.localName}-${value}`;
99
99
  };
100
100
  };
101
101
  const chooseRefType = (objectType) => {
@@ -164,6 +164,7 @@ class JATSExporter {
164
164
  };
165
165
  this.nodeFromJATS = (JATSFragment) => {
166
166
  JATSFragment = JATSFragment.trim();
167
+ JATSFragment = JATSFragment.replace(' ', ' ');
167
168
  if (!JATSFragment.length) {
168
169
  return null;
169
170
  }
@@ -614,6 +615,7 @@ class JATSExporter {
614
615
  this.createSerializer = () => {
615
616
  const getModel = (id) => id ? this.modelMap.get(id) : undefined;
616
617
  const nodes = {
618
+ author_notes: () => ['author-notes', 0],
617
619
  title: () => '',
618
620
  affiliations: () => '',
619
621
  contributors: () => '',
@@ -686,22 +688,20 @@ class JATSExporter {
686
688
  },
687
689
  doc: () => '',
688
690
  equation: (node) => {
689
- const formula = this.document.createElement('disp-formula');
690
- formula.setAttribute('id', normalizeID(node.attrs.id));
691
- if (node.attrs.TeXRepresentation) {
692
- const math = this.document.createElement('tex-math');
693
- math.textContent = node.attrs.TeXRepresentation;
694
- formula.appendChild(math);
695
- }
696
- else if (node.attrs.MathMLStringRepresentation) {
697
- const math = this.nodeFromJATS(node.attrs.MathMLStringRepresentation);
698
- if (math) {
699
- formula.appendChild(math);
700
- }
701
- }
702
- return formula;
691
+ return this.createEquation(node);
692
+ },
693
+ inline_equation: (node) => {
694
+ const eqElement = this.document.createElement('inline-formula');
695
+ const equation = this.createEquation(node, true);
696
+ eqElement.append(equation);
697
+ return eqElement;
698
+ },
699
+ equation_element: (node) => {
700
+ const eqElement = this.document.createElement('disp-formula');
701
+ eqElement.setAttribute('id', normalizeID(node.attrs.id));
702
+ processChildNodes(eqElement, node, schema_1.schema.nodes.equation);
703
+ return eqElement;
703
704
  },
704
- equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
705
705
  figcaption: (node) => {
706
706
  if (!node.textContent) {
707
707
  return '';
@@ -751,28 +751,6 @@ class JATSExporter {
751
751
  },
752
752
  hard_break: () => '',
753
753
  highlight_marker: () => '',
754
- inline_equation: (node) => {
755
- const formula = this.document.createElement('inline-formula');
756
- formula.setAttribute('id', normalizeID(node.attrs.id));
757
- if (node.attrs.TeXRepresentation) {
758
- const math = this.document.createElement('tex-math');
759
- math.textContent = node.attrs.TeXRepresentation;
760
- formula.appendChild(math);
761
- }
762
- else if (node.attrs.MathMLRepresentation) {
763
- const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
764
- if (math) {
765
- formula.appendChild(math);
766
- }
767
- }
768
- else if (node.attrs.SVGRepresentation) {
769
- const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
770
- if (math) {
771
- formula.appendChild(math);
772
- }
773
- }
774
- return formula;
775
- },
776
754
  inline_footnote: (node) => {
777
755
  const xref = this.document.createElement('xref');
778
756
  xref.setAttribute('ref-type', 'fn');
@@ -873,9 +851,13 @@ class JATSExporter {
873
851
  element.setAttribute('position', 'anchor');
874
852
  return element;
875
853
  },
876
- table_body: () => ['tbody', 0],
877
854
  table_cell: (node) => [
878
- node.attrs.celltype,
855
+ 'td',
856
+ Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
857
+ 0,
858
+ ],
859
+ table_header: (node) => [
860
+ 'th',
879
861
  Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
880
862
  0,
881
863
  ],
@@ -956,6 +938,26 @@ class JATSExporter {
956
938
  element.appendChild(this.serializeNode(childNode));
957
939
  }
958
940
  };
941
+ const appendTable = (element, node) => {
942
+ const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
943
+ const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
944
+ if (!tableNode) {
945
+ return;
946
+ }
947
+ const table = this.serializeNode(tableNode);
948
+ const tbodyElement = this.document.createElement('tbody');
949
+ while (table.firstChild) {
950
+ const child = table.firstChild;
951
+ table.removeChild(child);
952
+ tbodyElement.appendChild(child);
953
+ }
954
+ table.appendChild(tbodyElement);
955
+ if (colGroupNode) {
956
+ const colGroup = this.serializeNode(colGroupNode);
957
+ table.insertBefore(colGroup, table.firstChild);
958
+ }
959
+ element.appendChild(table);
960
+ };
959
961
  const createFigureElement = (node, nodeName, contentNodeType, figType) => {
960
962
  const element = createElement(node, nodeName);
961
963
  if (figType) {
@@ -976,7 +978,7 @@ class JATSExporter {
976
978
  const element = createElement(node, nodeName);
977
979
  appendLabels(element, node);
978
980
  appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
979
- appendChildNodeOfType(element, node, node.type.schema.nodes.table);
981
+ appendTable(element, node);
980
982
  appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
981
983
  if ((0, node_types_1.isExecutableNodeType)(node.type)) {
982
984
  processExecutableNode(node, element);
@@ -1034,6 +1036,7 @@ class JATSExporter {
1034
1036
  }
1035
1037
  };
1036
1038
  this.buildContributors = (articleMeta) => {
1039
+ var _a;
1037
1040
  const contributors = this.models.filter(isContributor);
1038
1041
  const authorContributors = contributors
1039
1042
  .filter((contributor) => contributor.role === 'author')
@@ -1252,56 +1255,59 @@ class JATSExporter {
1252
1255
  }
1253
1256
  });
1254
1257
  }
1255
- const noteIDs = [];
1256
- for (const contributor of [...authorContributors, ...otherContributors]) {
1257
- if (contributor.footnote) {
1258
- const ids = contributor.footnote.map((note) => {
1259
- return note.noteID;
1260
- });
1261
- noteIDs.push(...ids);
1262
- }
1263
- if (contributor.corresp) {
1264
- const ids = contributor.corresp.map((corresp) => {
1265
- return corresp.correspID;
1266
- });
1267
- noteIDs.push(...ids);
1268
- }
1269
- }
1270
- const footnotes = [];
1271
- footnotes.push(...this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Footnote)));
1272
- const correspodings = [];
1273
- correspodings.push(...this.models.filter((0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Corresponding)));
1274
- if (footnotes || correspodings) {
1275
- const authorNotesEl = this.document.createElement('author-notes');
1276
- const usedFootnotes = footnotes.filter((footnote) => {
1277
- return noteIDs.includes(footnote._id);
1278
- });
1279
- const usedCorrespodings = correspodings.filter((corresp) => {
1280
- return noteIDs.includes(corresp._id);
1281
- });
1282
- usedFootnotes.forEach((footnote) => {
1283
- const authorFootNote = this.document.createElement('fn');
1284
- authorFootNote.setAttribute('id', normalizeID(footnote._id));
1285
- authorFootNote.innerHTML = footnote.contents;
1286
- authorNotesEl.appendChild(authorFootNote);
1287
- });
1288
- usedCorrespodings.forEach((corresponding) => {
1289
- const correspondingEl = this.document.createElement('corresp');
1290
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1291
- if (corresponding.label) {
1292
- const labelEl = this.document.createElement('label');
1293
- labelEl.textContent = corresponding.label;
1294
- correspondingEl.appendChild(labelEl);
1258
+ const authorNotesEl = this.document.createElement('author-notes');
1259
+ const usedCorrespodings = this.getUsedCorrespondings([
1260
+ ...authorContributors,
1261
+ ...otherContributors,
1262
+ ]);
1263
+ usedCorrespodings.forEach((corresp) => {
1264
+ this.appendCorrespondingToElement(corresp, authorNotesEl);
1265
+ });
1266
+ const authorNotes = (_a = (0, json_schema_1.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1267
+ if (authorNotes) {
1268
+ authorNotes.containedObjectIDs.forEach((id) => {
1269
+ const model = this.modelMap.get(id);
1270
+ if (!model) {
1271
+ return;
1272
+ }
1273
+ if (id.startsWith('MPParagraphElement')) {
1274
+ this.appendParagraphToElement(model, authorNotesEl);
1275
+ }
1276
+ else if (id.startsWith('MPFootnote')) {
1277
+ this.appendFootnoteToElement(model, authorNotesEl);
1295
1278
  }
1296
- correspondingEl.append(corresponding.contents);
1297
- authorNotesEl.appendChild(correspondingEl);
1298
1279
  });
1299
- if (authorNotesEl.childNodes.length > 0) {
1300
- articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1301
- }
1302
1280
  }
1281
+ if (authorNotesEl.childNodes.length > 0) {
1282
+ articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1283
+ }
1284
+ }
1285
+ };
1286
+ this.appendCorrespondingToElement = (corresponding, element) => {
1287
+ const correspondingEl = this.document.createElement('corresp');
1288
+ correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1289
+ if (corresponding.label) {
1290
+ const labelEl = this.document.createElement('label');
1291
+ labelEl.textContent = corresponding.label;
1292
+ correspondingEl.appendChild(labelEl);
1293
+ }
1294
+ correspondingEl.append(corresponding.contents);
1295
+ element.appendChild(correspondingEl);
1296
+ };
1297
+ this.appendParagraphToElement = (paragraph, element) => {
1298
+ const parser = new DOMParser();
1299
+ const xmlDoc = parser.parseFromString(paragraph.contents, 'text/xml');
1300
+ const paragraphEl = xmlDoc.firstChild;
1301
+ if (paragraphEl && paragraphEl.nodeName === 'p') {
1302
+ element.appendChild(paragraphEl);
1303
1303
  }
1304
1304
  };
1305
+ this.appendFootnoteToElement = (footnote, element) => {
1306
+ const footnoteEl = this.document.createElement('fn');
1307
+ footnoteEl.setAttribute('id', normalizeID(footnote._id));
1308
+ footnoteEl.innerHTML = footnote.contents;
1309
+ element.appendChild(footnoteEl);
1310
+ };
1305
1311
  this.fixBody = (body, fragment) => {
1306
1312
  fragment.descendants((node) => {
1307
1313
  if (node.attrs.id) {
@@ -1589,6 +1595,27 @@ class JATSExporter {
1589
1595
  this.citationTexts.set(id, output);
1590
1596
  });
1591
1597
  }
1598
+ createEquation(node, isInline = false) {
1599
+ if (node.attrs.format === 'tex') {
1600
+ const texMath = this.document.createElement('tex-math');
1601
+ texMath.innerHTML = node.attrs.contents;
1602
+ return texMath;
1603
+ }
1604
+ else {
1605
+ const math = this.nodeFromJATS(node.attrs.contents);
1606
+ const mathml = math;
1607
+ if (!isInline) {
1608
+ mathml.setAttribute('id', normalizeID(node.attrs.id));
1609
+ }
1610
+ return mathml;
1611
+ }
1612
+ }
1613
+ getUsedCorrespondings(contributors) {
1614
+ return contributors
1615
+ .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1616
+ .map((corresp) => this.modelMap.get(corresp.correspID))
1617
+ .filter((corresp) => !!corresp);
1618
+ }
1592
1619
  buildKeywords(articleMeta) {
1593
1620
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Keyword);
1594
1621
  const keywordGroups = new Map();
@@ -1660,6 +1687,9 @@ class JATSExporter {
1660
1687
  }
1661
1688
  }
1662
1689
  }
1690
+ if (!fnGroup.hasChildNodes()) {
1691
+ fnGroup.remove();
1692
+ }
1663
1693
  }
1664
1694
  }
1665
1695
  });
@@ -36,6 +36,7 @@ const abstracts_1 = require("./nodes/abstracts");
36
36
  const affiliation_1 = require("./nodes/affiliation");
37
37
  const affiliations_1 = require("./nodes/affiliations");
38
38
  const attribution_1 = require("./nodes/attribution");
39
+ const author_notes_1 = require("./nodes/author_notes");
39
40
  const backmatter_1 = require("./nodes/backmatter");
40
41
  const bibliography_element_1 = require("./nodes/bibliography_element");
41
42
  const bibliography_item_1 = require("./nodes/bibliography_item");
@@ -87,7 +88,6 @@ const table_1 = require("./nodes/table");
87
88
  const table_col_1 = require("./nodes/table_col");
88
89
  const table_element_1 = require("./nodes/table_element");
89
90
  const table_element_footer_1 = require("./nodes/table_element_footer");
90
- const table_row_1 = require("./nodes/table_row");
91
91
  const text_1 = require("./nodes/text");
92
92
  const title_1 = require("./nodes/title");
93
93
  const toc_element_1 = require("./nodes/toc_element");
@@ -117,7 +117,6 @@ __exportStar(require("./nodes/footnotes_section"), exports);
117
117
  __exportStar(require("./nodes/graphical_abstract_section"), exports);
118
118
  __exportStar(require("./nodes/hard_break"), exports);
119
119
  __exportStar(require("./nodes/highlight_marker"), exports);
120
- __exportStar(require("./nodes/inline_equation"), exports);
121
120
  __exportStar(require("./nodes/inline_footnote"), exports);
122
121
  __exportStar(require("./nodes/keyword"), exports);
123
122
  __exportStar(require("./nodes/keywords_element"), exports);
@@ -137,7 +136,6 @@ __exportStar(require("./nodes/section_title"), exports);
137
136
  __exportStar(require("./nodes/table"), exports);
138
137
  __exportStar(require("./nodes/table_col"), exports);
139
138
  __exportStar(require("./nodes/table_element"), exports);
140
- __exportStar(require("./nodes/table_row"), exports);
141
139
  __exportStar(require("./nodes/text"), exports);
142
140
  __exportStar(require("./nodes/toc_element"), exports);
143
141
  __exportStar(require("./nodes/toc_section"), exports);
@@ -213,12 +211,12 @@ exports.schema = new prosemirror_model_1.Schema({
213
211
  section_title: section_title_1.sectionTitle,
214
212
  section_title_plain: section_title_1.sectionTitle,
215
213
  table: table_1.table,
216
- table_body: table_1.tableBody,
217
- table_cell: table_row_1.tableCell,
214
+ table_cell: table_1.tableCell,
218
215
  table_element: table_element_1.tableElement,
219
- table_row: table_row_1.tableRow,
216
+ table_row: table_1.tableRow,
220
217
  table_col: table_col_1.tableCol,
221
218
  table_colgroup: table_col_1.tableColGroup,
219
+ table_header: table_1.tableHeader,
222
220
  text: text_1.text,
223
221
  toc_element: toc_element_1.tocElement,
224
222
  toc_section: toc_section_1.tocSection,
@@ -230,5 +228,6 @@ exports.schema = new prosemirror_model_1.Schema({
230
228
  contributors: contributors_1.contributors,
231
229
  supplements: supplements_1.supplements,
232
230
  supplement: supplement_1.supplement,
231
+ author_notes: author_notes_1.authorNotes,
233
232
  },
234
233
  });