@manuscripts/transform 1.5.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/cjs/index.js +1 -1
  2. package/dist/cjs/jats/importer/index.js +1 -3
  3. package/dist/cjs/jats/importer/jats-body-dom-parser.js +23 -227
  4. package/dist/cjs/jats/importer/jats-body-transformations.js +110 -201
  5. package/dist/cjs/jats/importer/jats-comments.js +100 -98
  6. package/dist/cjs/jats/importer/jats-front-parser.js +87 -81
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +51 -39
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +17 -56
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +24 -79
  10. package/dist/cjs/jats/importer/jats-references.js +34 -0
  11. package/dist/cjs/jats/importer/parse-jats-article.js +67 -173
  12. package/dist/cjs/jats/index.js +1 -3
  13. package/dist/cjs/jats/jats-exporter.js +34 -55
  14. package/dist/cjs/lib/section-group-type.js +30 -0
  15. package/dist/cjs/lib/utils.js +1 -25
  16. package/dist/cjs/schema/index.js +20 -17
  17. package/dist/cjs/schema/nodes/abstracts.js +27 -0
  18. package/dist/cjs/schema/nodes/affiliations.js +27 -0
  19. package/dist/cjs/schema/nodes/backmatter.js +27 -0
  20. package/dist/cjs/schema/nodes/body.js +27 -0
  21. package/dist/cjs/schema/nodes/citation.js +10 -15
  22. package/dist/cjs/schema/nodes/{comment_list.js → comments.js} +4 -4
  23. package/dist/cjs/schema/nodes/contributors.js +27 -0
  24. package/dist/cjs/schema/nodes/{meta_section.js → core_section.js} +6 -5
  25. package/dist/cjs/schema/nodes/cross_reference.js +4 -3
  26. package/dist/cjs/schema/nodes/inline_footnote.js +6 -5
  27. package/dist/cjs/schema/nodes/keyword.js +0 -1
  28. package/dist/cjs/schema/nodes/{keywords_group.js → keyword_group.js} +6 -6
  29. package/dist/cjs/schema/nodes/{keywords_section.js → keywords.js} +7 -7
  30. package/dist/cjs/schema/nodes/keywords_element.js +1 -1
  31. package/dist/cjs/schema/nodes/manuscript.js +5 -2
  32. package/dist/cjs/transformer/builders.js +9 -86
  33. package/dist/cjs/transformer/decode.js +147 -176
  34. package/dist/cjs/transformer/encode.js +66 -67
  35. package/dist/cjs/transformer/highlight-markers.js +48 -36
  36. package/dist/cjs/transformer/html.js +7 -23
  37. package/dist/cjs/transformer/labels.js +3 -17
  38. package/dist/cjs/transformer/node-names.js +1 -1
  39. package/dist/cjs/transformer/node-title.js +1 -1
  40. package/dist/cjs/transformer/node-types.js +7 -6
  41. package/dist/cjs/transformer/object-types.js +1 -2
  42. package/dist/cjs/transformer/section-category.js +31 -31
  43. package/dist/es/index.js +1 -1
  44. package/dist/es/jats/importer/index.js +1 -1
  45. package/dist/es/jats/importer/jats-body-dom-parser.js +23 -227
  46. package/dist/es/jats/importer/jats-body-transformations.js +111 -202
  47. package/dist/es/jats/importer/jats-comments.js +97 -96
  48. package/dist/es/jats/importer/jats-front-parser.js +88 -82
  49. package/dist/es/jats/importer/jats-journal-meta-parser.js +51 -39
  50. package/dist/es/jats/importer/jats-parser-utils.js +16 -54
  51. package/dist/es/jats/importer/jats-reference-parser.js +27 -82
  52. package/dist/es/jats/importer/jats-references.js +30 -0
  53. package/dist/es/jats/importer/parse-jats-article.js +70 -174
  54. package/dist/es/jats/index.js +1 -1
  55. package/dist/es/jats/jats-exporter.js +34 -55
  56. package/dist/es/lib/section-group-type.js +27 -0
  57. package/dist/es/lib/utils.js +0 -22
  58. package/dist/es/schema/index.js +21 -18
  59. package/dist/es/schema/nodes/abstracts.js +24 -0
  60. package/dist/es/schema/nodes/affiliations.js +24 -0
  61. package/dist/es/schema/nodes/backmatter.js +24 -0
  62. package/dist/es/schema/nodes/body.js +24 -0
  63. package/dist/es/schema/nodes/citation.js +10 -15
  64. package/dist/es/schema/nodes/{comment_list.js → comments.js} +3 -3
  65. package/dist/es/schema/nodes/contributors.js +24 -0
  66. package/dist/es/schema/nodes/{meta_section.js → core_section.js} +5 -4
  67. package/dist/es/schema/nodes/cross_reference.js +4 -3
  68. package/dist/es/schema/nodes/inline_footnote.js +6 -5
  69. package/dist/es/schema/nodes/keyword.js +0 -1
  70. package/dist/es/schema/nodes/{keywords_group.js → keyword_group.js} +4 -4
  71. package/dist/es/schema/nodes/{keywords_section.js → keywords.js} +5 -5
  72. package/dist/es/schema/nodes/keywords_element.js +1 -1
  73. package/dist/es/schema/nodes/manuscript.js +3 -1
  74. package/dist/es/transformer/builders.js +6 -73
  75. package/dist/es/transformer/decode.js +147 -175
  76. package/dist/es/transformer/encode.js +70 -71
  77. package/dist/es/transformer/highlight-markers.js +44 -32
  78. package/dist/es/transformer/html.js +7 -23
  79. package/dist/es/transformer/labels.js +3 -17
  80. package/dist/es/transformer/node-names.js +1 -1
  81. package/dist/es/transformer/node-title.js +1 -1
  82. package/dist/es/transformer/node-types.js +7 -6
  83. package/dist/es/transformer/object-types.js +0 -1
  84. package/dist/es/transformer/section-category.js +29 -29
  85. package/dist/types/index.d.ts +1 -1
  86. package/dist/types/jats/importer/index.d.ts +1 -1
  87. package/dist/types/jats/importer/jats-body-transformations.d.ts +16 -19
  88. package/dist/types/jats/importer/jats-comments.d.ts +13 -9
  89. package/dist/types/jats/importer/jats-front-parser.d.ts +35 -12
  90. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +4 -4
  91. package/dist/types/jats/importer/jats-parser-utils.d.ts +1 -6
  92. package/dist/types/jats/importer/jats-reference-parser.d.ts +2 -6
  93. package/dist/types/jats/importer/jats-references.d.ts +12 -0
  94. package/dist/types/jats/importer/parse-jats-article.d.ts +5 -17
  95. package/dist/types/jats/index.d.ts +1 -1
  96. package/dist/types/lib/section-group-type.d.ts +23 -0
  97. package/dist/types/lib/utils.d.ts +1 -4
  98. package/dist/types/schema/index.d.ts +4 -5
  99. package/dist/types/schema/nodes/{meta_section.d.ts → abstracts.d.ts} +1 -9
  100. package/dist/types/schema/nodes/affiliations.d.ts +17 -0
  101. package/dist/types/schema/nodes/backmatter.d.ts +17 -0
  102. package/dist/types/schema/nodes/body.d.ts +17 -0
  103. package/dist/types/schema/nodes/citation.d.ts +3 -5
  104. package/dist/types/schema/nodes/comments.d.ts +17 -0
  105. package/dist/types/schema/nodes/contributors.d.ts +17 -0
  106. package/dist/types/schema/nodes/core_section.d.ts +17 -0
  107. package/dist/types/schema/nodes/cross_reference.d.ts +1 -1
  108. package/dist/types/schema/nodes/inline_footnote.d.ts +1 -1
  109. package/dist/types/schema/nodes/keyword.d.ts +0 -1
  110. package/dist/types/schema/nodes/{contributors_element.d.ts → keyword_group.d.ts} +3 -4
  111. package/dist/types/schema/nodes/{comment_list.d.ts → keywords.d.ts} +3 -2
  112. package/dist/types/schema/nodes/manuscript.d.ts +1 -0
  113. package/dist/types/schema/types.d.ts +1 -1
  114. package/dist/types/transformer/builders.d.ts +2 -14
  115. package/dist/types/transformer/decode.d.ts +5 -9
  116. package/dist/types/transformer/encode.d.ts +4 -4
  117. package/dist/types/transformer/highlight-markers.d.ts +7 -2
  118. package/dist/types/transformer/object-types.d.ts +1 -2
  119. package/dist/types/transformer/section-category.d.ts +4 -3
  120. package/package.json +1 -6
  121. package/dist/cjs/lib/core-section-categories.js +0 -29
  122. package/dist/cjs/schema/nodes/affiliations_section.js +0 -36
  123. package/dist/cjs/schema/nodes/contributors_element.js +0 -49
  124. package/dist/cjs/schema/nodes/contributors_section.js +0 -36
  125. package/dist/es/lib/core-section-categories.js +0 -26
  126. package/dist/es/schema/nodes/affiliations_section.js +0 -32
  127. package/dist/es/schema/nodes/contributors_element.js +0 -46
  128. package/dist/es/schema/nodes/contributors_section.js +0 -32
  129. package/dist/types/lib/core-section-categories.d.ts +0 -8
  130. package/dist/types/schema/nodes/affiliations_section.d.ts +0 -11
  131. package/dist/types/schema/nodes/contributors_section.d.ts +0 -12
  132. package/dist/types/schema/nodes/keywords_group.d.ts +0 -26
  133. package/dist/types/schema/nodes/keywords_section.d.ts +0 -26
