@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
@@ -88,7 +88,7 @@ const createDefaultIdGenerator = () => {
88
88
  const counter = createCounter();
89
89
  return async (element) => {
90
90
  const value = String(counter.increment(element.nodeName));
91
- return `${element.nodeName}-${value}`;
91
+ return `${element.localName}-${value}`;
92
92
  };
93
93
  };
94
94
  const chooseRefType = (objectType) => {
@@ -156,6 +156,7 @@ export class JATSExporter {
156
156
  };
157
157
  this.nodeFromJATS = (JATSFragment) => {
158
158
  JATSFragment = JATSFragment.trim();
159
+ JATSFragment = JATSFragment.replace(' ', ' ');
159
160
  if (!JATSFragment.length) {
160
161
  return null;
161
162
  }
@@ -678,22 +679,20 @@ export class JATSExporter {
678
679
  },
679
680
  doc: () => '',
680
681
  equation: (node) => {
681
- const formula = this.document.createElement('disp-formula');
682
- formula.setAttribute('id', normalizeID(node.attrs.id));
683
- if (node.attrs.TeXRepresentation) {
684
- const math = this.document.createElement('tex-math');
685
- math.textContent = node.attrs.TeXRepresentation;
686
- formula.appendChild(math);
687
- }
688
- else if (node.attrs.MathMLStringRepresentation) {
689
- const math = this.nodeFromJATS(node.attrs.MathMLStringRepresentation);
690
- if (math) {
691
- formula.appendChild(math);
692
- }
693
- }
694
- return formula;
682
+ return this.createEquation(node);
683
+ },
684
+ inline_equation: (node) => {
685
+ const eqElement = this.document.createElement('inline-formula');
686
+ const equation = this.createEquation(node, true);
687
+ eqElement.append(equation);
688
+ return eqElement;
689
+ },
690
+ equation_element: (node) => {
691
+ const eqElement = this.document.createElement('disp-formula');
692
+ eqElement.setAttribute('id', normalizeID(node.attrs.id));
693
+ processChildNodes(eqElement, node, schema.nodes.equation);
694
+ return eqElement;
695
695
  },
696
- equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
697
696
  figcaption: (node) => {
698
697
  if (!node.textContent) {
699
698
  return '';
@@ -743,28 +742,6 @@ export class JATSExporter {
743
742
  },
744
743
  hard_break: () => '',
745
744
  highlight_marker: () => '',
746
- inline_equation: (node) => {
747
- const formula = this.document.createElement('inline-formula');
748
- formula.setAttribute('id', normalizeID(node.attrs.id));
749
- if (node.attrs.TeXRepresentation) {
750
- const math = this.document.createElement('tex-math');
751
- math.textContent = node.attrs.TeXRepresentation;
752
- formula.appendChild(math);
753
- }
754
- else if (node.attrs.MathMLRepresentation) {
755
- const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
756
- if (math) {
757
- formula.appendChild(math);
758
- }
759
- }
760
- else if (node.attrs.SVGRepresentation) {
761
- const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
762
- if (math) {
763
- formula.appendChild(math);
764
- }
765
- }
766
- return formula;
767
- },
768
745
  inline_footnote: (node) => {
769
746
  const xref = this.document.createElement('xref');
770
747
  xref.setAttribute('ref-type', 'fn');
@@ -865,9 +842,13 @@ export class JATSExporter {
865
842
  element.setAttribute('position', 'anchor');
866
843
  return element;
867
844
  },
868
- table_body: () => ['tbody', 0],
869
845
  table_cell: (node) => [
870
- node.attrs.celltype,
846
+ 'td',
847
+ 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 })),
848
+ 0,
849
+ ],
850
+ table_header: (node) => [
851
+ 'th',
871
852
  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 })),
872
853
  0,
873
854
  ],
@@ -948,6 +929,26 @@ export class JATSExporter {
948
929
  element.appendChild(this.serializeNode(childNode));
949
930
  }
950
931
  };
