@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
@@ -29,15 +29,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.Decoder = exports.isManuscriptNode = exports.sortSectionsByPriority = exports.getModelsByType = exports.getModelData = void 0;
32
+ exports.Decoder = exports.sortSectionsByPriority = exports.getModelsByType = exports.getModelData = void 0;
33
33
  const json_schema_1 = require("@manuscripts/json-schema");
34
34
  const debug_1 = __importDefault(require("debug"));
35
35
  const prosemirror_model_1 = require("prosemirror-model");
36
36
  const errors_1 = require("../errors");
37
+ const section_group_type_1 = require("../lib/section-group-type");
37
38
  const schema_1 = require("../schema");
38
39
  const builders_1 = require("./builders");
39
40
  const highlight_markers_1 = require("./highlight-markers");
40
- const id_1 = require("./id");
41
41
  const object_types_1 = require("./object-types");
42
42
  const section_category_1 = require("./section-category");
43
43
  const timestamp_1 = require("./timestamp");
@@ -63,79 +63,79 @@ exports.sortSectionsByPriority = sortSectionsByPriority;
63
63
  const getSections = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Section).sort(exports.sortSectionsByPriority);
64
64
  const getAffiliations = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Affiliation);
65
65
  const getContributors = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Contributor);
66
- const isManuscriptNode = (model) => model !== null;
67
- exports.isManuscriptNode = isManuscriptNode;
68
- const isParagraphElement = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.ParagraphElement);
66
+ const getKeywordElements = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordsElement);
67
+ const getKeywordGroups = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordGroup);
68
+ const getKeywords = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Keyword);
69
+ const getTitles = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Titles)[0];
69
70
  const isFootnote = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Footnote);
70
- const isKeyword = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Keyword);
71
- const isKeywordsSection = (model) => model.category === 'MPSectionCategory:keywords';
72
- const isAffiliationsSection = (model) => model.category === 'MPSectionCategory:affiliations';
73
- const isContributorsSection = (model) => model.category === 'MPSectionCategory:contributors';
74
71
  const hasParentSection = (id) => (section) => section.path &&
75
72
  section.path.length > 1 &&
76
73
  section.path[section.path.length - 2] === id;
