@manuscripts/transform 2.1.3 → 2.1.5

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 (61) 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 +7 -16
  4. package/dist/cjs/jats/importer/jats-parser-utils.js +6 -0
  5. package/dist/cjs/jats/jats-exporter.js +57 -41
  6. package/dist/cjs/schema/index.js +3 -6
  7. package/dist/cjs/schema/nodes/equation.js +12 -14
  8. package/dist/cjs/schema/nodes/equation_element.js +4 -5
  9. package/dist/cjs/schema/nodes/inline_equation.js +13 -15
  10. package/dist/cjs/schema/nodes/table.js +52 -30
  11. package/dist/cjs/schema/nodes/table_element.js +1 -1
  12. package/dist/cjs/transformer/builders.js +1 -8
  13. package/dist/cjs/transformer/decode.js +30 -24
  14. package/dist/cjs/transformer/encode.js +7 -26
  15. package/dist/cjs/transformer/node-types.js +0 -1
  16. package/dist/cjs/transformer/object-types.js +0 -1
  17. package/dist/es/index.js +0 -1
  18. package/dist/es/jats/importer/jats-body-dom-parser.js +30 -89
  19. package/dist/es/jats/importer/jats-body-transformations.js +7 -16
  20. package/dist/es/jats/importer/jats-parser-utils.js +6 -0
  21. package/dist/es/jats/jats-exporter.js +57 -41
  22. package/dist/es/schema/index.js +2 -5
  23. package/dist/es/schema/nodes/equation.js +12 -14
  24. package/dist/es/schema/nodes/equation_element.js +4 -5
  25. package/dist/es/schema/nodes/inline_equation.js +13 -15
  26. package/dist/es/schema/nodes/table.js +51 -29
  27. package/dist/es/schema/nodes/table_element.js +1 -1
  28. package/dist/es/transformer/builders.js +0 -6
  29. package/dist/es/transformer/decode.js +30 -24
  30. package/dist/es/transformer/encode.js +7 -26
  31. package/dist/es/transformer/node-types.js +0 -1
  32. package/dist/es/transformer/object-types.js +0 -1
  33. package/dist/types/index.d.ts +0 -1
  34. package/dist/types/jats/jats-exporter.d.ts +1 -0
  35. package/dist/types/schema/index.d.ts +0 -2
  36. package/dist/types/schema/nodes/equation.d.ts +3 -4
  37. package/dist/types/schema/nodes/equation_element.d.ts +1 -2
  38. package/dist/types/schema/nodes/inline_equation.d.ts +4 -3
  39. package/dist/types/schema/nodes/table.d.ts +5 -12
  40. package/dist/types/schema/types.d.ts +1 -1
  41. package/dist/types/transformer/builders.d.ts +1 -2
  42. package/dist/types/transformer/decode.d.ts +1 -0
  43. package/package.json +5 -5
  44. package/dist/cjs/mathjax/index.js +0 -41
  45. package/dist/cjs/mathjax/mathjax-packages.js +0 -20
  46. package/dist/cjs/mathjax/mathml-to-svg.js +0 -70
  47. package/dist/cjs/mathjax/tex-to-mathml.js +0 -49
  48. package/dist/cjs/mathjax/tex-to-svg.js +0 -59
  49. package/dist/cjs/schema/nodes/table_row.js +0 -123
  50. package/dist/es/mathjax/index.js +0 -12
  51. package/dist/es/mathjax/mathjax-packages.js +0 -17
  52. package/dist/es/mathjax/mathml-to-svg.js +0 -66
  53. package/dist/es/mathjax/tex-to-mathml.js +0 -45
  54. package/dist/es/mathjax/tex-to-svg.js +0 -55
  55. package/dist/es/schema/nodes/table_row.js +0 -120
  56. package/dist/types/mathjax/index.d.ts +0 -3
  57. package/dist/types/mathjax/mathjax-packages.d.ts +0 -16
  58. package/dist/types/mathjax/mathml-to-svg.d.ts +0 -17
  59. package/dist/types/mathjax/tex-to-mathml.d.ts +0 -17
  60. package/dist/types/mathjax/tex-to-svg.d.ts +0 -17
  61. package/dist/types/schema/nodes/table_row.d.ts +0 -41
