@manuscripts/transform 2.1.4 → 2.1.5-LEAN-3376-1

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 (59) hide show
  1. package/dist/cjs/index.js +0 -1
  2. package/dist/cjs/jats/importer/jats-body-dom-parser.js +27 -72
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +3 -1
  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 +94 -83
  8. package/dist/cjs/schema/index.js +3 -2
  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/transformer/builders.js +11 -14
  15. package/dist/cjs/transformer/decode.js +17 -8
  16. package/dist/cjs/transformer/encode.js +8 -25
  17. package/dist/cjs/transformer/node-types.js +2 -1
  18. package/dist/cjs/transformer/object-types.js +0 -1
  19. package/dist/es/index.js +0 -1
  20. package/dist/es/jats/importer/jats-body-dom-parser.js +28 -73
  21. package/dist/es/jats/importer/jats-body-transformations.js +3 -1
  22. package/dist/es/jats/importer/jats-front-parser.js +40 -2
  23. package/dist/es/jats/importer/jats-parser-utils.js +6 -0
  24. package/dist/es/jats/importer/parse-jats-article.js +3 -6
  25. package/dist/es/jats/jats-exporter.js +97 -86
  26. package/dist/es/schema/index.js +3 -2
  27. package/dist/{types/mathjax/mathjax-packages.d.ts → es/schema/nodes/author_notes.js} +9 -1
  28. package/dist/es/schema/nodes/contributors.js +1 -1
  29. package/dist/es/schema/nodes/equation.js +12 -14
  30. package/dist/es/schema/nodes/equation_element.js +4 -5
  31. package/dist/es/schema/nodes/inline_equation.js +13 -15
  32. package/dist/es/transformer/builders.js +9 -12
  33. package/dist/es/transformer/decode.js +17 -8
  34. package/dist/es/transformer/encode.js +8 -25
  35. package/dist/es/transformer/node-types.js +2 -1
  36. package/dist/es/transformer/object-types.js +0 -1
  37. package/dist/types/index.d.ts +0 -1
  38. package/dist/types/jats/importer/jats-front-parser.d.ts +10 -1
  39. package/dist/types/jats/jats-exporter.d.ts +5 -0
  40. package/dist/types/schema/index.d.ts +0 -1
  41. package/dist/{es/mathjax/mathjax-packages.js → types/schema/nodes/author_notes.d.ts} +10 -2
  42. package/dist/types/schema/nodes/equation.d.ts +3 -4
  43. package/dist/types/schema/nodes/equation_element.d.ts +1 -2
  44. package/dist/types/schema/nodes/inline_equation.d.ts +4 -3
  45. package/dist/types/schema/types.d.ts +1 -1
  46. package/dist/types/transformer/builders.d.ts +3 -3
  47. package/package.json +4 -5
  48. package/dist/cjs/mathjax/index.js +0 -41
  49. package/dist/cjs/mathjax/mathml-to-svg.js +0 -70
  50. package/dist/cjs/mathjax/tex-to-mathml.js +0 -49
  51. package/dist/cjs/mathjax/tex-to-svg.js +0 -59
  52. package/dist/es/mathjax/index.js +0 -12
  53. package/dist/es/mathjax/mathml-to-svg.js +0 -66
  54. package/dist/es/mathjax/tex-to-mathml.js +0 -45
  55. package/dist/es/mathjax/tex-to-svg.js +0 -55
  56. package/dist/types/mathjax/index.d.ts +0 -3
  57. package/dist/types/mathjax/mathml-to-svg.d.ts +0 -17
  58. package/dist/types/mathjax/tex-to-mathml.d.ts +0 -17
  59. package/dist/types/mathjax/tex-to-svg.d.ts +0 -17
@@ -13,10 +13,10 @@
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
+ import { getModelsByType, ObjectTypes, } from '@manuscripts/json-schema';
17
17
  import { CitationProvider } from '@manuscripts/library';
