@manuscripts/transform 2.1.1-LEAN-3092-9 → 2.1.1-LEAN-3336-21

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 +1 -0
  2. package/dist/cjs/jats/importer/jats-body-dom-parser.js +74 -33
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +0 -13
  4. package/dist/cjs/jats/importer/jats-parser-utils.js +0 -6
  5. package/dist/cjs/jats/jats-exporter.js +64 -32
  6. package/dist/cjs/mathjax/index.js +41 -0
  7. package/dist/cjs/mathjax/mathjax-packages.js +20 -0
  8. package/dist/cjs/mathjax/mathml-to-svg.js +70 -0
  9. package/dist/cjs/mathjax/tex-to-mathml.js +49 -0
  10. package/dist/cjs/mathjax/tex-to-svg.js +59 -0
  11. package/dist/cjs/schema/index.js +4 -5
  12. package/dist/cjs/schema/nodes/equation.js +14 -12
  13. package/dist/cjs/schema/nodes/equation_element.js +5 -4
  14. package/dist/cjs/schema/nodes/inline_equation.js +15 -13
  15. package/dist/cjs/schema/nodes/table.js +73 -30
  16. package/dist/cjs/schema/nodes/table_element.js +1 -1
  17. package/dist/cjs/transformer/builders.js +8 -1
  18. package/dist/cjs/transformer/decode.js +26 -7
  19. package/dist/cjs/transformer/encode.js +27 -6
  20. package/dist/cjs/transformer/node-types.js +1 -0
  21. package/dist/cjs/transformer/object-types.js +1 -0
  22. package/dist/es/index.js +1 -0
  23. package/dist/es/jats/importer/jats-body-dom-parser.js +75 -34
  24. package/dist/es/jats/importer/jats-body-transformations.js +0 -13
  25. package/dist/es/jats/importer/jats-parser-utils.js +0 -6
  26. package/dist/es/jats/jats-exporter.js +64 -32
  27. package/dist/es/mathjax/index.js +12 -0
  28. package/dist/es/mathjax/mathjax-packages.js +17 -0
  29. package/dist/es/mathjax/mathml-to-svg.js +66 -0
  30. package/dist/es/mathjax/tex-to-mathml.js +45 -0
  31. package/dist/es/mathjax/tex-to-svg.js +55 -0
  32. package/dist/es/schema/index.js +3 -4
  33. package/dist/es/schema/nodes/equation.js +14 -12
  34. package/dist/es/schema/nodes/equation_element.js +5 -4
  35. package/dist/es/schema/nodes/inline_equation.js +15 -13
  36. package/dist/es/schema/nodes/table.js +72 -29
  37. package/dist/es/schema/nodes/table_element.js +1 -1
  38. package/dist/es/transformer/builders.js +6 -0
  39. package/dist/es/transformer/decode.js +26 -7
  40. package/dist/es/transformer/encode.js +27 -6
  41. package/dist/es/transformer/node-types.js +1 -0
  42. package/dist/es/transformer/object-types.js +1 -0
  43. package/dist/types/index.d.ts +1 -0
  44. package/dist/types/jats/jats-exporter.d.ts +0 -1
  45. package/dist/types/mathjax/index.d.ts +3 -0
  46. package/dist/types/mathjax/mathjax-packages.d.ts +16 -0
  47. package/dist/types/mathjax/mathml-to-svg.d.ts +17 -0
  48. package/dist/types/mathjax/tex-to-mathml.d.ts +17 -0
  49. package/dist/types/mathjax/tex-to-svg.d.ts +17 -0
  50. package/dist/types/schema/index.d.ts +1 -1
  51. package/dist/types/schema/nodes/equation.d.ts +4 -3
  52. package/dist/types/schema/nodes/equation_element.d.ts +2 -1
  53. package/dist/types/schema/nodes/inline_equation.d.ts +3 -4
  54. package/dist/types/schema/nodes/table.d.ts +72 -10
  55. package/dist/types/schema/types.d.ts +1 -1
  56. package/dist/types/transformer/builders.d.ts +2 -1
  57. package/dist/types/transformer/decode.d.ts +1 -0
  58. package/package.json +7 -5
  59. package/dist/cjs/schema/nodes/table_row.js +0 -123
  60. package/dist/es/schema/nodes/table_row.js +0 -120
  61. package/dist/types/schema/nodes/table_row.d.ts +0 -41