932
+ const appendTable = (element, node) => {
933
+ const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
934
+ const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
935
+ if (!tableNode) {
936
+ return;
937
+ }
938
+ const table = this.serializeNode(tableNode);
939
+ const tbodyElement = this.document.createElement('tbody');
940
+ while (table.firstChild) {
941
+ const child = table.firstChild;
942
+ table.removeChild(child);
943
+ tbodyElement.appendChild(child);
944
+ }
945
+ table.appendChild(tbodyElement);
946
+ if (colGroupNode) {
947
+ const colGroup = this.serializeNode(colGroupNode);
948
+ table.insertBefore(colGroup, table.firstChild);
949
+ }
950
+ element.appendChild(table);
951
+ };
951
952
  const createFigureElement = (node, nodeName, contentNodeType, figType) => {
952
953
  const element = createElement(node, nodeName);
953
954
  if (figType) {
@@ -968,7 +969,7 @@ export class JATSExporter {
968
969
  const element = createElement(node, nodeName);
969
970
  appendLabels(element, node);
970
971
  appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
971
- appendChildNodeOfType(element, node, node.type.schema.nodes.table);
972
+ appendTable(element, node);
972
973
  appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
973
974
  if (isExecutableNodeType(node.type)) {
974
975
  processExecutableNode(node, element);
@@ -1581,6 +1582,21 @@ export class JATSExporter {
1581
1582
  this.citationTexts.set(id, output);
1582
1583
  });
1583
1584
  }
1585
+ createEquation(node, isInline = false) {
1586
+ if (node.attrs.format === 'tex') {
1587
+ const texMath = this.document.createElement('tex-math');
1588
+ texMath.innerHTML = node.attrs.contents;
1589
+ return texMath;
1590
+ }
1591
+ else {
1592
+ const math = this.nodeFromJATS(node.attrs.contents);
1593
+ const mathml = math;
1594
+ if (!isInline) {
1595
+ mathml.setAttribute('id', normalizeID(node.attrs.id));
1596
+ }
1597
+ return mathml;
1598
+ }
1599
+ }
1584
1600
  buildKeywords(articleMeta) {
1585
1601
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1586
1602
  const keywordGroups = new Map();
@@ -66,11 +66,10 @@ import { sectionLabel } from './nodes/section_label';
66
66
  import { sectionTitle } from './nodes/section_title';
67
67
  import { supplement } from './nodes/supplement';
68
68
  import { supplements } from './nodes/supplements';
69
- import { table, tableBody } from './nodes/table';
69
+ import { table, tableCell, tableHeader, tableRow } from './nodes/table';
70
70
  import { tableCol, tableColGroup } from './nodes/table_col';
71
71
  import { tableElement } from './nodes/table_element';
72
72
  import { tableElementFooter } from './nodes/table_element_footer';
73
- import { tableCell, tableRow } from './nodes/table_row';
74
73
  import { text } from './nodes/text';
75
74
  import { title } from './nodes/title';
76
75
  import { tocElement } from './nodes/toc_element';
@@ -100,7 +99,6 @@ export * from './nodes/footnotes_section';
100
99
  export * from './nodes/graphical_abstract_section';
101
100
  export * from './nodes/hard_break';
102
101
  export * from './nodes/highlight_marker';
103
- export * from './nodes/inline_equation';
104
102
  export * from './nodes/inline_footnote';
105
103
  export * from './nodes/keyword';
106
104
  export * from './nodes/keywords_element';
@@ -120,7 +118,6 @@ export * from './nodes/section_title';
120
118
  export * from './nodes/table';
121
119
  export * from './nodes/table_col';
122
120
  export * from './nodes/table_element';
123
- export * from './nodes/table_row';
124
121
  export * from './nodes/text';
125
122
  export * from './nodes/toc_element';
126
123
  export * from './nodes/toc_section';
@@ -196,7 +193,6 @@ export const schema = new Schema({
196
193
  section_title: sectionTitle,
197
194
  section_title_plain: sectionTitle,
198
195
  table,
199
- table_body: tableBody,
200
196
  table_cell: tableCell,
201
197
  table_element: tableElement,
202
198
  table_row: tableRow,
@@ -213,5 +209,6 @@ export const schema = new Schema({
213
209
  contributors,
214
210
  supplements,
215
211
  supplement,
212
+ table_header: tableHeader,
216
213
  },
217
214
  });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2019 Atypon Systems LLC
2
+ * © 2023 Atypon Systems LLC
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -17,9 +17,8 @@ import { ObjectTypes } from '@manuscripts/json-schema';
17
17
  export const equation = {
18
18
  attrs: {
19
19
  id: { default: '' },
20
- MathMLStringRepresentation: { default: '' },
21
- SVGStringRepresentation: { default: '' },
22
- TeXRepresentation: { default: '' },
20
+ contents: { default: '' },
21
+ format: { default: '' },
23
22
  dataTracked: { default: null },
24
23
  },
25
24
  group: 'block',
@@ -27,26 +26,25 @@ export const equation = {
27
26
  {
28
27
  tag: `div.${ObjectTypes.Equation}`,
29
28
  getAttrs: (p) => {
30
- const dom = p;
29
+ const htmlEl = p;
31
30
  return {
32
- id: dom.getAttribute('id'),
33
- MathMLStringRepresentation: dom.getAttribute('data-mathml-string-representation'),
34
- SVGStringRepresentation: dom.innerHTML,
35
- TeXRepresentation: dom.getAttribute('data-tex-representation'),
31
+ id: htmlEl.getAttribute('id'),
32
+ format: htmlEl.getAttribute('data-equation-format'),
33
+ contents: htmlEl.innerHTML,
36
34
  };
37
35
  },
38
36
  },
39
37
  ],
40
38
  toDOM: (node) => {
41
39
  const equationNode = node;
40
+ const { id, contents, format } = equationNode.attrs;
42
41
  const dom = document.createElement('div');
43
- dom.setAttribute('id', equationNode.attrs.id);
44
42
  dom.classList.add(ObjectTypes.Equation);
45
- if (equationNode.attrs.MathMLStringRepresentation) {
46
- dom.setAttribute('data-mathml-string-representation', equationNode.attrs.MathMLStringRepresentation);
43
+ dom.setAttribute('id', id);
44
+ if (format) {
45
+ dom.setAttribute('data-equation-format', format);
47
46
  }
48
- dom.setAttribute('data-tex-representation', equationNode.attrs.TeXRepresentation);
49
- dom.innerHTML = equationNode.attrs.SVGStringRepresentation;
47
+ dom.innerHTML = contents;
50
48
  return dom;
51
49
  },
52
50
  };
@@ -14,11 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export const equationElement = {
17
- content: '(equation | placeholder) figcaption',
17
+ content: '(equation | placeholder)',
18
18
  attrs: {
19
19
  id: { default: '' },
20
- suppressCaption: { default: true },
21
- suppressTitle: { default: undefined },
20
+ label: { default: '' },
22
21
  dataTracked: { default: null },
23
22
  comments: { default: null },
24
23
  },
@@ -26,7 +25,7 @@ export const equationElement = {
26
25
  group: 'block element',
27
26
  parseDOM: [
28
27
  {
29
- tag: 'figure.equation',
28
+ tag: 'div.equation',
30
29
  getAttrs: (p) => {
31
30
  const dom = p;
32
31
  return {
@@ -38,7 +37,7 @@ export const equationElement = {
38
37
  toDOM: (node) => {
39
38
  const equationElementNode = node;
40
39
  return [
41
- 'figure',
40
+ 'div',
42
41
  {
43
42
  class: 'equation',
44
43
  id: equationElementNode.attrs.id,
@@ -13,14 +13,13 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ObjectTypes } from '@manuscripts/json-schema';
17
16
  export const inlineEquation = {
18
17
  attrs: {
19
- id: { default: '' },
20
- MathMLRepresentation: { default: '' },
21
- SVGRepresentation: { default: '' },
22
- TeXRepresentation: { default: '' },
23
18
  dataTracked: { default: null },
19
+ comments: { default: null },
20
+ id: { default: '' },
21
+ contents: { default: '' },
22
+ format: { default: '' },
24
23
  },
25
24
  atom: true,
26
25
  inline: true,
@@ -28,28 +27,27 @@ export const inlineEquation = {
28
27
  group: 'inline',
29
28
  parseDOM: [
30
29
  {
31
- tag: `span.${ObjectTypes.InlineMathFragment}`,
30
+ tag: `span.MPInlineMathFragment`,
32
31
  getAttrs: (p) => {
33
32
  const dom = p;
34
33
  return {
34
+ format: dom.getAttribute('data-equation-format'),
35
35
  id: dom.getAttribute('id'),
36
- MathMLRepresentation: dom.getAttribute('data-mathml-representation') || '',
37
- SVGRepresentation: dom.innerHTML || '',
38
- TeXRepresentation: dom.getAttribute('data-tex-representation') || '',
36
+ contents: dom.innerHTML,
39
37
  };
40
38
  },
41
39
  },
42
40
  ],
43
41
  toDOM: (node) => {
44
42
  const inlineEquationNode = node;
43
+ const { id, contents, format } = inlineEquationNode.attrs;
45
44
  const dom = document.createElement('span');
46
- dom.classList.add(ObjectTypes.InlineMathFragment);
47
- dom.setAttribute('id', inlineEquationNode.attrs.id);
48
- dom.setAttribute('data-tex-representation', inlineEquationNode.attrs.TeXRepresentation);
49
- if (inlineEquationNode.attrs.MathMLRepresentation) {
50
- dom.setAttribute('data-mathml-representation', inlineEquationNode.attrs.MathMLRepresentation);
45
+ dom.setAttribute('id', id);
46
+ dom.classList.add('MPInlineMathFragment');
47
+ if (format) {
48
+ dom.setAttribute('data-equation-format', format);
51
49
  }
52
- dom.innerHTML = inlineEquationNode.attrs.SVGRepresentation;
50
+ dom.innerHTML = contents;
53
51
  return dom;
54
52
  },
55
53
  };
@@ -13,19 +13,56 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { tableNodes as createTableNodes, } from 'prosemirror-tables';
17
+ function createCellAttribute(attributeName, defaultValue = null, customGetFromDOM, customSetDOMAttr) {
18
+ return {
19
+ default: defaultValue,
20
+ getFromDOM(dom) {
21
+ if (customGetFromDOM) {
22
+ return customGetFromDOM(dom);
23
+ }
24
+ return dom.getAttribute(attributeName);
25
+ },
26
+ setDOMAttr(value, attrs) {
27
+ if (customSetDOMAttr) {
28
+ customSetDOMAttr(value, attrs);
29
+ }
30
+ else if (value) {
31
+ attrs[attributeName] = value;
32
+ }
33
+ },
34
+ };
35
+ }
36
+ const tableOptions = {
37
+ cellContent: 'inline*',
38
+ cellAttributes: {
39
+ placeholder: createCellAttribute('data-placeholder-text', 'Data', (dom) => dom.getAttribute('data-placeholder-text') || ''),
40
+ valign: createCellAttribute('valign'),
41
+ align: createCellAttribute('align'),
42
+ scope: createCellAttribute('scope'),
43
+ style: createCellAttribute('style'),
44
+ colspan: createCellAttribute('colspan', 1, (dom) => Number(dom.getAttribute('colspan') || 1), (value, attrs) => {
45
+ if (value && value !== 1) {
46
+ attrs['colspan'] = String(value);
47
+ }
48
+ }),
49
+ rowspan: createCellAttribute('rowspan', 1, (dom) => Number(dom.getAttribute('rowspan') || 1), (value, attrs) => {
50
+ if (value && value !== 1) {
51
+ attrs['rowspan'] = String(value);
52
+ }
53
+ }),
54
+ },
55
+ };
56
+ const tableNodes = createTableNodes(tableOptions);
16
57
  export const table = {
17
- content: 'table_colgroup? table_body',
18
- tableRole: 'table',
19
- isolating: true,
20
- group: 'block',
21
- selectable: false,
22
58
  attrs: {
23
59
  id: { default: '' },
24
- headerRows: { default: 1 },
25
- footerRows: { default: 1 },
26
60
  dataTracked: { default: null },
27
- comments: { default: null },
28
61
  },
62
+ content: 'table_row+',
63
+ tableRole: 'table',
64
+ isolating: true,
65
+ group: 'block',
29
66
  parseDOM: [
30
67
  {
31
68
  tag: 'table',
@@ -33,35 +70,20 @@ export const table = {
33
70
  const dom = p;
34
71
  return {
35
72
  id: dom.getAttribute('id'),
36
- headerRows: dom.dataset && dom.dataset['header-rows'],
37
- footerRows: dom.dataset && dom.dataset['footer-rows'],
38
73
  };
39
74
  },
40
75
  },
41
76
  ],
42
- toDOM: (node) => {
43
- const tableNode = node;
77
+ toDOM(node) {
44
78
  return [
45
79
  'table',
46
80
  {
47
- id: tableNode.attrs.id,
48
- 'data-header-rows': String(node.attrs.headerRows),
49
- 'data-footer-rows': String(node.attrs.footerRows),
81
+ id: node.attrs.id,
50
82
  },
51
- 0,
83
+ ['tbody', 0],
52
84
  ];
53
85
  },
54
86
  };
55
- export const tableBody = {
56
- content: 'table_row+',
57
- group: 'block',
58
- tableRole: 'table',
59
- parseDOM: [
60
- {
61
- tag: 'tbody',
62
- },
63
- ],
64
- toDOM() {
65
- return ['tbody', 0];
66
- },
67
- };
87
+ export const tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
88
+ export const tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
89
+ export const tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export const tableElement = {
17
- content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
17
+ content: '(table | placeholder) table_colgroup? table_element_footer? figcaption? (listing | placeholder)',
18
18
  attrs: {
19
19
  id: { default: '' },
20
20
  paragraphStyle: { default: '' },
@@ -95,12 +95,6 @@ export const buildNote = (target, source, contents = '') => ({
95
95
  source,
96
96
  contents,
97
97
  });
98
- export const buildInlineMathFragment = (containingObject, TeXRepresentation) => ({
99
- _id: generateID(ObjectTypes.InlineMathFragment),
100
- objectType: ObjectTypes.InlineMathFragment,
101
- containingObject: containingObject || undefined,
102
- TeXRepresentation,
103
- });
104
98
  export const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
105
99
  _id: generateID(ObjectTypes.Footnote),
106
100
  objectType: ObjectTypes.Footnote,
@@ -271,9 +271,8 @@ export class Decoder {
271
271
  const model = data;
272
272
  return schema.nodes.equation.createChecked({
273
273
  id: model._id,
274
- MathMLStringRepresentation: model.MathMLStringRepresentation,
275
- SVGStringRepresentation: model.SVGStringRepresentation,
276
- TeXRepresentation: model.TeXRepresentation,
274
+ contents: model.contents,
275
+ format: model.format,
277
276
  });
278
277
  },
279
278
  [ObjectTypes.EquationElement]: (data) => {
@@ -292,12 +291,10 @@ export class Decoder {
292
291
  else {
293
292
  throw new MissingElement(model.containedObjectID);
294
293
  }
295
- const figcaption = this.getFigcaption(model);
296
294
  return schema.nodes.equation_element.createChecked({
297
295
  id: model._id,
298
- suppressCaption: Boolean(model.suppressCaption),
299
- suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
300
- }, [equation, figcaption]);
296
+ label: model.label,
297
+ }, [equation]);
301
298
  },
302
299
  [ObjectTypes.FootnotesElement]: (data) => {
303
300
  const foonotesElementModel = data;
@@ -549,33 +546,32 @@ export class Decoder {
549
546
  },
550
547
  [ObjectTypes.Table]: (data) => {
551
548
  const model = data;
552
- const comments = this.createCommentNodes(model);
553
- comments.forEach((c) => this.comments.set(c.attrs.id, c));
554
- return this.parseContents(model.contents, undefined, this.getComments(model), {
549
+ return this.parseContents(model.contents, undefined, [], {
555
550
  topNode: schema.nodes.table.create({
556
551
  id: model._id,
557
- comments: comments.map((c) => c.attrs.id),
558
552
  }),
559
553
  });
560
554
  },
561
555
  [ObjectTypes.TableElement]: (data) => {
562
556
  const model = data;
563
557
  const table = this.createTable(model);
558
+ const tableColGroup = this.createTableColGroup(model);
564
559
  const tableElementFooter = this.createTableElementFooter(model);
565
560
  const figcaption = this.getFigcaption(model);
566
561
  const comments = this.createCommentNodes(model);
567
562
  comments.forEach((c) => this.comments.set(c.attrs.id, c));
568
- const content = tableElementFooter
569
- ? [table, tableElementFooter, figcaption]
570
- : [table, figcaption];
571
- if (model.listingID) {
572
- const listing = this.createListing(model.listingID);
573
- content.push(listing);
563
+ const content = [table];
564
+ if (tableColGroup) {
565
+ content.push(tableColGroup);
574
566
  }
575
- else {
576
- const listing = schema.nodes.listing.create();
577
- content.push(listing);
567
+ if (tableElementFooter) {
568
+ content.push(tableElementFooter);
578
569
  }
570
+ content.push(figcaption);
571
+ const listing = model.listingID
572
+ ? this.createListing(model.listingID)
573
+ : schema.nodes.listing.create();
574
+ content.push(listing);
579
575
  return schema.nodes.table_element.createChecked({
580
576
  id: model._id,
581
577
  table: model.containedObjectID,
@@ -764,23 +760,33 @@ export class Decoder {
764
760
  this.allowMissingElements = allowMissingElements;
765
761
  }
766
762
  createTable(model) {
767
- const tableId = model.containedObjectID;
768
- const tableModel = this.getModel(tableId);
763
+ const tableID = model.containedObjectID;
764
+ const tableModel = this.getModel(tableID);
769
765
  let table;
770
766
  if (tableModel) {
771
767
  table = this.decode(tableModel);
772
768
  }
773
769
  else if (this.allowMissingElements) {
774
770
  table = schema.nodes.placeholder.create({
775
- id: tableId,
771
+ id: tableID,
776
772
  label: 'A table',
777
773
  });
778
774
  }
779
775
  else {
780
- throw new MissingElement(tableId);
776
+ throw new MissingElement(tableID);
781
777
  }
782
778
  return table;
783
779
  }
780
+ createTableColGroup(model) {
781
+ const tableID = model.containedObjectID;
782
+ const tableModel = this.getModel(tableID);
783
+ if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
784
+ return undefined;
785
+ }
786
+ return this.parseContents(tableModel.contents, undefined, [], {
787
+ topNode: schema.nodes.table_colgroup.create(),
788
+ });
789
+ }
784
790
  createTableElementFooter(model) {
785
791
  const tableElementFooterID = model.tableElementFooterID;
786
792
  if (!tableElementFooterID) {
@@ -54,12 +54,6 @@ const listContents = (node) => {
54
54
  }
55
55
  return serializeToXML(output);
56
56
  };
57
- const svgDefs = (svg) => {
58
- const template = document.createElement('template');
59
- template.innerHTML = svg.trim();
60
- const defs = template.content.querySelector('defs');
61
- return defs ? serializeToXML(defs) : undefined;
62
- };
63
57
  const tableRowDisplayStyle = (tagName, parent) => {
64
58
  switch (tagName) {
65
59
  case 'thead':
@@ -107,8 +101,9 @@ function buildTableColGroup(cols) {
107
101
  }
108
102
  const tableContents = (node, parent) => {
109
103
  const input = serializer.serializeNode(node);
104
+ const parentInput = serializer.serializeNode(parent);
110
105
  const output = document.createElement('table');
111
- const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
106
+ const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
112
107
  if (colgroup) {
113
108
  output.appendChild(colgroup);
114
109
  }
@@ -345,20 +340,13 @@ const encoders = {
345
340
  : false,
346
341
  }),
347
342
  equation: (node) => ({
348
- MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
349
- TeXRepresentation: node.attrs.TeXRepresentation,
350
- SVGStringRepresentation: node.attrs.SVGStringRepresentation,
343
+ contents: node.attrs.contents,
344
+ format: node.attrs.format,
351
345
  }),
352
346
  equation_element: (node) => ({
353
347
  containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
354
- caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
355
- title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
356
- elementType: 'p',
357
- suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
358
- suppressTitle: node.attrs.suppressTitle === undefined ||
359
- node.attrs.suppressTitle === true
360
- ? undefined
361
- : false,
348
+ elementType: 'div',
349
+ label: node.attrs.label,
362
350
  }),
363
351
  figure: (node) => ({
364
352
  contentType: node.attrs.contentType || undefined,
@@ -405,12 +393,6 @@ const encoders = {
405
393
  .map((childNode) => childNode.attrs.id)
406
394
  .filter((id) => id),
407
395
  }),
408
- inline_equation: (node, parent) => ({
409
- containingObject: parent.attrs.id,
410
- TeXRepresentation: node.attrs.TeXRepresentation,
411
- SVGRepresentation: node.attrs.SVGRepresentation,
412
- SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
413
- }),
414
396
  keyword: (node, parent) => ({
415
397
  containedGroup: parent.attrs.id,
416
398
  name: keywordContents(node),
@@ -583,8 +565,7 @@ export const encode = (node) => {
583
565
  if (placeholderTypes.includes(child.type)) {
584
566
  return;
585
567
  }
586
- if (parent.type === schema.nodes.paragraph &&
587
- child.type !== schema.nodes.inline_equation) {
568
+ if (parent.type === schema.nodes.paragraph) {
588
569
  return;
589
570
  }
590
571
  if (child.type === schema.nodes.footnotes_element) {
@@ -36,7 +36,6 @@ export const nodeTypesMap = new Map([
36
36
  [schema.nodes.footnotes_section, ObjectTypes.Section],
37
37
  [schema.nodes.graphical_abstract_section, ObjectTypes.Section],
38
38
  [schema.nodes.highlight_marker, ObjectTypes.HighlightMarker],
39
- [schema.nodes.inline_equation, ObjectTypes.InlineMathFragment],
40
39
  [schema.nodes.keyword, ObjectTypes.Keyword],
41
40
  [schema.nodes.keywords_element, ObjectTypes.KeywordsElement],
42
41
  [schema.nodes.keywords, ObjectTypes.Section],