@@ -25,7 +25,6 @@ const utils_1 = require("../lib/utils");
25
25
  const schema_1 = require("../schema");
26
26
  const builders_1 = require("./builders");
27
27
  const highlight_markers_1 = require("./highlight-markers");
28
- const id_1 = require("./id");
29
28
  const node_types_1 = require("./node-types");
30
29
  const section_category_1 = require("./section-category");
31
30
  const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
@@ -429,34 +428,9 @@ const encoders = {
429
428
  elementType: 'div',
430
429
  paragraphStyle: node.attrs.paragraphStyle || undefined,
431
430
  }),
432
- keywords_group: (node) => ({
431
+ keyword_group: (node) => ({
433
432
  type: node.attrs.type,
434
433
  }),
435
- keywords_section: (node, parent, path, priority) => ({
436
- category: (0, section_category_1.buildSectionCategory)(node),
437
- priority: priority.value++,
438
- title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
439
- path: path.concat([node.attrs.id]),
440
- elementIDs: childElements(node)
441
- .map((childNode) => childNode.attrs.id)
442
- .filter((id) => id),
443
- }),
444
- affiliations_section: (node, parent, path, priority) => ({
445
- category: (0, section_category_1.buildSectionCategory)(node),
446
- priority: priority.value++,
447
- path: path.concat([node.attrs.id]),
448
- elementIDs: childElements(node)
449
- .map((childNode) => childNode.attrs.id)
450
- .filter((id) => id),
451
- }),
452
- contributors_section: (node, parent, path, priority) => ({
453
- category: (0, section_category_1.buildSectionCategory)(node),
454
- priority: priority.value++,
455
- path: path.concat([node.attrs.id]),
456
- elementIDs: childElements(node)
457
- .map((childNode) => childNode.attrs.id)
458
- .filter((id) => id),
459
- }),
460
434
  missing_figure: (node) => ({
461
435
  position: node.attrs.position || undefined,
462
436
  }),
@@ -560,7 +534,6 @@ const modelData = (node, parent, path, priority) => {
560
534
  return encoder(node, parent, path, priority);
561
535
  };
562
536
  const modelFromNode = (node, parent, path, priority) => {
563
- const commentAnnotationsMap = new Map();
564
537
  const objectType = node_types_1.nodeTypesMap.get(node.type);
565
538
  if (!objectType) {
566
539
  throw new Error(`No objectType is defined for ${node.type.name}`);
@@ -571,68 +544,94 @@ const modelFromNode = (node, parent, path, priority) => {
571
544
  }
572
545
  const data = Object.assign(Object.assign({}, modelData(node, parent, path, priority)), { _id: id, objectType: objectType });
573
546
  const model = data;
574
- if ((0, highlight_markers_1.isHighlightableModel)(model)) {
575
- (0, highlight_markers_1.extractHighlightMarkers)(model, commentAnnotationsMap);
576
- }
577
- const comments = [...commentAnnotationsMap.values()];
578
- return { model, comments };
547
+ const markers = (0, highlight_markers_1.extractCommentMarkers)(model);
548
+ return { model, markers };
579
549
  };
580
550
  exports.modelFromNode = modelFromNode;
581
- const encode = (node, preserveWithRepeatedID = false) => {
551
+ const containerTypes = [
552
+ schema_1.schema.nodes.affiliations,
553
+ schema_1.schema.nodes.contributors,
554
+ schema_1.schema.nodes.affiliations,
555
+ schema_1.schema.nodes.keywords,
556
+ schema_1.schema.nodes.abstracts,
557
+ schema_1.schema.nodes.body,
558
+ schema_1.schema.nodes.backmatter,
559
+ ];
560
+ const placeholderTypes = [
561
+ schema_1.schema.nodes.placeholder,
562
+ schema_1.schema.nodes.placeholder_element,
563
+ ];
564
+ const encode = (node) => {
582
565
  const models = new Map();
583
566
  const priority = {
584
567
  value: 1,
585
568
  };
586
- const placeholders = ['placeholder', 'placeholder_element'];
587
- const addModel = (path, parent) => (child) => {
569
+ const processNode = (path, parent) => (child) => {
570
+ if (containerTypes.includes(child.type)) {
571
+ child.forEach(processNode([], child));
572
+ return;
573
+ }
588
574
  if (!child.attrs.id) {
589
575
  return;
590
576
  }
591
577
  if ((0, schema_1.isHighlightMarkerNode)(child)) {
592
578
  return;
593
579
  }
594
- if (child.type === schema_1.schema.nodes.meta_section) {
580
+ if (placeholderTypes.includes(child.type)) {
595
581
  return;
596
582
  }
597
- if (placeholders.includes(child.type.name)) {
583
+ if (parent.type === schema_1.schema.nodes.paragraph &&
584
+ child.type !== schema_1.schema.nodes.inline_equation) {
598
585
  return;
599
586
  }
600
- const { model, comments } = (0, exports.modelFromNode)(child, parent, path, priority);
601
- const existingModel = models.get(model._id);
602
- if (existingModel) {
603
- if (preserveWithRepeatedID && !(0, utils_1.modelsEqual)(model, existingModel)) {
604
- model._id = (0, id_1.generateID)(model.objectType);
605
- }
606
- else {
607
- throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
608
- }
609
- }
610
- comments.forEach((comment) => {
611
- const proseMirrorComment = models.get(comment._id);
612
- if (proseMirrorComment) {
613
- ;
614
- proseMirrorComment.selector = comment.selector;
615
- models.set(comment._id, proseMirrorComment);
587
+ const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
588
+ markers.forEach((marker) => {
589
+ const comment = models.get(marker._id);
590
+ if (comment) {
591
+ comment.selector = {
592
+ from: marker.from,
593
+ to: marker.to,
594
+ };
616
595
  }
617
596
  });
597
+ if (models.has(model._id)) {
598
+ throw Error(`Duplicate ids in encode: ${model._id}`);
599
+ }
618
600
  models.set(model._id, model);
619
- child.forEach(addModel(path.concat(child.attrs.id), child));
601
+ child.forEach(processNode(path.concat(child.attrs.id), child));
620
602
  };
621
- node.forEach((cNode) => {
622
- if (cNode.type === schema_1.schema.nodes.meta_section) {
623
- processMetaSectionNode(cNode, models, priority);
624
- }
625
- });
626
- node.forEach(addModel([], node));
603
+ const comments = node.lastChild;
604
+ if (comments && comments.type === schema_1.schema.nodes.comments) {
605
+ comments.forEach(processNode([], comments));
606
+ }
607
+ node.forEach(processNode([], node));
608
+ if ((0, schema_1.isManuscriptNode)(node)) {
609
+ builders_1.auxiliaryObjectTypes.forEach((t) => {
610
+ const order = generateElementOrder(node, t);
611
+ if (order) {
612
+ models.set(order._id, order);
613
+ }
614
+ });
615
+ }
627
616
  return models;
628
617
  };
629
618
  exports.encode = encode;
630
- const processMetaSectionNode = (node, models, priority) => {
631
- node.descendants((child) => {
632
- if ((!child.content || child.content.size === 0) &&
633
- node_types_1.nodeTypesMap.get(child.type)) {
634
- const { model } = (0, exports.modelFromNode)(child, node, [], priority);
635
- models.set(model._id, model);
619
+ const generateElementOrder = (node, nodeType) => {
620
+ const ids = [];
621
+ node.descendants((n) => {
622
+ if (n.type === nodeType) {
623
+ ids.push(n.attrs.id);
636
624
  }
625
+ return true;
637
626
  });
627
+ if (!ids.length) {
628
+ return undefined;
629
+ }
630
+ const type = node_types_1.nodeTypesMap.get(nodeType);
631
+ if (!type) {
632
+ return undefined;
633
+ }
634
+ const order = (0, builders_1.buildElementsOrder)(type);
635
+ order.elements = ids;
636
+ return order;
638
637
  };
@@ -15,15 +15,14 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.insertHighlightMarkers = exports.extractHighlightMarkers = exports.isHighlightableModel = void 0;
19
- const builders_1 = require("./builders");
20
- const highlightableFields = [
18
+ exports.insertHighlightMarkers = exports.extractCommentMarkers = exports.isHighlightableModel = exports.highlightableFields = void 0;
19
+ exports.highlightableFields = [
21
20
  'caption',
22
21
  'contents',
23
22
  'title',
24
23
  ];
25
24
  const isHighlightableModel = (model) => {
26
- for (const field of highlightableFields) {
25
+ for (const field of exports.highlightableFields) {
27
26
  if (field in model) {
28
27
  return true;
29
28
  }
@@ -31,54 +30,67 @@ const isHighlightableModel = (model) => {
31
30
  return false;
32
31
  };
33
32
  exports.isHighlightableModel = isHighlightableModel;
34
- const extractHighlightMarkers = (model, commentAnnotationsMap) => {
35
- for (const field of highlightableFields) {
33
+ const extractCommentMarkers = (model) => {
34
+ if (!(0, exports.isHighlightableModel)(model)) {
35
+ return [];
36
+ }
37
+ const comments = new Map();
38
+ for (const field of exports.highlightableFields) {
36
39
  let html = model[field];
37
- if (html === undefined) {
40
+ if (!html || !html.includes('highlight-marker')) {
38
41
  continue;
39
42
  }
40
43
  const template = document.createElement('template');
41
44
  template.innerHTML = `<div>${html}</div>`;
42
45
  const element = template.content.firstChild;
43
- if (!(element instanceof Element)) {
46
+ if (!element) {
44
47
  continue;
45
48
  }
46
49
  const markers = element.querySelectorAll('span.highlight-marker');
47
- if (markers.length) {
48
- for (const marker of markers) {
49
- const markerHTML = marker.outerHTML;
50
- const offset = html.indexOf(markerHTML);
51
- if (offset === -1) {
52
- continue;
50
+ if (!markers.length) {
51
+ continue;
52
+ }
53
+ for (const marker of markers) {
54
+ const markerHTML = marker.outerHTML;
55
+ const offset = html.indexOf(markerHTML);
56
+ if (offset === -1) {
57
+ continue;
58
+ }
59
+ const id = marker.getAttribute('id');
60
+ const target = marker.getAttribute('data-target-id');
61
+ if (id && target) {
62
+ const position = marker.getAttribute('data-position');
63
+ if (position === 'start') {
64
+ const comment = {
65
+ _id: id,
66
+ from: offset,
67
+ to: -1,
68
+ };
69
+ comments.set(id, comment);
53
70
  }
54
- const _id = marker.getAttribute('id');
55
- const target = marker.getAttribute('data-target-id');
56
- if (_id && target) {
57
- const position = marker.getAttribute('data-position');
58
- const commentAnnotation = Object.assign(Object.assign({}, (0, builders_1.buildComment)(target, '')), { _id: _id });
59
- if (position === 'start') {
60
- commentAnnotationsMap.set(commentAnnotation._id, Object.assign(Object.assign({}, commentAnnotation), { selector: {
61
- from: offset,
62
- to: -1,
63
- } }));
64
- }
65
- else if (position === 'end') {
66
- const comment = commentAnnotationsMap.get(commentAnnotation._id);
67
- if (comment && comment.selector) {
68
- commentAnnotationsMap.set(comment._id, Object.assign(Object.assign({}, comment), { selector: Object.assign(Object.assign({}, comment.selector), { to: offset }) }));
69
- }
70
- }
71
- else if (position === 'point') {
72
- commentAnnotationsMap.set(commentAnnotation._id, Object.assign(Object.assign({}, commentAnnotation), { selector: { from: offset, to: offset } }));
71
+ else if (position === 'end') {
72
+ const comment = comments.get(id);
73
+ if (comment) {
74
+ comment.to = offset;
73
75
  }
74
76
  }
75
- html = html.substr(0, offset) + html.substr(offset + markerHTML.length);
77
+ else if (position === 'point') {
78
+ const comment = {
79
+ _id: id,
80
+ from: offset,
81
+ to: offset,
82
+ };
83
+ comments.set(id, comment);
84
+ }
76
85
  }
77
- model[field] = html;
86
+ html =
87
+ html.substring(0, offset) + html.substring(offset + markerHTML.length);
78
88
  }
89
+ model[field] = html;
79
90
  }
91
+ return Array.from(comments.values());
80
92
  };
81
- exports.extractHighlightMarkers = extractHighlightMarkers;
93
+ exports.extractCommentMarkers = extractCommentMarkers;
82
94
  const insertHighlightMarkers = (contents, commentAnnotations) => {
83
95
  let output = contents;
84
96
  const sortedComments = commentAnnotations.sort((a, b) => {
@@ -200,11 +200,9 @@ class HTMLTransformer {
200
200
  const citationNode = node;
201
201
  const element = this.document.createElement('span');
202
202
  element.setAttribute('class', 'citation');
203
- const citation = getModel(citationNode.attrs.rid);
204
- if (citation) {
205
- element.setAttribute('data-reference-ids', citation.embeddedCitationItems
206
- .map((item) => item.bibliographyItem)
207
- .join(' '));
203
+ const rids = citationNode.attrs.rids;
204
+ if (rids.length) {
205
+ element.setAttribute('data-reference-ids', rids.join(' '));
208
206
  }
209
207
  if (citationNode.attrs.contents) {
210
208
  element.innerHTML = citationNode.attrs.contents;
@@ -212,25 +210,11 @@ class HTMLTransformer {
212
210
  return element;
213
211
  };
214
212
  nodes.cross_reference = (node) => {
215
- const crossReferenceNode = node;
213
+ const xref = node;
216
214
  const element = this.document.createElement('a');
217
215
  element.classList.add('cross-reference');
218
- const auxiliaryObjectReference = getModel(crossReferenceNode.attrs.rid);
219
- if (auxiliaryObjectReference &&
220
- auxiliaryObjectReference.referencedObject) {
221
- if (auxiliaryObjectReference.referencedObject.startsWith('MPFigureElement')) {
222
- const model = getModel(auxiliaryObjectReference.referencedObject);
223
- if (model && model.containedObjectIDs.length > 0) {
224
- element.setAttribute('href', `#${model.containedObjectIDs[0]}`);
225
- }
226
- }
227
- else {
228
- element.setAttribute('href', `#${auxiliaryObjectReference.referencedObject}`);
229
- }
230
- element.setAttribute('data-reference-ids', crossReferenceNode.attrs.rid);
231
- }
232
- element.textContent =
233
- crossReferenceNode.attrs.customLabel || crossReferenceNode.attrs.label;
216
+ element.setAttribute('data-reference-ids', xref.attrs.rids.join(' '));
217
+ element.textContent = xref.attrs.customLabel || xref.attrs.label;
234
218
  return element;
235
219
  };
236
220
  nodes.listing = (node) => {
@@ -262,7 +246,7 @@ class HTMLTransformer {
262
246
  };
263
247
  return ['span', attrs];
264
248
  };
265
- nodes.meta_section = () => '';
249
+ nodes.comments = () => '';
266
250
  const serializer = new prosemirror_model_1.DOMSerializer(nodes, marks);
267
251
  return serializer.serializeFragment(fragment, { document });
268
252
  };
@@ -30,6 +30,7 @@ const labelProperties = new Map([
30
30
  [schema_1.schema.nodes.equation_element, 'equationElementLabel'],
31
31
  [schema_1.schema.nodes.listing_element, 'listingElementLabel'],
32
32
  ]);
33
+ const excludedTypes = [schema_1.schema.nodes.graphical_abstract_section];
33
34
  const chooseLabel = (nodeType, manuscript) => {
34
35
  const labelProperty = labelProperties.get(nodeType);
35
36
  if (labelProperty) {
@@ -54,25 +55,10 @@ const buildTargets = (fragment, manuscript) => {
54
55
  return `${counter.label} ${counter.index}`;
55
56
  };
56
57
  const targets = new Map();
57
- const figures = [];
58
- fragment.forEach((node) => {
59
- if (node.attrs.category === 'MPSectionCategory:abstracts') {
60
- node.forEach((child) => {
61
- if (child.type === node.type.schema.nodes.graphical_abstract_section) {
62
- child.forEach((item) => {
63
- if (item.type === node.type.schema.nodes.figure_element) {
64
- figures.push(item.attrs.id);
65
- }
66
- });
67
- }
68
- });
69
- }
70
- });
71
- fragment.descendants((node) => {
58
+ fragment.descendants((node, pos, parent) => {
72
59
  var _a;
73
60
  if (node.type.name in counters) {
74
- const isInGraphicalAbstract = figures.indexOf(node.attrs.id) > -1;
75
- if (isInGraphicalAbstract) {
61
+ if (parent && excludedTypes.includes(parent.type)) {
76
62
  return;
77
63
  }
78
64
  const label = buildLabel(node.type);
@@ -38,6 +38,6 @@ exports.nodeNames = new Map([
38
38
  [schema_1.schema.nodes.table_element, 'Table'],
39
39
  [schema_1.schema.nodes.blockquote_element, 'Block Quote'],
40
40
  [schema_1.schema.nodes.pullquote_element, 'Pull Quote'],
41
- [schema_1.schema.nodes.keywords_section, 'Section'],
41
+ [schema_1.schema.nodes.keywords, 'Section'],
42
42
  [schema_1.schema.nodes.toc_section, 'Section'],
43
43
  ]);
@@ -50,7 +50,7 @@ const nodeTitle = (node) => {
50
50
  case nodes.section:
51
51
  case nodes.bibliography_section:
52
52
  case nodes.footnotes_section:
53
- case nodes.keywords_section:
53
+ case nodes.keywords:
54
54
  case nodes.toc_section:
55
55
  case nodes.graphical_abstract_section:
56
56
  return snippetOfNodeType(node, nodes.section_title);
@@ -19,6 +19,9 @@ exports.isNodeType = exports.isSectionNodeType = exports.isElementNodeType = exp
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const schema_1 = require("../schema");
21
21
  exports.nodeTypesMap = new Map([
22
+ [schema_1.schema.nodes.abstracts, json_schema_1.ObjectTypes.Section],
23
+ [schema_1.schema.nodes.body, json_schema_1.ObjectTypes.Section],
24
+ [schema_1.schema.nodes.backmatter, json_schema_1.ObjectTypes.Section],
22
25
  [schema_1.schema.nodes.comment, json_schema_1.ObjectTypes.CommentAnnotation],
23
26
  [schema_1.schema.nodes.bibliography_item, json_schema_1.ObjectTypes.BibliographyItem],
24
27
  [schema_1.schema.nodes.bibliography_element, json_schema_1.ObjectTypes.BibliographyElement],
@@ -26,7 +29,6 @@ exports.nodeTypesMap = new Map([
26
29
  [schema_1.schema.nodes.blockquote_element, json_schema_1.ObjectTypes.QuoteElement],
27
30
  [schema_1.schema.nodes.bullet_list, json_schema_1.ObjectTypes.ListElement],
28
31
  [schema_1.schema.nodes.citation, json_schema_1.ObjectTypes.Citation],
29
- [schema_1.schema.nodes.cross_reference, json_schema_1.ObjectTypes.AuxiliaryObjectReference],
30
32
  [schema_1.schema.nodes.equation, json_schema_1.ObjectTypes.Equation],
31
33
  [schema_1.schema.nodes.equation_element, json_schema_1.ObjectTypes.EquationElement],
32
34
  [schema_1.schema.nodes.figure, json_schema_1.ObjectTypes.Figure],
@@ -40,8 +42,8 @@ exports.nodeTypesMap = new Map([
40
42
  [schema_1.schema.nodes.inline_equation, json_schema_1.ObjectTypes.InlineMathFragment],
41
43
  [schema_1.schema.nodes.keyword, json_schema_1.ObjectTypes.Keyword],
42
44
  [schema_1.schema.nodes.keywords_element, json_schema_1.ObjectTypes.KeywordsElement],
43
- [schema_1.schema.nodes.keywords_section, json_schema_1.ObjectTypes.Section],
44
- [schema_1.schema.nodes.keywords_group, json_schema_1.ObjectTypes.KeywordGroup],
45
+ [schema_1.schema.nodes.keywords, json_schema_1.ObjectTypes.Section],
46
+ [schema_1.schema.nodes.keyword_group, json_schema_1.ObjectTypes.KeywordGroup],
45
47
  [schema_1.schema.nodes.listing, json_schema_1.ObjectTypes.Listing],
46
48
  [schema_1.schema.nodes.listing_element, json_schema_1.ObjectTypes.ListingElement],
47
49
  [schema_1.schema.nodes.manuscript, json_schema_1.ObjectTypes.Manuscript],
@@ -53,13 +55,12 @@ exports.nodeTypesMap = new Map([
53
55
  [schema_1.schema.nodes.table_element, json_schema_1.ObjectTypes.TableElement],
54
56
  [schema_1.schema.nodes.toc_element, json_schema_1.ObjectTypes.TOCElement],
55
57
  [schema_1.schema.nodes.toc_section, json_schema_1.ObjectTypes.Section],
56
- [schema_1.schema.nodes.meta_section, json_schema_1.ObjectTypes.MetaSection],
57
58
  [schema_1.schema.nodes.affiliation, json_schema_1.ObjectTypes.Affiliation],
58
59
  [schema_1.schema.nodes.contributor, json_schema_1.ObjectTypes.Contributor],
59
60
  [schema_1.schema.nodes.table_element_footer, json_schema_1.ObjectTypes.TableElementFooter],
61
+ [schema_1.schema.nodes.contributors, json_schema_1.ObjectTypes.Section],
62
+ [schema_1.schema.nodes.affiliations, json_schema_1.ObjectTypes.Section],
60
63
  [schema_1.schema.nodes.title, json_schema_1.ObjectTypes.Titles],
61
- [schema_1.schema.nodes.contributors_section, json_schema_1.ObjectTypes.Section],
62
- [schema_1.schema.nodes.affiliations_section, json_schema_1.ObjectTypes.Section],
63
64
  ]);
64
65
  const isExecutableNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_EXECUTABLE);
65
66
  exports.isExecutableNodeType = isExecutableNodeType;
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.isKeyword = exports.isCommentAnnotation = exports.isUserProfile = exports.isTable = exports.isManuscript = exports.isFigure = exports.hasObjectType = exports.isManuscriptModel = exports.manuscriptObjects = exports.elementObjects = exports.ExtraObjectTypes = void 0;
18
+ exports.isKeyword = exports.isCommentAnnotation = exports.isTable = exports.isManuscript = exports.isFigure = exports.hasObjectType = exports.isManuscriptModel = exports.manuscriptObjects = exports.elementObjects = exports.ExtraObjectTypes = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
20
  var ExtraObjectTypes;
21
21
  (function (ExtraObjectTypes) {
@@ -53,6 +53,5 @@ exports.hasObjectType = hasObjectType;
53
53
  exports.isFigure = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Figure);
54
54
  exports.isManuscript = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Manuscript);
55
55
  exports.isTable = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Table);
56
- exports.isUserProfile = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.UserProfile);
57
56
  exports.isCommentAnnotation = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.CommentAnnotation);
58
57
  exports.isKeyword = (0, exports.hasObjectType)(json_schema_1.ObjectTypes.Keyword);
@@ -15,25 +15,17 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.chooseSecType = exports.chooseJatsFnType = exports.buildSectionCategory = exports.guessSectionCategory = exports.chooseSectionLableName = exports.chooseSectionNodeType = exports.isAnySectionNode = exports.getCoreSectionTitles = void 0;
18
+ exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.getSectionGroupType = exports.chooseSecType = exports.chooseJatsFnType = exports.buildSectionCategory = exports.guessSectionCategory = exports.chooseSectionLableName = exports.chooseSectionNodeType = exports.isAnySectionNode = void 0;
19
19
  const json_schema_1 = require("@manuscripts/json-schema");
20
- const core_section_categories_1 = require("../lib/core-section-categories");
20
+ const section_group_type_1 = require("../lib/section-group-type");
21
21
  const schema_1 = require("../schema");
22
22
  const sectionNodeTypes = [
23
23
  schema_1.schema.nodes.bibliography_section,
24
24
  schema_1.schema.nodes.footnotes_section,
25
- schema_1.schema.nodes.keywords_section,
25
+ schema_1.schema.nodes.keywords,
26
26
  schema_1.schema.nodes.section,
27
27
  schema_1.schema.nodes.toc_section,
28
28
  ];
29
- const getCoreSectionTitles = (sectionCategory) => {
30
- const category = core_section_categories_1.coreSectionCategories.find((section) => section._id === sectionCategory);
31
- if (category) {
32
- return category.titles.length ? category.titles : [' '];
33
- }
34
- throw new Error(`${sectionCategory} not found in core sections`);
35
- };
36
- exports.getCoreSectionTitles = getCoreSectionTitles;
37
29
  const isAnySectionNode = (node) => sectionNodeTypes.includes(node.type);
38
30
  exports.isAnySectionNode = isAnySectionNode;
39
31
  const chooseSectionNodeType = (category) => {
@@ -45,11 +37,7 @@ const chooseSectionNodeType = (category) => {
45
37
  case 'MPSectionCategory:endnotes':
46
38
  return schema_1.schema.nodes.footnotes_section;
47
39
  case 'MPSectionCategory:keywords':
48
- return schema_1.schema.nodes.keywords_section;
49
- case 'MPSectionCategory:affiliations':
50
- return schema_1.schema.nodes.affiliations_section;
51
- case 'MPSectionCategory:contributors':
52
- return schema_1.schema.nodes.contributors_section;
40
+ return schema_1.schema.nodes.keywords;
53
41
  case 'MPSectionCategory:toc':
54
42
  return schema_1.schema.nodes.toc_section;
55
43
  default:
@@ -90,16 +78,12 @@ const buildSectionCategory = (node) => {
90
78
  return 'MPSectionCategory:bibliography';
91
79
  case schema_1.schema.nodes.footnotes_section:
92
80
  return 'MPSectionCategory:endnotes';
93
- case schema_1.schema.nodes.keywords_section:
81
+ case schema_1.schema.nodes.keywords:
94
82
  return 'MPSectionCategory:keywords';
95
83
  case schema_1.schema.nodes.toc_section:
96
84
  return 'MPSectionCategory:toc';
97
85
  case schema_1.schema.nodes.graphical_abstract_section:
98
86
  return 'MPSectionCategory:abstract-graphical';
99
- case schema_1.schema.nodes.affiliations_section:
100
- return 'MPSectionCategory:affiliations';
101
- case schema_1.schema.nodes.contributors_section:
102
- return 'MPSectionCategory:contributors';
103
87
  default:
104
88
  return node.attrs.category || undefined;
105
89
  }
@@ -128,6 +112,32 @@ const chooseSecType = (sectionCategory) => {
128
112
  }
129
113
  };
130
114
  exports.chooseSecType = chooseSecType;
115
+ const getSectionGroupType = (category) => {
116
+ switch (category) {
117
+ case 'MPSectionCategory:abstract':
118
+ case 'MPSectionCategory:abstract-graphical':
119
+ return section_group_type_1.abstractsType;
120
+ case 'MPSectionCategory:competing-interests':
121
+ case 'MPSectionCategory:con':
122
+ case 'MPSectionCategory:ethics-statement':
123
+ case 'MPSectionCategory:financial-disclosure':
124
+ case 'MPSectionCategory:supplementary-material':
125
+ case 'MPSectionCategory:supported-by':
126
+ case 'MPSectionCategory:availability':
127
+ case 'MPSectionCategory:acknowledgement':
128
+ case 'MPSectionCategory:endnotes':
129
+ case 'MPSectionCategory:bibliography':
130
+ case 'MPSectionCategory:appendices':
131
+ case 'MPSectionCategory:deceased':
132
+ case 'MPSectionCategory:equal':
133
+ case 'MPSectionCategory:present-address':
134
+ case 'MPSectionCategory:presented-at':
135
+ case 'MPSectionCategory:previously-at':
136
+ return section_group_type_1.backmatterType;
137
+ }
138
+ return section_group_type_1.bodyType;
139
+ };
140
+ exports.getSectionGroupType = getSectionGroupType;
131
141
  const chooseSectionCategoryByType = (secType) => {
132
142
  switch (secType) {
133
143
  case 'abstract':
@@ -187,16 +197,6 @@ const chooseSectionCategoryByType = (secType) => {
187
197
  return 'MPSectionCategory:supported-by';
188
198
  case 'ethics-statement':
189
199
  return 'MPSectionCategory:ethics-statement';
190
- case 'body':
191
- return 'MPSectionCategory:body';
192
- case 'backmatter':
193
- return 'MPSectionCategory:backmatter';
194
- case 'abstracts':
195
- return 'MPSectionCategory:abstracts';
196
- case 'affiliations':
197
- return 'MPSectionCategory:affiliations';
198
- case 'contributors':
199
- return 'MPSectionCategory:contributors';
200
200
  default:
201
201
  return undefined;
202
202
  }
package/dist/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from './lib/core-section-categories';
1
+ export * from './lib/section-group-type';
2
2
  export * from './lib/table-cell-styles';
3
3
  export * from './lib/utils';
4
4
  export * from './mathjax';
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { parseJATSFront, parseJATSBody, parseJATSReferences, parseJATSArticle, getElementsOrder, } from './parse-jats-article';
16
+ export { parseJATSFront, parseJATSBody, parseJATSArticle, } from './parse-jats-article';