@@ -13,8 +13,6 @@
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';
18
16
  import { generateID, nodeTypesMap } from '../../transformer';
19
17
  export const updateDocumentIDs = (node, replacements) => {
20
18
  const warnings = [];
@@ -28,10 +26,6 @@ function recurseDoc(node, fn) {
28
26
  node.descendants((n) => fn(n));
29
27
  }
30
28
  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
- }
35
29
  if (!('id' in node.attrs)) {
36
30
  return;
37
31
  }
@@ -156,7 +156,6 @@ export class JATSExporter {
156
156
  };
157
157
  this.nodeFromJATS = (JATSFragment) => {
158
158
  JATSFragment = JATSFragment.trim();
159
- JATSFragment = JATSFragment.replace(' ', ' ');
160
159
  if (!JATSFragment.length) {
161
160
  return null;
162
161
  }
@@ -607,6 +606,11 @@ export class JATSExporter {
607
606
  this.createSerializer = () => {
608
607
  const getModel = (id) => id ? this.modelMap.get(id) : undefined;
609
608
  const nodes = {
609
+ table_header: (node) => [
610
+ 'th',
611
+ 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 })),
612
+ 0,
613
+ ],
610
614
  title: () => '',
611
615
  affiliations: () => '',
612
616
  contributors: () => '',
@@ -679,20 +683,22 @@ export class JATSExporter {
679
683
  },
680
684
  doc: () => '',
681
685
  equation: (node) => {
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;
686
+ const formula = this.document.createElement('disp-formula');
687
+ formula.setAttribute('id', normalizeID(node.attrs.id));
688
+ if (node.attrs.TeXRepresentation) {
689
+ const math = this.document.createElement('tex-math');
690
+ math.textContent = node.attrs.TeXRepresentation;
691
+ formula.appendChild(math);
692
+ }
693
+ else if (node.attrs.MathMLStringRepresentation) {
694
+ const math = this.nodeFromJATS(node.attrs.MathMLStringRepresentation);
695
+ if (math) {
696
+ formula.appendChild(math);
697
+ }
698
+ }
699
+ return formula;
695
700
  },
701
+ equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
696
702
  figcaption: (node) => {
697
703
  if (!node.textContent) {
698
704
  return '';
@@ -742,6 +748,28 @@ export class JATSExporter {
742
748
  },
743
749
  hard_break: () => '',
744
750
  highlight_marker: () => '',
751
+ inline_equation: (node) => {
752
+ const formula = this.document.createElement('inline-formula');
753
+ formula.setAttribute('id', normalizeID(node.attrs.id));
754
+ if (node.attrs.TeXRepresentation) {
755
+ const math = this.document.createElement('tex-math');
756
+ math.textContent = node.attrs.TeXRepresentation;
757
+ formula.appendChild(math);
758
+ }
759
+ else if (node.attrs.MathMLRepresentation) {
760
+ const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
761
+ if (math) {
762
+ formula.appendChild(math);
763
+ }
764
+ }
765
+ else if (node.attrs.SVGRepresentation) {
766
+ const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
767
+ if (math) {
768
+ formula.appendChild(math);
769
+ }
770
+ }
771
+ return formula;
772
+ },
745
773
  inline_footnote: (node) => {
746
774
  const xref = this.document.createElement('xref');
747
775
  xref.setAttribute('ref-type', 'fn');
@@ -842,9 +870,8 @@ export class JATSExporter {
842
870
  element.setAttribute('position', 'anchor');
843
871
  return element;
844
872
  },
845
- table_body: () => ['tbody', 0],
846
873
  table_cell: (node) => [
847
- node.attrs.celltype,
874
+ 'td',
848
875
  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 })),
849
876
  0,
850
877
  ],
@@ -925,6 +952,26 @@ export class JATSExporter {
925
952
  element.appendChild(this.serializeNode(childNode));
926
953
  }
927
954
  };