18
18
  import debug from 'debug';
19
- import { DOMParser, DOMSerializer } from 'prosemirror-model';
19
+ import { DOMParser as ProseMirrorDOMParser, DOMSerializer, } from 'prosemirror-model';
20
20
  import serializeToXML from 'w3c-xmlserializer';
21
21
  import { nodeFromHTML, textFromHTML } from '../lib/html';
22
22
  import { normalizeStyleName } from '../lib/styled-content';
@@ -32,7 +32,7 @@ import { selectVersionIds } from './jats-versions';
32
32
  const warn = debug('manuscripts-transform');
33
33
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
34
34
  const normalizeID = (id) => id.replace(/:/g, '_');
35
- const parser = DOMParser.fromSchema(schema);
35
+ const parser = ProseMirrorDOMParser.fromSchema(schema);
36
36
  const findChildNodeOfType = (node, nodeType) => {
37
37
  for (const child of iterateChildren(node)) {
38
38
  if (child.type === nodeType) {
@@ -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
  }
@@ -606,6 +607,7 @@ export class JATSExporter {
606
607
  this.createSerializer = () => {
607
608
  const getModel = (id) => id ? this.modelMap.get(id) : undefined;
608
609
  const nodes = {
610
+ author_notes: () => ['author-notes', 0],
609
611
  title: () => '',
610
612
  affiliations: () => '',
611
613
  contributors: () => '',
@@ -678,22 +680,20 @@ export class JATSExporter {
678
680
  },
679
681
  doc: () => '',
680
682
  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;
683
+ return this.createEquation(node);
684
+ },
685
+ inline_equation: (node) => {
686
+ const eqElement = this.document.createElement('inline-formula');
687
+ const equation = this.createEquation(node, true);
688
+ eqElement.append(equation);
689
+ return eqElement;
690
+ },
691
+ equation_element: (node) => {
692
+ const eqElement = this.document.createElement('disp-formula');
693
+ eqElement.setAttribute('id', normalizeID(node.attrs.id));
694
+ processChildNodes(eqElement, node, schema.nodes.equation);
695
+ return eqElement;
695
696
  },
696
- equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
697
697
  figcaption: (node) => {
698
698
  if (!node.textContent) {
699
699
  return '';
@@ -743,28 +743,6 @@ export class JATSExporter {
743
743
  },
744
744
  hard_break: () => '',
745
745
  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
746
  inline_footnote: (node) => {
769
747
  const xref = this.document.createElement('xref');
770
748
  xref.setAttribute('ref-type', 'fn');
@@ -1050,6 +1028,7 @@ export class JATSExporter {
1050
1028
  }
1051
1029
  };
1052
1030
  this.buildContributors = (articleMeta) => {
1031
+ var _a;
1053
1032
  const contributors = this.models.filter(isContributor);
1054
1033
  const authorContributors = contributors
1055
1034
  .filter((contributor) => contributor.role === 'author')
@@ -1268,56 +1247,64 @@ export class JATSExporter {
1268
1247
  }
1269
1248
  });
1270
1249
  }
1271
- const noteIDs = [];
1272
- for (const contributor of [...authorContributors, ...otherContributors]) {
1273
- if (contributor.footnote) {
1274
- const ids = contributor.footnote.map((note) => {
1275
- return note.noteID;
1276
- });
1277
- noteIDs.push(...ids);
1278
- }
1279
- if (contributor.corresp) {
1280
- const ids = contributor.corresp.map((corresp) => {
1281
- return corresp.correspID;
1282
- });
1283
- noteIDs.push(...ids);
1284
- }
1285
- }
1286
- const footnotes = [];
1287
- footnotes.push(...this.models.filter(hasObjectType(ObjectTypes.Footnote)));
1288
- const correspodings = [];
1289
- correspodings.push(...this.models.filter(hasObjectType(ObjectTypes.Corresponding)));
1290
- if (footnotes || correspodings) {
1291
- const authorNotesEl = this.document.createElement('author-notes');
1292
- const usedFootnotes = footnotes.filter((footnote) => {
1293
- return noteIDs.includes(footnote._id);
1294
- });
1295
- const usedCorrespodings = correspodings.filter((corresp) => {
1296
- return noteIDs.includes(corresp._id);
1297
- });
1298
- usedFootnotes.forEach((footnote) => {
1299
- const authorFootNote = this.document.createElement('fn');
1300
- authorFootNote.setAttribute('id', normalizeID(footnote._id));
1301
- authorFootNote.innerHTML = footnote.contents;
1302
- authorNotesEl.appendChild(authorFootNote);
1303
- });
1304
- usedCorrespodings.forEach((corresponding) => {
1305
- const correspondingEl = this.document.createElement('corresp');
1306
- correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1307
- if (corresponding.label) {
1308
- const labelEl = this.document.createElement('label');
1309
- labelEl.textContent = corresponding.label;
1310
- correspondingEl.appendChild(labelEl);
1250
+ const authorNotesEl = this.document.createElement('author-notes');
1251
+ const usedCorrespodings = this.getUsedCorrespondings([
1252
+ ...authorContributors,
1253
+ ...otherContributors,
1254
+ ]);
1255
+ usedCorrespodings.forEach((corresp) => {
1256
+ this.appendCorrespondingToElement(corresp, authorNotesEl);
1257
+ });
1258
+ const authorNotes = (_a = getModelsByType(this.modelMap, ObjectTypes.AuthorNotes)) === null || _a === void 0 ? void 0 : _a[0];
1259
+ if (authorNotes) {
1260
+ authorNotes.containedObjectIDs.forEach((id) => {
1261
+ const model = this.modelMap.get(id);
1262
+ if (!model) {
1263
+ return;
1264
+ }
1265
+ if (id.startsWith('MPParagraphElement')) {
1266
+ this.appendParagraphToElement(model, authorNotesEl);
1267
+ }
1268
+ else if (id.startsWith('MPFootnote')) {
1269
+ this.appendFootnoteToElement(model, authorNotesEl);
1311
1270
  }
1312
- correspondingEl.append(corresponding.contents);
1313
- authorNotesEl.appendChild(correspondingEl);
1314
1271
  });
1315
- if (authorNotesEl.childNodes.length > 0) {
1316
- articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1317
- }
1272
+ }
1273
+ if (authorNotesEl.childNodes.length > 0) {
1274
+ articleMeta.insertBefore(authorNotesEl, contribGroup.nextSibling);
1318
1275
  }
1319
1276
  }
1320
1277
  };
1278
+ this.appendCorrespondingToElement = (corresponding, element) => {
1279
+ const correspondingEl = this.document.createElement('corresp');
1280
+ correspondingEl.setAttribute('id', normalizeID(corresponding._id));
1281
+ if (corresponding.label) {
1282
+ const labelEl = this.document.createElement('label');
1283
+ labelEl.textContent = corresponding.label;
1284
+ correspondingEl.appendChild(labelEl);
1285
+ }
1286
+ correspondingEl.append(corresponding.contents);
1287
+ element.appendChild(correspondingEl);
1288
+ };
1289
+ this.appendParagraphToElement = (paragraph, element) => {
1290
+ const parsedDoc = new DOMParser().parseFromString(paragraph.contents, 'text/html');
1291
+ const parsedParagraph = parsedDoc.body.querySelector('p');
1292
+ if (parsedParagraph) {
1293
+ const paragraphEl = this.document.createElement('p');
1294
+ paragraphEl.innerHTML = parsedParagraph.innerHTML;
1295
+ const value = parsedParagraph.getAttribute('id');
1296
+ if (value) {
1297
+ paragraphEl.setAttribute('id', value);
1298
+ }
1299
+ element.appendChild(paragraphEl);
1300
+ }
1301
+ };
1302
+ this.appendFootnoteToElement = (footnote, element) => {
1303
+ const footnoteEl = this.document.createElement('fn');
1304
+ footnoteEl.setAttribute('id', normalizeID(footnote._id));
1305
+ footnoteEl.innerHTML = footnote.contents;
1306
+ element.appendChild(footnoteEl);
1307
+ };
1321
1308
  this.fixBody = (body, fragment) => {
1322
1309
  fragment.descendants((node) => {
1323
1310
  if (node.attrs.id) {
@@ -1605,6 +1592,27 @@ export class JATSExporter {
1605
1592
  this.citationTexts.set(id, output);
1606
1593
  });
1607
1594
  }
1595
+ createEquation(node, isInline = false) {
1596
+ if (node.attrs.format === 'tex') {
1597
+ const texMath = this.document.createElement('tex-math');
1598
+ texMath.innerHTML = node.attrs.contents;
1599
+ return texMath;
1600
+ }
1601
+ else {
1602
+ const math = this.nodeFromJATS(node.attrs.contents);
1603
+ const mathml = math;
1604
+ if (!isInline) {
1605
+ mathml.setAttribute('id', normalizeID(node.attrs.id));
1606
+ }
1607
+ return mathml;
1608
+ }
1609
+ }
1610
+ getUsedCorrespondings(contributors) {
1611
+ return contributors
1612
+ .flatMap((c) => { var _a; return (_a = c.corresp) !== null && _a !== void 0 ? _a : []; })
1613
+ .map((corresp) => this.modelMap.get(corresp.correspID))
1614
+ .filter((corresp) => !!corresp);
1615
+ }
1608
1616
  buildKeywords(articleMeta) {
1609
1617
  const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
1610
1618
  const keywordGroups = new Map();
@@ -1676,6 +1684,9 @@ export class JATSExporter {
1676
1684
  }
1677
1685
  }
1678
1686
  }
1687
+ if (!fnGroup.hasChildNodes()) {
1688
+ fnGroup.remove();
1689
+ }
1679
1690
  }
1680
1691
  }
1681
1692
  });
@@ -19,6 +19,7 @@ import { abstracts } from './nodes/abstracts';
19
19
  import { affiliation } from './nodes/affiliation';
20
20
  import { affiliations } from './nodes/affiliations';
21
21
  import { attribution } from './nodes/attribution';
22
+ import { authorNotes } from './nodes/author_notes';
22
23
  import { backmatter } from './nodes/backmatter';
23
24
  import { bibliographyElement } from './nodes/bibliography_element';
24
25
  import { bibliographyItem } from './nodes/bibliography_item';
@@ -99,7 +100,6 @@ export * from './nodes/footnotes_section';
99
100
  export * from './nodes/graphical_abstract_section';
100
101
  export * from './nodes/hard_break';
101
102
  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';
@@ -199,6 +199,7 @@ export const schema = new Schema({
199
199
  table_row: tableRow,
200
200
  table_col: tableCol,
201
201
  table_colgroup: tableColGroup,
202
+ table_header: tableHeader,
202
203
  text,
203
204
  toc_element: tocElement,
204
205
  toc_section: tocSection,
@@ -210,6 +211,6 @@ export const schema = new Schema({
210
211
  contributors,
211
212
  supplements,
212
213
  supplement,
213
- table_header: tableHeader,
214
+ author_notes: authorNotes,
214
215
  },
215
216
  });
@@ -13,4 +13,12 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const packages: string[];
16
+ export const authorNotes = {
17
+ attrs: {
18
+ id: { default: '' },
19
+ dataTracked: { default: null },
20
+ },
21
+ content: '(footnote | paragraph)+',
22
+ group: 'block element',
23
+ toDOM: () => ['author-notes', 0],
24
+ };
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  export const contributors = {
17
- content: 'contributor*',
17
+ content: 'contributor* author_notes?',
18
18
  attrs: {
19
19
  id: { default: '' },
20
20
  },
@@ -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
  };
@@ -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,
@@ -108,6 +102,11 @@ export const buildFootnote = (containingObject, contents, kind = 'footnote') =>
108
102
  contents,
109
103
  kind,
110
104
  });
105
+ export const buildAuthorNotes = (containedObjectIDs) => ({
106
+ _id: generateID(ObjectTypes.AuthorNotes),
107
+ objectType: ObjectTypes.AuthorNotes,
108
+ containedObjectIDs: containedObjectIDs,
109
+ });
111
110
  export const buildFootnotesOrder = (footnotesList, containedObjectID) => ({
112
111
  _id: generateID(ObjectTypes.FootnotesOrder),
113
112
  objectType: ObjectTypes.FootnotesOrder,
@@ -128,13 +127,12 @@ export const buildSection = (priority = 0, path = []) => {
128
127
  path: path.concat(id),
129
128
  };
130
129
  };
131
- export const buildParagraph = (placeholderInnerHTML) => {
130
+ export const buildParagraph = (innerHTML = '') => {
132
131
  const _id = generateID(ObjectTypes.ParagraphElement);
133
- const element = document.createElementNS('http://www.w3.org/1999/xhtml', 'p');
132
+ const element = document.createElementNS(null, 'p');
134
133
  element.setAttribute('id', _id);
135
- element.setAttribute('class', 'MPElement');
136
- if (placeholderInnerHTML) {
137
- element.setAttribute('data-placeholder-text', placeholderInnerHTML);
134
+ if (innerHTML) {
135
+ element.innerHTML = innerHTML;
138
136
  }
139
137
  const contents = serializeToXML(element);
140
138
  return {
@@ -142,7 +140,6 @@ export const buildParagraph = (placeholderInnerHTML) => {
142
140
  objectType: ObjectTypes.ParagraphElement,
143
141
  elementType: 'p',
144
142
  contents,
145
- placeholderInnerHTML,
146
143
  };
147
144
  };
148
145
  export const buildColor = (value, priority) => ({
@@ -53,6 +53,7 @@ export const getModelsByType = (modelMap, objectType) => {
53
53
  export const sortSectionsByPriority = (a, b) => a.priority === b.priority ? 0 : Number(a.priority) - Number(b.priority);
54
54
  const getSections = (modelMap) => getModelsByType(modelMap, ObjectTypes.Section).sort(sortSectionsByPriority);
55
55
  const getAffiliations = (modelMap) => getModelsByType(modelMap, ObjectTypes.Affiliation);
56
+ const getAuthorNotes = (modelMap) => getModelsByType(modelMap, ObjectTypes.AuthorNotes);
56
57
  const getContributors = (modelMap) => getModelsByType(modelMap, ObjectTypes.Contributor);
57
58
  const getKeywordElements = (modelMap) => getModelsByType(modelMap, ObjectTypes.KeywordsElement);
58
59
  const getSupplements = (modelMap) => getModelsByType(modelMap, ObjectTypes.Supplement);
@@ -82,7 +83,11 @@ export class Decoder {
82
83
  const contributors = getContributors(this.modelMap)
83
84
  .map((c) => this.decode(c))
84
85
  .filter(Boolean);
85
- return schema.nodes.contributors.createAndFill({}, contributors);
86
+ const authorNotes = getAuthorNotes(this.modelMap)
87
+ .map((authorNote) => this.decode(authorNote))
88
+ .filter(Boolean);
89
+ const content = [...contributors, ...authorNotes];
90
+ return schema.nodes.contributors.createAndFill({}, content);
86
91
  }
87
92
  createKeywordsNode() {
88
93
  const elements = getKeywordElements(this.modelMap)
@@ -271,9 +276,8 @@ export class Decoder {
271
276
  const model = data;
272
277
  return schema.nodes.equation.createChecked({
273
278
  id: model._id,
274
- MathMLStringRepresentation: model.MathMLStringRepresentation,
275
- SVGStringRepresentation: model.SVGStringRepresentation,
276
- TeXRepresentation: model.TeXRepresentation,
279
+ contents: model.contents,
280
+ format: model.format,
277
281
  });
278
282
  },
279
283
  [ObjectTypes.EquationElement]: (data) => {
@@ -292,12 +296,10 @@ export class Decoder {
292
296
  else {
293
297
  throw new MissingElement(model.containedObjectID);
294
298
  }
295
- const figcaption = this.getFigcaption(model);
296
299
  return schema.nodes.equation_element.createChecked({
297
300
  id: model._id,
298
- suppressCaption: Boolean(model.suppressCaption),
299
- suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
300
- }, [equation, figcaption]);
301
+ label: model.label,
302
+ }, [equation]);
301
303
  },
302
304
  [ObjectTypes.FootnotesElement]: (data) => {
303
305
  const foonotesElementModel = data;
@@ -483,6 +485,13 @@ export class Decoder {
483
485
  id: model._id,
484
486
  }, content);
485
487
  },
488
+ [ObjectTypes.AuthorNotes]: (data) => {
489
+ const model = data;
490
+ const content = model.containedObjectIDs.map((id) => this.decode(this.modelMap.get(id)));
491
+ return schema.nodes.author_notes.create({
492
+ id: model._id,
493
+ }, content);
494
+ },
486
495
  [ObjectTypes.Section]: (data) => {
487
496
  const model = data;
488
497
  const elements = [];
@@ -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':
@@ -346,20 +340,13 @@ const encoders = {
346
340
  : false,
347
341
  }),
348
342
  equation: (node) => ({
349
- MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
350
- TeXRepresentation: node.attrs.TeXRepresentation,
351
- SVGStringRepresentation: node.attrs.SVGStringRepresentation,
343
+ contents: node.attrs.contents,
344
+ format: node.attrs.format,
352
345
  }),
353
346
  equation_element: (node) => ({
354
347
  containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
355
- caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
356
- title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
357
- elementType: 'p',
358
- suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
359
- suppressTitle: node.attrs.suppressTitle === undefined ||
360
- node.attrs.suppressTitle === true
361
- ? undefined
362
- : false,
348
+ elementType: 'div',
349
+ label: node.attrs.label,
363
350
  }),
364
351
  figure: (node) => ({
365
352
  contentType: node.attrs.contentType || undefined,
@@ -388,6 +375,9 @@ const encoders = {
388
375
  table_element_footer: (node) => ({
389
376
  containedObjectIDs: containedObjectIDs(node),
390
377
  }),
378
+ author_notes: (node) => ({
379
+ containedObjectIDs: containedObjectIDs(node),
380
+ }),
391
381
  footnotes_section: (node, parent, path, priority) => ({
392
382
  category: buildSectionCategory(node),
393
383
  priority: priority.value++,
@@ -406,12 +396,6 @@ const encoders = {
406
396
  .map((childNode) => childNode.attrs.id)
407
397
  .filter((id) => id),
408
398
  }),
409
- inline_equation: (node, parent) => ({
410
- containingObject: parent.attrs.id,
411
- TeXRepresentation: node.attrs.TeXRepresentation,
412
- SVGRepresentation: node.attrs.SVGRepresentation,
413
- SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
414
- }),
415
399
  keyword: (node, parent) => ({
416
400
  containedGroup: parent.attrs.id,
417
401
  name: keywordContents(node),
@@ -584,8 +568,7 @@ export const encode = (node) => {
584
568
  if (placeholderTypes.includes(child.type)) {
585
569
  return;
586
570
  }
587
- if (parent.type === schema.nodes.paragraph &&
588
- child.type !== schema.nodes.inline_equation) {
571
+ if (parent.type === schema.nodes.paragraph) {
589
572
  return;
590
573
  }
591
574
  if (child.type === schema.nodes.footnotes_element) {