74
+ const deprecatedCategories = [
75
+ 'MPSectionCategory:contributors',
76
+ 'MPSectionCategory:affiliations',
77
+ 'MPSectionCategory:keywords',
78
+ ];
77
79
  class Decoder {
78
- createMetaSectionNode() {
79
- const commentListNode = this.createCommentListNode();
80
- return schema_1.schema.nodes.meta_section.createAndFill({}, [
81
- commentListNode,
82
- ]);
83
- }
84
- createCommentListNode() {
85
- return schema_1.schema.nodes.comment_list.createAndFill({}, [
86
- ...this.comments.values(),
87
- ]);
80
+ createTitleNode() {
81
+ const titles = getTitles(this.modelMap) || (0, builders_1.buildTitles)();
82
+ return this.decode(titles);
88
83
  }
89
- handleMissingRootSectionNodes(rootSectionNodes) {
90
- if (!rootSectionNodes.find((node) => node.type.name === 'affiliations_section')) {
91
- this.createAffiliationSectionNode(rootSectionNodes);
92
- }
93
- if (!rootSectionNodes.find((node) => node.type.name === 'contributors_section')) {
94
- this.createContributorSectionNode(rootSectionNodes);
95
- }
84
+ createAffiliationsNode() {
85
+ const affiliations = getAffiliations(this.modelMap)
86
+ .map((a) => this.decode(a))
87
+ .filter(Boolean);
88
+ return schema_1.schema.nodes.affiliations.createAndFill({}, affiliations);
96
89
  }
97
- createAffiliationSectionNode(rootSectionNodes) {
98
- const affiliationNodes = getAffiliations(this.modelMap)
99
- .map((affiliation) => this.decode(affiliation))
90
+ createContributorsNode() {
91
+ const contributors = getContributors(this.modelMap)
92
+ .map((c) => this.decode(c))
100
93
  .filter(Boolean);
101
- if (affiliationNodes.length) {
102
- const node = schema_1.schema.nodes.affiliations_section.createAndFill({
103
- id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
104
- }, affiliationNodes);
105
- rootSectionNodes.unshift(node);
106
- }
94
+ return schema_1.schema.nodes.contributors.createAndFill({}, contributors);
107
95
  }
108
- createContributorSectionNode(rootSectionNodes) {
109
- const contributorNodes = getContributors(this.modelMap)
110
- .map((contributor) => this.decode(contributor))
96
+ createKeywordsNode() {
97
+ const elements = getKeywordElements(this.modelMap)
98
+ .map((e) => this.decode(e))
111
99
  .filter(Boolean);
112
- if (contributorNodes.length) {
113
- const node = schema_1.schema.nodes.contributors_section.createAndFill({
114
- id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
115
- }, contributorNodes);
116
- rootSectionNodes.unshift(node);
117
- }
100
+ return schema_1.schema.nodes.keywords.createAndFill({}, [
101
+ schema_1.schema.nodes.section_title.create({}, schema_1.schema.text('Keywords')),
102
+ ...elements,
103
+ ]);
118
104
  }
119
- createTitleNode() {
120
- const titles = (0, exports.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.Titles)[0] ||
121
- (0, builders_1.buildTitles)();
122
- return this.decode(titles);
105
+ createCommentsNode() {
106
+ return schema_1.schema.nodes.comments.createAndFill({}, [
107
+ ...this.comments.values(),
108
+ ]);
123
109
  }
124
- createRootSectionNodes() {
125
- let rootSections = getSections(this.modelMap).filter((section) => !section.path || section.path.length <= 1);
126
- rootSections = this.addGeneratedLabels(rootSections);
127
- const rootSectionNodes = rootSections
128
- .map(this.decode)
129
- .filter(exports.isManuscriptNode);
130
- this.handleMissingRootSectionNodes(rootSectionNodes);
131
- if (!rootSectionNodes.length) {
132
- rootSectionNodes.push(schema_1.schema.nodes.section.createAndFill({
133
- id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
134
- }));
110
+ createContentSections() {
111
+ let sections = getSections(this.modelMap);
112
+ sections = this.addGeneratedLabels(sections);
113
+ const groups = {
114
+ abstracts: [],
115
+ body: [],
116
+ backmatter: [],
117
+ };
118
+ for (const section of sections) {
119
+ if (section.path.length > 1) {
120
+ continue;
121
+ }
122
+ const category = section.category;
123
+ if (category && deprecatedCategories.includes(category)) {
124
+ continue;
125
+ }
126
+ const group = category ? (0, section_category_1.getSectionGroupType)(category) : section_group_type_1.bodyType;
127
+ groups[group._id].push(this.decode(section));
135
128
  }
136
- return rootSectionNodes;
129
+ const abstracts = schema_1.schema.nodes.abstracts.createAndFill({}, groups[section_group_type_1.abstractsType._id]);
130
+ const body = schema_1.schema.nodes.body.createAndFill({}, groups[section_group_type_1.bodyType._id]);
131
+ const backmatter = schema_1.schema.nodes.backmatter.createAndFill({}, groups[section_group_type_1.backmatterType._id]);
132
+ return {
133
+ abstracts,
134
+ body,
135
+ backmatter,
136
+ };
137
137
  }
138
- createCommentsNode(model) {
138
+ createCommentNodes(model) {
139
139
  const comments = [];
140
140
  for (const comment of this.getComments(model)) {
141
141
  comments.push(this.decode(comment));
@@ -147,7 +147,7 @@ class Decoder {
147
147
  }
148
148
  extractListing(model) {
149
149
  if (model.listingID) {
150
- return this.createListing(model);
150
+ return this.createListing(model.listingID);
151
151
  }
152
152
  }
153
153
  constructor(modelMap, allowMissingElements = false) {
@@ -180,8 +180,8 @@ class Decoder {
180
180
  },
181
181
  [json_schema_1.ObjectTypes.BibliographyItem]: (data) => {
182
182
  const model = data;
183
- const commentNodes = this.createCommentsNode(model);
184
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
183
+ const comments = this.createCommentNodes(model);
184
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
185
185
  return schema_1.schema.nodes.bibliography_item.create({
186
186
  id: model._id,
187
187
  type: model.type,
@@ -195,7 +195,7 @@ class Decoder {
195
195
  page: model.page,
196
196
  title: model.title,
197
197
  literal: model.literal,
198
- comments: commentNodes.map((c) => c.attrs.id),
198
+ comments: comments.map((c) => c.attrs.id),
199
199
  });
200
200
  },
201
201
  [object_types_1.ExtraObjectTypes.PlaceholderElement]: (data) => {
@@ -206,14 +206,14 @@ class Decoder {
206
206
  },
207
207
  [json_schema_1.ObjectTypes.Figure]: (data) => {
208
208
  const model = data;
209
- const commentNodes = this.createCommentsNode(model);
210
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
209
+ const comments = this.createCommentNodes(model);
210
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
211
211
  return schema_1.schema.nodes.figure.create({
212
212
  id: model._id,
213
213
  contentType: model.contentType,
214
214
  src: model.src,
215
215
  position: model.position,
216
- comments: commentNodes.map((c) => c.attrs.id),
216
+ comments: comments.map((c) => c.attrs.id),
217
217
  });
218
218
  },
219
219
  [json_schema_1.ObjectTypes.FigureElement]: (data) => {
@@ -242,8 +242,8 @@ class Decoder {
242
242
  figures.push(schema_1.schema.nodes.figure.createAndFill());
243
243
  }
244
244
  const figcaption = this.getFigcaption(model);
245
- const commentNodes = this.createCommentsNode(model);
246
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
245
+ const comments = this.createCommentNodes(model);
246
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
247
247
  const content = [...paragraphs, ...figures, figcaption];
248
248
  const listing = this.extractListing(model);
249
249
  if (listing) {
@@ -264,7 +264,7 @@ class Decoder {
264
264
  suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
265
265
  attribution: model.attribution,
266
266
  alternatives: model.alternatives,
267
- comments: commentNodes.map((c) => c.attrs.id),
267
+ comments: comments.map((c) => c.attrs.id),
268
268
  }, content);
269
269
  },
270
270
  [json_schema_1.ObjectTypes.Equation]: (data) => {
@@ -307,13 +307,13 @@ class Decoder {
307
307
  if (isFootnote(model) &&
308
308
  model.kind === collateByKind &&
309
309
  model.containingObject === foonotesElementModel._id) {
310
- const commentNodes = this.createCommentsNode(model);
311
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
310
+ const comments = this.createCommentNodes(model);
311
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
312
312
  const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
313
313
  topNode: schema_1.schema.nodes.footnote.create({
314
314
  id: model._id,
315
315
  kind: model.kind,
316
- comments: commentNodes.map((c) => c.attrs.id),
316
+ comments: comments.map((c) => c.attrs.id),
317
317
  }),
318
318
  });
319
319
  footnotesOfKind.push(footnote);
@@ -327,36 +327,51 @@ class Decoder {
327
327
  },
328
328
  [json_schema_1.ObjectTypes.Footnote]: (data) => {
329
329
  const footnoteModel = data;
330
- const commentNodes = this.createCommentsNode(footnoteModel);
331
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
330
+ const comments = this.createCommentNodes(footnoteModel);
331
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
332
332
  return this.parseContents(footnoteModel.contents || '<div></div>', undefined, this.getComments(footnoteModel), {
333
333
  topNode: schema_1.schema.nodes.footnote.create({
334
334
  id: footnoteModel._id,
335
335
  kind: footnoteModel.kind,
336
- comments: commentNodes.map((c) => c.attrs.id),
336
+ comments: comments.map((c) => c.attrs.id),
337
337
  }),
338
338
  });
339
339
  },
340
340
  [json_schema_1.ObjectTypes.KeywordsElement]: (data) => {
341
341
  const model = data;
342
- const keywordGroups = this.getKeywordGroups();
342
+ const keywordGroups = getKeywordGroups(this.modelMap).map((k) => this.decode(k));
343
343
  return schema_1.schema.nodes.keywords_element.create({
344
344
  id: model._id,
345
345
  paragraphStyle: model.paragraphStyle,
346
346
  }, keywordGroups);
347
347
  },
348
+ [json_schema_1.ObjectTypes.KeywordGroup]: (data) => {
349
+ const keywordGroup = data;
350
+ const keywords = getKeywords(this.modelMap)
351
+ .filter((k) => k.containedGroup === keywordGroup._id)
352
+ .map((k) => this.decode(k));
353
+ const comments = this.createCommentNodes(keywordGroup);
354
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
355
+ return schema_1.schema.nodes.keyword_group.create({
356
+ id: keywordGroup._id,
357
+ type: keywordGroup.type,
358
+ comments: comments.map((c) => c.attrs.id),
359
+ }, keywords);
360
+ },
348
361
  [json_schema_1.ObjectTypes.Keyword]: (data) => {
349
- const model = data;
362
+ const keyword = data;
363
+ const comments = this.createCommentNodes(keyword);
364
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
350
365
  return schema_1.schema.nodes.keyword.create({
351
- id: model._id,
352
- contents: model.name,
353
- comments: this.createCommentsNode(model),
354
- }, schema_1.schema.text(model.name));
366
+ id: keyword._id,
367
+ contents: keyword.name,
368
+ comments: comments.map((c) => c.attrs.id),
369
+ }, schema_1.schema.text(keyword.name));
355
370
  },
356
371
  [json_schema_1.ObjectTypes.ListElement]: (data) => {
357
372
  const model = data;
358
- const commentNodes = this.createCommentsNode(model);
359
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
373
+ const comments = this.createCommentNodes(model);
374
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
360
375
  switch (model.elementType) {
361
376
  case 'ol':
362
377
  return this.parseContents(model.contents || '<ol></ol>', undefined, this.getComments(model), {
@@ -364,7 +379,7 @@ class Decoder {
364
379
  id: model._id,
365
380
  listStyleType: model.listStyleType,
366
381
  paragraphStyle: model.paragraphStyle,
367
- comments: commentNodes.map((c) => c.attrs.id),
382
+ comments: comments.map((c) => c.attrs.id),
368
383
  }),
369
384
  });
370
385
  case 'ul':
@@ -380,14 +395,14 @@ class Decoder {
380
395
  },
381
396
  [json_schema_1.ObjectTypes.Listing]: (data) => {
382
397
  const model = data;
383
- const commentNodes = this.createCommentsNode(model);
384
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
398
+ const comments = this.createCommentNodes(model);
399
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
385
400
  return schema_1.schema.nodes.listing.createChecked({
386
401
  id: model._id,
387
402
  contents: model.contents,
388
403
  language: model.language,
389
404
  languageKey: model.languageKey,
390
- comments: commentNodes.map((c) => c.attrs.id),
405
+ comments: comments.map((c) => c.attrs.id),
391
406
  });
392
407
  },
393
408
  [json_schema_1.ObjectTypes.ListingElement]: (data) => {
@@ -407,13 +422,13 @@ class Decoder {
407
422
  throw new errors_1.MissingElement(model.containedObjectID);
408
423
  }
409
424
  const figcaption = this.getFigcaption(model);
410
- const commentNodes = this.createCommentsNode(model);
411
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
425
+ const comments = this.createCommentNodes(model);
426
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
412
427
  return schema_1.schema.nodes.listing_element.createChecked({
413
428
  id: model._id,
414
429
  suppressCaption: model.suppressCaption,
415
430
  suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
416
- comments: commentNodes.map((c) => c.attrs.id),
431
+ comments: comments.map((c) => c.attrs.id),
417
432
  }, [listing, figcaption]);
418
433
  },
419
434
  [json_schema_1.ObjectTypes.MissingFigure]: (data) => {
@@ -425,14 +440,14 @@ class Decoder {
425
440
  },
426
441
  [json_schema_1.ObjectTypes.ParagraphElement]: (data) => {
427
442
  const model = data;
428
- const commentNodes = this.createCommentsNode(model);
429
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
443
+ const comments = this.createCommentNodes(model);
444
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
430
445
  return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
431
446
  topNode: schema_1.schema.nodes.paragraph.create({
432
447
  id: model._id,
433
448
  paragraphStyle: model.paragraphStyle,
434
449
  placeholder: model.placeholderInnerHTML,
435
- comments: commentNodes.map((c) => c.attrs.id),
450
+ comments: comments.map((c) => c.attrs.id),
436
451
  }),
437
452
  });
438
453
  },
@@ -473,9 +488,6 @@ class Decoder {
473
488
  for (const id of model.elementIDs) {
474
489
  const element = this.getModel(id);
475
490
  if (element) {
476
- if (isKeywordsSection(model) && isParagraphElement(element)) {
477
- continue;
478
- }
479
491
  elements.push(element);
480
492
  }
481
493
  else if (this.allowMissingElements) {
@@ -494,9 +506,7 @@ class Decoder {
494
506
  }
495
507
  }
496
508
  }
497
- const elementNodes = elements
498
- .map(this.decode)
499
- .filter(exports.isManuscriptNode);
509
+ const elementNodes = elements.map((e) => this.decode(e));
500
510
  const sectionTitle = 'section_title';
501
511
  const sectionTitleNode = model.title
502
512
  ? this.parseContents(model.title, 'h1', this.getComments(model), {
@@ -514,26 +524,20 @@ class Decoder {
514
524
  .map(this.creators[json_schema_1.ObjectTypes.Section]);
515
525
  const sectionCategory = model.category || (0, section_category_1.guessSectionCategory)(elements);
516
526
  const sectionNodeType = (0, section_category_1.chooseSectionNodeType)(sectionCategory);
517
- const commentNodes = this.createCommentsNode(model);
518
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
519
- let content;
520
- if (isAffiliationsSection(model) || isContributorsSection(model)) {
521
- content = elementNodes.concat(nestedSections);
522
- }
523
- else {
524
- content = (sectionLabelNode
525
- ? [sectionLabelNode, sectionTitleNode]
526
- : [sectionTitleNode])
527
- .concat(elementNodes)
528
- .concat(nestedSections);
529
- }
527
+ const comments = this.createCommentNodes(model);
528
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
529
+ const content = (sectionLabelNode
530
+ ? [sectionLabelNode, sectionTitleNode]
531
+ : [sectionTitleNode])
532
+ .concat(elementNodes)
533
+ .concat(nestedSections);
530
534
  const sectionNode = sectionNodeType.createAndFill({
531
535
  id: model._id,
532
536
  category: sectionCategory,
533
537
  titleSuppressed: model.titleSuppressed,
534
538
  pageBreakStyle: model.pageBreakStyle,
535
539
  generatedLabel: model.generatedLabel,
536
- comments: commentNodes.map((c) => c.attrs.id),
540
+ comments: comments.map((c) => c.attrs.id),
537
541
  }, content);
538
542
  if (!sectionNode) {
539
543
  console.error(model);
@@ -543,12 +547,12 @@ class Decoder {
543
547
  },
544
548
  [json_schema_1.ObjectTypes.Table]: (data) => {
545
549
  const model = data;
546
- const commentNodes = this.createCommentsNode(model);
547
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
550
+ const comments = this.createCommentNodes(model);
551
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
548
552
  return this.parseContents(model.contents, undefined, this.getComments(model), {
549
553
  topNode: schema_1.schema.nodes.table.create({
550
554
  id: model._id,
551
- comments: commentNodes.map((c) => c.attrs.id),
555
+ comments: comments.map((c) => c.attrs.id),
552
556
  }),
553
557
  });
554
558
  },
@@ -557,13 +561,13 @@ class Decoder {
557
561
  const table = this.createTable(model);
558
562
  const tableElementFooter = this.createTableElementFooter(model);
559
563
  const figcaption = this.getFigcaption(model);
560
- const commentNodes = this.createCommentsNode(model);
561
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
564
+ const comments = this.createCommentNodes(model);
565
+ comments.forEach((c) => this.comments.set(c.attrs.id, c));
562
566
  const content = tableElementFooter
563
567
  ? [table, figcaption, tableElementFooter]
564
568
  : [table, figcaption];
565
569
  if (model.listingID) {
566
- const listing = this.createListing(model);
570
+ const listing = this.createListing(model.listingID);
567
571
  content.push(listing);
568
572
  }
569
573
  else {
@@ -579,7 +583,7 @@ class Decoder {
579
583
  suppressHeader: model.suppressHeader,
580
584
  tableStyle: model.tableStyle,
581
585
  paragraphStyle: model.paragraphStyle,
582
- comments: commentNodes.map((c) => c.attrs.id),
586
+ comments: comments.map((c) => c.attrs.id),
583
587
  }, content);
584
588
  },
585
589
  [json_schema_1.ObjectTypes.TOCElement]: (data) => {
@@ -645,13 +649,21 @@ class Decoder {
645
649
  };
646
650
  this.getModel = (id) => this.modelMap.get(id);
647
651
  this.createArticleNode = (manuscriptID) => {
648
- const titlesNode = this.createTitleNode();
649
- const rootSectionNodes = this.createRootSectionNodes();
650
- const metaSectionNode = this.createMetaSectionNode();
652
+ const title = this.createTitleNode();
653
+ const contributors = this.createContributorsNode();
654
+ const affiliations = this.createAffiliationsNode();
655
+ const keywords = this.createKeywordsNode();
656
+ const { abstracts, body, backmatter } = this.createContentSections();
657
+ const comments = this.createCommentsNode();
651
658
  const contents = [
652
- titlesNode,
653
- ...rootSectionNodes,
654
- metaSectionNode,
659
+ title,
660
+ contributors,
661
+ affiliations,
662
+ keywords,
663
+ abstracts,
664
+ body,
665
+ backmatter,
666
+ comments,
655
667
  ];
656
668
  return schema_1.schema.nodes.manuscript.create({
657
669
  id: manuscriptID || this.getManuscriptID(),
@@ -693,23 +705,6 @@ class Decoder {
693
705
  }
694
706
  return parser.parse(template.content.firstElementChild, options);
695
707
  };
696
- this.getKeywords = (id) => {
697
- const keywordsOfKind = [];
698
- const keywordsByGroup = [...this.modelMap.values()].filter((m) => m.objectType === json_schema_1.ObjectTypes.Keyword &&
699
- m.containedGroup === id);
700
- for (const model of keywordsByGroup) {
701
- if (isKeyword(model)) {
702
- const keyword = this.parseContents(model.name || '', 'div', this.getComments(model), {
703
- topNode: schema_1.schema.nodes.keyword.create({
704
- id: model._id,
705
- contents: model.name,
706
- }),
707
- });
708
- keywordsOfKind.push(keyword);
709
- }
710
- }
711
- return keywordsOfKind;
712
- };
713
708
  this.getManuscriptID = () => {
714
709
  for (const item of this.modelMap.values()) {
715
710
  if ((0, object_types_1.isManuscript)(item)) {
@@ -777,44 +772,20 @@ class Decoder {
777
772
  ? this.decode(tableElementFooterModel)
778
773
  : undefined;
779
774
  }
780
- createListing(model) {
781
- const listingModel = this.getModel(model.listingID);
782
- let listing;
783
- if (listingModel) {
784
- listing = this.decode(listingModel);
775
+ createListing(id) {
776
+ const listing = this.getModel(id);
777
+ if (listing) {
778
+ return this.decode(listing);
785
779
  }
786
780
  else if (this.allowMissingElements) {
787
- listing = schema_1.schema.nodes.placeholder.create({
788
- id: model.listingID,
781
+ return schema_1.schema.nodes.placeholder.create({
782
+ id,
789
783
  label: 'A listing',
790
784
  });
791
785
  }
792
786
  else {
793
- throw new errors_1.MissingElement(model.listingID);
794
- }
795
- return listing;
796
- }
797
- getKeywordGroups() {
798
- const kwdGroupNodes = [];
799
- const kwdGroupsModels = [
800
- ...this.modelMap.values(),
801
- ].filter((model) => model.objectType === json_schema_1.ObjectTypes.KeywordGroup);
802
- if (kwdGroupsModels.length > 0) {
803
- for (const kwdGroupModel of kwdGroupsModels) {
804
- const keywords = this.getKeywords(kwdGroupModel._id);
805
- const commentNodes = this.createCommentsNode(kwdGroupModel);
806
- commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
807
- const contents = [];
808
- contents.push(...keywords);
809
- const kwdGroupNode = schema_1.schema.nodes.keywords_group.create({
810
- id: kwdGroupModel._id,
811
- type: kwdGroupModel.type,
812
- comments: commentNodes.map((c) => c.attrs.id),
813
- }, contents);
814
- kwdGroupNodes.push(kwdGroupNode);
815
- }
787
+ throw new errors_1.MissingElement(id);
816
788
  }
817
- return kwdGroupNodes;
818
789
  }
819
790
  }
820
791
  exports.Decoder = Decoder;