955
+ const appendTable = (element, node) => {
956
+ const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
957
+ const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
958
+ if (!tableNode) {
959
+ return;
960
+ }
961
+ const table = this.serializeNode(tableNode);
962
+ const tbodyElement = this.document.createElement('tbody');
963
+ while (table.firstChild) {
964
+ const child = table.firstChild;
965
+ table.removeChild(child);
966
+ tbodyElement.appendChild(child);
967
+ }
968
+ table.appendChild(tbodyElement);
969
+ if (colGroupNode) {
970
+ const colGroup = this.serializeNode(colGroupNode);
971
+ table.insertBefore(colGroup, table.firstChild);
972
+ }
973
+ element.appendChild(table);
974
+ };
928
975
  const createFigureElement = (node, nodeName, contentNodeType, figType) => {
929
976
  const element = createElement(node, nodeName);
930
977
  if (figType) {
@@ -945,7 +992,7 @@ export class JATSExporter {
945
992
  const element = createElement(node, nodeName);
946
993
  appendLabels(element, node);
947
994
  appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
948
- appendChildNodeOfType(element, node, node.type.schema.nodes.table);
995
+ appendTable(element, node);
949
996
  appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
950
997
  if (isExecutableNodeType(node.type)) {
951
998
  processExecutableNode(node, element);
@@ -1558,21 +1605,6 @@ export class JATSExporter {
1558
1605
  this.citationTexts.set(id, output);
1559
1606
  });
1560
1607
  }
1561
- createEquation(node, isInline = false) {
1562
- if (node.attrs.format === 'tex') {
1563
- const texMath = this.document.createElement('tex-math');
1564
- texMath.innerHTML = node.attrs.contents;
1565
- return texMath;
1566
- }
1567
- else {
1568
- const math = this.nodeFromJATS(node.attrs.contents);
1569
- const mathml = math;
1570
- if (!isInline) {
1571
- mathml.setAttribute('id', normalizeID(node.attrs.id));
1572
- }
1573
- return mathml;
1574
- }
1575
- }
1576
1608
  buildKeywords(articleMeta) {
1577
1609
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1578
1610
  const keywordGroups = new Map();
@@ -0,0 +1,12 @@
1
+ export const convertMathMLToSVG = async (mathml, display) => {
2
+ const { convertMathMLToSVG } = await import('./mathml-to-svg');
3
+ return convertMathMLToSVG(mathml, display);
4
+ };
5
+ export const convertTeXToMathML = async (tex, display) => {
6
+ const { convertTeXToMathML } = await import('./tex-to-mathml');
7
+ return convertTeXToMathML(tex, display);
8
+ };
9
+ export const convertTeXToSVG = async (tex, display) => {
10
+ const { convertTeXToSVG } = await import('./tex-to-svg');
11
+ return convertTeXToSVG(tex, display);
12
+ };
@@ -0,0 +1,17 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
17
+ export const packages = AllPackages.filter((name) => name !== 'html' && name !== 'bussproofs');
@@ -0,0 +1,66 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
18
+ import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
19
+ import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
20
+ import { MathML } from 'mathjax-full/js/input/mathml';
21
+ import { SVG } from 'mathjax-full/js/output/svg';
22
+ import { xmlSerializer } from '../transformer';
23
+ class ManuscriptsMmlFactory extends MmlFactory {
24
+ constructor() {
25
+ super();
26
+ this.nodeMap.set('image', this.nodeMap.get('none'));
27
+ }
28
+ create(kind, properties = {}, children = []) {
29
+ if (kind === 'image') {
30
+ return this.node['none'](properties, children);
31
+ }
32
+ return this.node[kind](properties, children);
33
+ }
34
+ }
35
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
36
+ setAttribute(node, name, value, ns) {
37
+ if (name !== 'xmlns') {
38
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
39
+ }
40
+ }
41
+ }
42
+ const InputJax = new MathML();
43
+ const OutputJax = new SVG({
44
+ fontCache: 'none',
45
+ });
46
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
47
+ const doc = new HTMLDocument(document, adaptor, {
48
+ InputJax,
49
+ OutputJax,
50
+ MmlFactory: new ManuscriptsMmlFactory(),
51
+ });
52
+ doc.addStyleSheet();
53
+ export const convertMathMLToSVG = (mathml, display) => {
54
+ const item = doc.convert(mathml, {
55
+ display,
56
+ em: 16,
57
+ ex: 8,
58
+ containerWidth: 1000000,
59
+ lineWidth: 1000000,
60
+ scale: 1,
61
+ });
62
+ if (!item || !item.firstChild) {
63
+ return null;
64
+ }
65
+ return xmlSerializer.serializeToString(item.firstChild);
66
+ };
@@ -0,0 +1,45 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
18
+ import { STATE } from 'mathjax-full/js/core/MathItem.js';
19
+ import { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';
20
+ import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
21
+ import { TeX } from 'mathjax-full/js/input/tex';
22
+ import { packages } from './mathjax-packages';
23
+ const InputJax = new TeX({
24
+ packages,
25
+ });
26
+ const adaptor = new HTMLAdaptor(window);
27
+ const doc = new HTMLDocument(document, adaptor, {
28
+ InputJax,
29
+ });
30
+ const visitor = new SerializedMmlVisitor();
31
+ export const convertTeXToMathML = (tex, display) => {
32
+ const item = doc.convert(tex, {
33
+ display,
34
+ em: 16,
35
+ ex: 8,
36
+ containerWidth: 1000000,
37
+ lineWidth: 1000000,
38
+ scale: 1,
39
+ end: STATE.CONVERT,
40
+ });
41
+ if (!item) {
42
+ return null;
43
+ }
44
+ return visitor.visitTree(item);
45
+ };
@@ -0,0 +1,55 @@
1
+ /*!
2
+ * © 2019 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import 'mathjax-full/js/util/entities/all';
17
+ import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
18
+ import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
19
+ import { TeX } from 'mathjax-full/js/input/tex';
20
+ import { SVG } from 'mathjax-full/js/output/svg';
21
+ import { xmlSerializer } from '../transformer';
22
+ import { packages } from './mathjax-packages';
23
+ class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
24
+ setAttribute(node, name, value, ns) {
25
+ if (name !== 'xmlns') {
26
+ ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
27
+ }
28
+ }
29
+ }
30
+ const InputJax = new TeX({
31
+ packages,
32
+ });
33
+ const OutputJax = new SVG({
34
+ fontCache: 'none',
35
+ });
36
+ const adaptor = new ManuscriptsHTMLAdaptor(window);
37
+ const doc = new HTMLDocument(document, adaptor, {
38
+ InputJax,
39
+ OutputJax,
40
+ });
41
+ doc.addStyleSheet();
42
+ export const convertTeXToSVG = (tex, display) => {
43
+ const item = doc.convert(tex, {
44
+ display,
45
+ em: 16,
46
+ ex: 8,
47
+ containerWidth: 1000000,
48
+ lineWidth: 1000000,
49
+ scale: 1,
50
+ });
51
+ if (!item || !item.firstChild) {
52
+ return null;
53
+ }
54
+ return xmlSerializer.serializeToString(item.firstChild);
55
+ };
@@ -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,6 +99,7 @@ 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';
102
+ export * from './nodes/inline_equation';
103
103
  export * from './nodes/inline_footnote';
104
104
  export * from './nodes/keyword';
105
105
  export * from './nodes/keywords_element';
@@ -119,7 +119,6 @@ export * from './nodes/section_title';
119
119
  export * from './nodes/table';
120
120
  export * from './nodes/table_col';
121
121
  export * from './nodes/table_element';
122
- export * from './nodes/table_row';
123
122
  export * from './nodes/text';
124
123
  export * from './nodes/toc_element';
125
124
  export * from './nodes/toc_section';
@@ -195,7 +194,6 @@ export const schema = new Schema({
195
194
  section_title: sectionTitle,
196
195
  section_title_plain: sectionTitle,
197
196
  table,
198
- table_body: tableBody,
199
197
  table_cell: tableCell,
200
198
  table_element: tableElement,
201
199
  table_row: tableRow,
@@ -212,5 +210,6 @@ export const schema = new Schema({
212
210
  contributors,
213
211
  supplements,
214
212
  supplement,
213
+ table_header: tableHeader,
215
214
  },
216
215
  });
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * © 2023 Atypon Systems LLC
2
+ * © 2019 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,8 +17,9 @@ import { ObjectTypes } from '@manuscripts/json-schema';
17
17
  export const equation = {
18
18
  attrs: {
19
19
  id: { default: '' },
20
- contents: { default: '' },
21
- format: { default: '' },
20
+ MathMLStringRepresentation: { default: '' },
21
+ SVGStringRepresentation: { default: '' },
22
+ TeXRepresentation: { default: '' },
22
23
  dataTracked: { default: null },
23
24
  },
24
25
  group: 'block',
@@ -26,25 +27,26 @@ export const equation = {
26
27
  {
27
28
  tag: `div.${ObjectTypes.Equation}`,
28
29
  getAttrs: (p) => {
29
- const htmlEl = p;
30
+ const dom = p;
30
31
  return {
31
- id: htmlEl.getAttribute('id'),
32
- format: htmlEl.getAttribute('data-equation-format'),
33
- contents: htmlEl.innerHTML,
32
+ id: dom.getAttribute('id'),
33
+ MathMLStringRepresentation: dom.getAttribute('data-mathml-string-representation'),
34
+ SVGStringRepresentation: dom.innerHTML,
35
+ TeXRepresentation: dom.getAttribute('data-tex-representation'),
34
36
  };
35
37
  },
36
38
  },
37
39
  ],
38
40
  toDOM: (node) => {
39
41
  const equationNode = node;
40
- const { id, contents, format } = equationNode.attrs;
41
42
  const dom = document.createElement('div');
43
+ dom.setAttribute('id', equationNode.attrs.id);
42
44
  dom.classList.add(ObjectTypes.Equation);
43
- dom.setAttribute('id', id);
44
- if (format) {
45
- dom.setAttribute('data-equation-format', format);
45
+ if (equationNode.attrs.MathMLStringRepresentation) {
46
+ dom.setAttribute('data-mathml-string-representation', equationNode.attrs.MathMLStringRepresentation);
46
47
  }
47
- dom.innerHTML = contents;
48
+ dom.setAttribute('data-tex-representation', equationNode.attrs.TeXRepresentation);
49
+ dom.innerHTML = equationNode.attrs.SVGStringRepresentation;
48
50
  return dom;
49
51
  },
50
52
  };
@@ -14,10 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export const equationElement = {
17
- content: '(equation | placeholder)',
17
+ content: '(equation | placeholder) figcaption',
18
18
  attrs: {
19
19
  id: { default: '' },
20
- label: { default: '' },
20
+ suppressCaption: { default: true },
21
+ suppressTitle: { default: undefined },
21
22
  dataTracked: { default: null },
22
23
  comments: { default: null },
23
24
  },
@@ -25,7 +26,7 @@ export const equationElement = {
25
26
  group: 'block element',
26
27
  parseDOM: [
27
28
  {
28
- tag: 'div.equation',
29
+ tag: 'figure.equation',
29
30
  getAttrs: (p) => {
30
31
  const dom = p;
31
32
  return {
@@ -37,7 +38,7 @@ export const equationElement = {
37
38
  toDOM: (node) => {
38
39
  const equationElementNode = node;
39
40
  return [
40
- 'div',
41
+ 'figure',
41
42
  {
42
43
  class: 'equation',
43
44
  id: equationElementNode.attrs.id,
@@ -13,13 +13,14 @@
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';
16
17
  export const inlineEquation = {
17
18
  attrs: {
18
- dataTracked: { default: null },
19
- comments: { default: null },
20
19
  id: { default: '' },
21
- contents: { default: '' },
22
- format: { default: '' },
20
+ MathMLRepresentation: { default: '' },
21
+ SVGRepresentation: { default: '' },
22
+ TeXRepresentation: { default: '' },
23
+ dataTracked: { default: null },
23
24
  },
24
25
  atom: true,
25
26
  inline: true,
@@ -27,27 +28,28 @@ export const inlineEquation = {
27
28
  group: 'inline',
28
29
  parseDOM: [
29
30
  {
30
- tag: `span.MPInlineMathFragment`,
31
+ tag: `span.${ObjectTypes.InlineMathFragment}`,
31
32
  getAttrs: (p) => {
32
33
  const dom = p;
33
34
  return {
34
- format: dom.getAttribute('data-equation-format'),
35
35
  id: dom.getAttribute('id'),
36
- contents: dom.innerHTML,
36
+ MathMLRepresentation: dom.getAttribute('data-mathml-representation') || '',
37
+ SVGRepresentation: dom.innerHTML || '',
38
+ TeXRepresentation: dom.getAttribute('data-tex-representation') || '',
37
39
  };
38
40
  },
39
41
  },
40
42
  ],
41
43
  toDOM: (node) => {
42
44
  const inlineEquationNode = node;
43
- const { id, contents, format } = inlineEquationNode.attrs;
44
45
  const dom = document.createElement('span');
45
- dom.setAttribute('id', id);
46
- dom.classList.add('MPInlineMathFragment');
47
- if (format) {
48
- dom.setAttribute('data-equation-format', format);
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);
49
51
  }
50
- dom.innerHTML = contents;
52
+ dom.innerHTML = inlineEquationNode.attrs.SVGRepresentation;
51
53
  return dom;
52
54
  },
53
55
  };