@@ -15,20 +15,57 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.tableBody = exports.table = void 0;
18
+ exports.tableHeader = exports.tableCell = exports.tableRow = exports.table = void 0;
19
+ const prosemirror_tables_1 = require("prosemirror-tables");
20
+ function createCellAttribute(attributeName, defaultValue = null, customGetFromDOM, customSetDOMAttr) {
21
+ return {
22
+ default: defaultValue,
23
+ getFromDOM(dom) {
24
+ if (customGetFromDOM) {
25
+ return customGetFromDOM(dom);
26
+ }
27
+ return dom.getAttribute(attributeName);
28
+ },
29
+ setDOMAttr(value, attrs) {
30
+ if (customSetDOMAttr) {
31
+ customSetDOMAttr(value, attrs);
32
+ }
33
+ else if (value) {
34
+ attrs[attributeName] = value;
35
+ }
36
+ },
37
+ };
38
+ }
39
+ const tableOptions = {
40
+ cellContent: 'inline*',
41
+ cellAttributes: {
42
+ placeholder: createCellAttribute('data-placeholder-text', 'Data', (dom) => dom.getAttribute('data-placeholder-text') || ''),
43
+ valign: createCellAttribute('valign'),
44
+ align: createCellAttribute('align'),
45
+ scope: createCellAttribute('scope'),
46
+ style: createCellAttribute('style'),
47
+ colspan: createCellAttribute('colspan', 1, (dom) => Number(dom.getAttribute('colspan') || 1), (value, attrs) => {
48
+ if (value && value !== 1) {
49
+ attrs['colspan'] = String(value);
50
+ }
51
+ }),
52
+ rowspan: createCellAttribute('rowspan', 1, (dom) => Number(dom.getAttribute('rowspan') || 1), (value, attrs) => {
53
+ if (value && value !== 1) {
54
+ attrs['rowspan'] = String(value);
55
+ }
56
+ }),
57
+ },
58
+ };
59
+ const tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
19
60
  exports.table = {
20
- content: 'table_colgroup? table_body',
21
- tableRole: 'table',
22
- isolating: true,
23
- group: 'block',
24
- selectable: false,
25
61
  attrs: {
26
62
  id: { default: '' },
27
- headerRows: { default: 1 },
28
- footerRows: { default: 1 },
29
63
  dataTracked: { default: null },
30
- comments: { default: null },
31
64
  },
65
+ content: 'table_row+',
66
+ tableRole: 'table',
67
+ isolating: true,
68
+ group: 'block',
32
69
  parseDOM: [
33
70
  {
34
71
  tag: 'table',
@@ -36,35 +73,20 @@ exports.table = {
36
73
  const dom = p;
37
74
  return {
38
75
  id: dom.getAttribute('id'),
39
- headerRows: dom.dataset && dom.dataset['header-rows'],
40
- footerRows: dom.dataset && dom.dataset['footer-rows'],
41
76
  };
42
77
  },
43
78
  },
44
79
  ],
45
- toDOM: (node) => {
46
- const tableNode = node;
80
+ toDOM(node) {
47
81
  return [
48
82
  'table',
49
83
  {
50
- id: tableNode.attrs.id,
51
- 'data-header-rows': String(node.attrs.headerRows),
52
- 'data-footer-rows': String(node.attrs.footerRows),
84
+ id: node.attrs.id,
53
85
  },
54
- 0,
86
+ ['tbody', 0],
55
87
  ];
56
88
  },
57
89
  };
58
- exports.tableBody = {
59
- content: 'table_row+',
60
- group: 'block',
61
- tableRole: 'table',
62
- parseDOM: [
63
- {
64
- tag: 'tbody',
65
- },
66
- ],
67
- toDOM() {
68
- return ['tbody', 0];
69
- },
70
- };
90
+ exports.tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
91
+ exports.tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
92
+ exports.tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
@@ -17,7 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.tableElement = void 0;
19
19
  exports.tableElement = {
20
- content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
20
+ content: '(table | placeholder) table_colgroup? table_element_footer? figcaption? (listing | placeholder)',
21
21
  attrs: {
22
22
  id: { default: '' },
23
23
  paragraphStyle: { default: '' },
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.buildTitles = exports.buildElementsOrder = exports.auxiliaryObjectTypes = exports.buildJournal = exports.buildAttribution = exports.buildContributorRole = exports.buildContribution = exports.buildColor = exports.buildParagraph = exports.buildSection = exports.buildCorresp = exports.buildFootnotesOrder = exports.buildFootnote = exports.buildInlineMathFragment = exports.buildNote = exports.buildComment = exports.buildSupplementaryMaterial = exports.buildAffiliation = exports.buildFigure = exports.buildKeywordGroup = exports.buildKeyword = exports.buildBibliographyElement = exports.buildBibliographicDate = exports.buildBibliographicName = exports.buildBibliographyItem = exports.buildContributor = exports.buildManuscript = exports.buildProject = void 0;
21
+ exports.buildTitles = exports.buildElementsOrder = exports.auxiliaryObjectTypes = exports.buildJournal = exports.buildAttribution = exports.buildContributorRole = exports.buildContribution = exports.buildColor = exports.buildParagraph = exports.buildSection = exports.buildCorresp = exports.buildFootnotesOrder = exports.buildFootnote = exports.buildNote = exports.buildComment = exports.buildSupplementaryMaterial = exports.buildAffiliation = exports.buildFigure = exports.buildKeywordGroup = exports.buildKeyword = exports.buildBibliographyElement = exports.buildBibliographicDate = exports.buildBibliographicName = exports.buildBibliographyItem = exports.buildContributor = exports.buildManuscript = exports.buildProject = void 0;
22
22
  const json_schema_1 = require("@manuscripts/json-schema");
23
23
  const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
24
24
  const schema_1 = require("../schema");
@@ -115,13 +115,6 @@ const buildNote = (target, source, contents = '') => ({
115
115
  contents,
116
116
  });
117
117
  exports.buildNote = buildNote;
118
- const buildInlineMathFragment = (containingObject, TeXRepresentation) => ({
119
- _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.InlineMathFragment),
120
- objectType: json_schema_1.ObjectTypes.InlineMathFragment,
121
- containingObject: containingObject || undefined,
122
- TeXRepresentation,
123
- });
124
- exports.buildInlineMathFragment = buildInlineMathFragment;
125
118
  const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
126
119
  _id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Footnote),
127
120
  objectType: json_schema_1.ObjectTypes.Footnote,
@@ -280,9 +280,8 @@ class Decoder {
280
280
  const model = data;
281
281
  return schema_1.schema.nodes.equation.createChecked({
282
282
  id: model._id,
283
- MathMLStringRepresentation: model.MathMLStringRepresentation,
284
- SVGStringRepresentation: model.SVGStringRepresentation,
285
- TeXRepresentation: model.TeXRepresentation,
283
+ contents: model.contents,
284
+ format: model.format,
286
285
  });
287
286
  },
288
287
  [json_schema_1.ObjectTypes.EquationElement]: (data) => {
@@ -301,12 +300,10 @@ class Decoder {
301
300
  else {
302
301
  throw new errors_1.MissingElement(model.containedObjectID);
303
302
  }
304
- const figcaption = this.getFigcaption(model);
305
303
  return schema_1.schema.nodes.equation_element.createChecked({
306
304
  id: model._id,
307
- suppressCaption: Boolean(model.suppressCaption),
308
- suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
309
- }, [equation, figcaption]);
305
+ label: model.label,
306
+ }, [equation]);
310
307
  },
311
308
  [json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
312
309
  const foonotesElementModel = data;
@@ -558,33 +555,32 @@ class Decoder {
558
555
  },
559
556
  [json_schema_1.ObjectTypes.Table]: (data) => {
560
557
  const model = data;
561
- const comments = this.createCommentNodes(model);
562
- comments.forEach((c) => this.comments.set(c.attrs.id, c));
563
- return this.parseContents(model.contents, undefined, this.getComments(model), {
558
+ return this.parseContents(model.contents, undefined, [], {
564
559
  topNode: schema_1.schema.nodes.table.create({
565
560
  id: model._id,
566
- comments: comments.map((c) => c.attrs.id),
567
561
  }),
568
562
  });
569
563
  },
570
564
  [json_schema_1.ObjectTypes.TableElement]: (data) => {
571
565
  const model = data;
572
566
  const table = this.createTable(model);
567
+ const tableColGroup = this.createTableColGroup(model);
573
568
  const tableElementFooter = this.createTableElementFooter(model);
574
569
  const figcaption = this.getFigcaption(model);
575
570
  const comments = this.createCommentNodes(model);
576
571
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
577
- const content = tableElementFooter
578
- ? [table, tableElementFooter, figcaption]
579
- : [table, figcaption];
580
- if (model.listingID) {
581
- const listing = this.createListing(model.listingID);
582
- content.push(listing);
572
+ const content = [table];
573
+ if (tableColGroup) {
574
+ content.push(tableColGroup);
583
575
  }
584
- else {
585
- const listing = schema_1.schema.nodes.listing.create();
586
- content.push(listing);
576
+ if (tableElementFooter) {
577
+ content.push(tableElementFooter);
587
578
  }
579
+ content.push(figcaption);
580
+ const listing = model.listingID
581
+ ? this.createListing(model.listingID)
582
+ : schema_1.schema.nodes.listing.create();
583
+ content.push(listing);
588
584
  return schema_1.schema.nodes.table_element.createChecked({
589
585
  id: model._id,
590
586
  table: model.containedObjectID,
@@ -773,23 +769,33 @@ class Decoder {
773
769
  this.allowMissingElements = allowMissingElements;
774
770
  }
775
771
  createTable(model) {
776
- const tableId = model.containedObjectID;
777
- const tableModel = this.getModel(tableId);
772
+ const tableID = model.containedObjectID;
773
+ const tableModel = this.getModel(tableID);
778
774
  let table;
779
775
  if (tableModel) {
780
776
  table = this.decode(tableModel);
781
777
  }
782
778
  else if (this.allowMissingElements) {
783
779
  table = schema_1.schema.nodes.placeholder.create({
784
- id: tableId,
780
+ id: tableID,
785
781
  label: 'A table',
786
782
  });
787
783
  }
788
784
  else {
789
- throw new errors_1.MissingElement(tableId);
785
+ throw new errors_1.MissingElement(tableID);
790
786
  }
791
787
  return table;
792
788
  }
789
+ createTableColGroup(model) {
790
+ const tableID = model.containedObjectID;
791
+ const tableModel = this.getModel(tableID);
792
+ if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
793
+ return undefined;
794
+ }
795
+ return this.parseContents(tableModel.contents, undefined, [], {
796
+ topNode: schema_1.schema.nodes.table_colgroup.create(),
797
+ });
798
+ }
793
799
  createTableElementFooter(model) {
794
800
  const tableElementFooterID = model.tableElementFooterID;
795
801
  if (!tableElementFooterID) {
@@ -62,12 +62,6 @@ const listContents = (node) => {
62
62
  }
63
63
  return (0, w3c_xmlserializer_1.default)(output);
64
64
  };
65
- const svgDefs = (svg) => {
66
- const template = document.createElement('template');
67
- template.innerHTML = svg.trim();
68
- const defs = template.content.querySelector('defs');
69
- return defs ? (0, w3c_xmlserializer_1.default)(defs) : undefined;
70
- };
71
65
  const tableRowDisplayStyle = (tagName, parent) => {
72
66
  switch (tagName) {
73
67
  case 'thead':
@@ -115,8 +109,9 @@ function buildTableColGroup(cols) {
115
109
  }
116
110
  const tableContents = (node, parent) => {
117
111
  const input = serializer.serializeNode(node);
112
+ const parentInput = serializer.serializeNode(parent);
118
113
  const output = document.createElement('table');
119
- const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
114
+ const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
120
115
  if (colgroup) {
121
116
  output.appendChild(colgroup);
122
117
  }
@@ -353,20 +348,13 @@ const encoders = {
353
348
  : false,
354
349
  }),
355
350
  equation: (node) => ({
356
- MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
357
- TeXRepresentation: node.attrs.TeXRepresentation,
358
- SVGStringRepresentation: node.attrs.SVGStringRepresentation,
351
+ contents: node.attrs.contents,
352
+ format: node.attrs.format,
359
353
  }),
360
354
  equation_element: (node) => ({
361
355
  containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
362
- caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
363
- title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
364
- elementType: 'p',
365
- suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
366
- suppressTitle: node.attrs.suppressTitle === undefined ||
367
- node.attrs.suppressTitle === true
368
- ? undefined
369
- : false,
356
+ elementType: 'div',
357
+ label: node.attrs.label,
370
358
  }),
371
359
  figure: (node) => ({
372
360
  contentType: node.attrs.contentType || undefined,
@@ -413,12 +401,6 @@ const encoders = {
413
401
  .map((childNode) => childNode.attrs.id)
414
402
  .filter((id) => id),
415
403
  }),
416
- inline_equation: (node, parent) => ({
417
- containingObject: parent.attrs.id,
418
- TeXRepresentation: node.attrs.TeXRepresentation,
419
- SVGRepresentation: node.attrs.SVGRepresentation,
420
- SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
421
- }),
422
404
  keyword: (node, parent) => ({
423
405
  containedGroup: parent.attrs.id,
424
406
  name: keywordContents(node),
@@ -592,8 +574,7 @@ const encode = (node) => {
592
574
  if (placeholderTypes.includes(child.type)) {
593
575
  return;
594
576
  }
595
- if (parent.type === schema_1.schema.nodes.paragraph &&
596
- child.type !== schema_1.schema.nodes.inline_equation) {
577
+ if (parent.type === schema_1.schema.nodes.paragraph) {
597
578
  return;
598
579
  }
599
580
  if (child.type === schema_1.schema.nodes.footnotes_element) {
@@ -39,7 +39,6 @@ exports.nodeTypesMap = new Map([
39
39
  [schema_1.schema.nodes.footnotes_section, json_schema_1.ObjectTypes.Section],
40
40
  [schema_1.schema.nodes.graphical_abstract_section, json_schema_1.ObjectTypes.Section],
41
41
  [schema_1.schema.nodes.highlight_marker, json_schema_1.ObjectTypes.HighlightMarker],
42
- [schema_1.schema.nodes.inline_equation, json_schema_1.ObjectTypes.InlineMathFragment],
43
42
  [schema_1.schema.nodes.keyword, json_schema_1.ObjectTypes.Keyword],
44
43
  [schema_1.schema.nodes.keywords_element, json_schema_1.ObjectTypes.KeywordsElement],
45
44
  [schema_1.schema.nodes.keywords, json_schema_1.ObjectTypes.Section],
@@ -38,7 +38,6 @@ exports.manuscriptObjects = [
38
38
  json_schema_1.ObjectTypes.CommentAnnotation,
39
39
  json_schema_1.ObjectTypes.Contributor,
40
40
  json_schema_1.ObjectTypes.Footnote,
41
- json_schema_1.ObjectTypes.InlineMathFragment,
42
41
  json_schema_1.ObjectTypes.Section,
43
42
  ].concat(exports.elementObjects);
44
43
  const isManuscriptModel = (model) => {
package/dist/es/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from './lib/section-group-type';
2
2
  export * from './lib/table-cell-styles';
3
3
  export * from './lib/utils';
4
- export * from './mathjax';
5
4
  export * from './schema';
6
5
  export * from './transformer';
7
6
  export * from './jats';
@@ -15,10 +15,8 @@
15
15
  */
16
16
  import mime from 'mime';
17
17
  import { DOMParser, Fragment } from 'prosemirror-model';
18
- import { convertMathMLToSVG } from '../../mathjax/mathml-to-svg';
19
- import { convertTeXToSVG } from '../../mathjax/tex-to-svg';
20
18
  import { schema } from '../../schema';
21
- import { chooseSectionCategory, xmlSerializer } from '../../transformer';
19
+ import { chooseSectionCategory } from '../../transformer';
22
20
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
23
21
  const chooseContentType = (graphicNode) => {
24
22
  if (graphicNode) {
@@ -33,6 +31,28 @@ const chooseContentType = (graphicNode) => {
33
31
  }
34
32
  }
35
33
  };
34
+ const getEquationContent = (p) => {
35
+ var _a;
36
+ const element = p;
37
+ const id = element.getAttribute('id');
38
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
39
+ let contents = '';
40
+ let format = '';
41
+ for (const child of container.childNodes) {
42
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
43
+ switch (nodeName) {
44
+ case 'tex-math':
45
+ contents = child.innerHTML;
46
+ format = 'tex';
47
+ break;
48
+ case 'mml:math':
49
+ contents = child.outerHTML;
50
+ format = 'mathml';
51
+ break;
52
+ }
53
+ }
54
+ return { id, format, contents };
55
+ };
36
56
  const marks = [
37
57
  {
38
58
  tag: 'bold',
@@ -141,91 +161,26 @@ const nodes = [
141
161
  tag: 'inline-formula',
142
162
  node: 'inline_equation',
143
163
  getAttrs: (node) => {
144
- var _a, _b, _c, _d, _e;
145
164
  const element = node;
146
- const attrs = {
147
- id: element.getAttribute('id'),
148
- MathMLRepresentation: '',
149
- SVGRepresentation: '',
150
- TeXRepresentation: '',
151
- };
152
- const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
153
- for (const child of container.childNodes) {
154
- const nodeName = child.nodeName.replace(/^[a-z]:/, '');
155
- switch (nodeName) {
156
- case 'tex-math':
157
- attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
158
- if (attrs.TeXRepresentation) {
159
- attrs.SVGRepresentation =
160
- (_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
161
- }
162
- break;
163
- case 'mml:math':
164
- ;
165
- child.removeAttribute('id');
166
- attrs.MathMLRepresentation = xmlSerializer.serializeToString(child);
167
- if (attrs.MathMLRepresentation) {
168
- attrs.SVGRepresentation =
169
- (_e = convertMathMLToSVG(attrs.MathMLRepresentation, true)) !== null && _e !== void 0 ? _e : '';
170
- }
171
- break;
172
- }
173
- }
174
- return attrs;
165
+ return getEquationContent(element);
175
166
  },
176
167
  },
177
168
  {
178
169
  tag: 'disp-formula',
179
170
  node: 'equation_element',
180
171
  getAttrs: (node) => {
172
+ var _a, _b;
181
173
  const element = node;
182
- const caption = element.querySelector('figcaption');
183
174
  return {
184
175
  id: element.getAttribute('id'),
185
- suppressCaption: !caption,
176
+ label: (_b = (_a = element.querySelector('label')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '',
186
177
  };
187
178
  },
188
179
  getContent: (node, schema) => {
189
- var _a, _b, _c, _d, _e;
190
180
  const element = node;
191
- const attrs = {
192
- MathMLStringRepresentation: '',
193
- SVGStringRepresentation: '',
194
- TeXRepresentation: '',
195
- };
196
- const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
197
- for (const child of container.childNodes) {
198
- const nodeName = child.nodeName.replace(/^[a-z]:/, '');
199
- switch (nodeName) {
200
- case 'tex-math':
201
- attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
202
- if (attrs.TeXRepresentation) {
203
- attrs.SVGStringRepresentation =
204
- (_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
205
- }
206
- break;
207
- case 'mml:math':
208
- ;
209
- child.removeAttribute('id');
210
- attrs.MathMLStringRepresentation =
211
- xmlSerializer.serializeToString(child);
212
- if (attrs.MathMLStringRepresentation) {
213
- attrs.SVGStringRepresentation =
214
- (_e = convertMathMLToSVG(attrs.MathMLStringRepresentation, true)) !== null && _e !== void 0 ? _e : '';
215
- }
216
- break;
217
- }
218
- }
219
- const caption = element.querySelector('figcaption');
220
- const figcaption = schema.nodes.figcaption.create();
181
+ const attrs = getEquationContent(element);
221
182
  return Fragment.from([
222
- schema.nodes.equation.createChecked(attrs),
223
- caption
224
- ?
225
- jatsBodyDOMParser.parse(caption, {
226
- topNode: figcaption,
227
- })
228
- : figcaption,
183
+ schema.nodes.equation.createChecked(Object.assign({}, attrs)),
229
184
  ]);
230
185
  },
231
186
  },
@@ -519,23 +474,9 @@ const nodes = [
519
474
  const element = node;
520
475
  return {
521
476
  id: element.getAttribute('id'),
522
- suppressFooter: !element.querySelector('table > tfoot > tr'),
523
- suppressHeader: !element.querySelector('table > thead > tr'),
524
477
  };
525
478
  },
526
479
  },
527
- {
528
- tag: 'tbody',
529
- skip: true,
530
- },
531
- {
532
- tag: 'tfoot',
533
- skip: true,
534
- },
535
- {
536
- tag: 'thead',
537
- skip: true,
538
- },
539
480
  {
540
481
  tag: 'title',
541
482
  node: 'section_title',
@@ -562,12 +503,12 @@ const nodes = [
562
503
  },
563
504
  {
564
505
  tag: 'th',
565
- node: 'table_cell',
506
+ node: 'table_header',
566
507
  getAttrs: (node) => {
567
508
  const element = node;
568
509
  const colspan = element.getAttribute('colspan');
569
510
  const rowspan = element.getAttribute('rowspan');
570
- 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') });
511
+ 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') });
571
512
  },
572
513
  },
573
514
  {
@@ -236,8 +236,12 @@ export const jatsBodyTransformations = {
236
236
  }
237
237
  },
238
238
  fixTables(body, createElement) {
239
- const tables = body.querySelectorAll('table-wrap > table');
240
- tables.forEach((table) => {
239
+ const tableWraps = body.querySelectorAll('table-wrap');
240
+ tableWraps.forEach((tableWrap) => {
241
+ const table = tableWrap.querySelector('table');
242
+ if (!table) {
243
+ return;
244
+ }
241
245
  const colgroup = table.querySelector('colgroup');
242
246
  const cols = table.querySelectorAll('col');
243
247
  if (!colgroup && table.firstChild && cols.length > 0) {
@@ -245,20 +249,7 @@ export const jatsBodyTransformations = {
245
249
  for (const col of cols) {
246
250
  colgroup.appendChild(col);
247
251
  }
248
- table.insertBefore(colgroup, table.firstChild);
249
- }
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
- }
252
+ tableWrap.insertBefore(colgroup, table.nextSibling);
262
253
  }
263
254
  });
264
255
  },
@@ -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
+ import { v4 as uuidv4 } from 'uuid';
17
+ import { schema } from '../../schema';
16
18
  import { generateID, nodeTypesMap } from '../../transformer';
17
19
  export const updateDocumentIDs = (node, replacements) => {
18
20
  const warnings = [];
@@ -26,6 +28,10 @@ function recurseDoc(node, fn) {
26
28
  node.descendants((n) => fn(n));
27
29
  }
28
30
  const updateNodeID = (node, replacements, warnings) => {
31
+ if (node.type === schema.nodes.inline_equation) {
32
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${uuidv4()}` });
33
+ return;
34
+ }
29
35
  if (!('id' in node.attrs)) {
30
36
  return;
31
37
  }