@manuscripts/transform 1.5.7 → 1.5.8-LEAN-3030
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.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/jats/importer/index.js +1 -3
- package/dist/cjs/jats/importer/jats-body-dom-parser.js +23 -227
- package/dist/cjs/jats/importer/jats-body-transformations.js +110 -201
- package/dist/cjs/jats/importer/jats-comments.js +100 -98
- package/dist/cjs/jats/importer/jats-front-parser.js +87 -81
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +51 -39
- package/dist/cjs/jats/importer/jats-parser-utils.js +17 -56
- package/dist/cjs/jats/importer/jats-reference-parser.js +24 -79
- package/dist/cjs/jats/importer/jats-references.js +34 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +67 -173
- package/dist/cjs/jats/index.js +1 -3
- package/dist/cjs/jats/jats-exporter.js +33 -54
- package/dist/cjs/lib/section-group-type.js +30 -0
- package/dist/cjs/lib/utils.js +23 -1
- package/dist/cjs/schema/index.js +20 -17
- package/dist/cjs/schema/nodes/abstracts.js +27 -0
- package/dist/cjs/schema/nodes/affiliations.js +27 -0
- package/dist/cjs/schema/nodes/backmatter.js +27 -0
- package/dist/cjs/schema/nodes/body.js +27 -0
- package/dist/cjs/schema/nodes/citation.js +10 -15
- package/dist/cjs/schema/nodes/{comment_list.js → comments.js} +4 -4
- package/dist/cjs/schema/nodes/contributors.js +27 -0
- package/dist/cjs/schema/nodes/{meta_section.js → core_section.js} +6 -5
- package/dist/cjs/schema/nodes/cross_reference.js +4 -3
- package/dist/cjs/schema/nodes/inline_footnote.js +6 -5
- package/dist/cjs/schema/nodes/keyword.js +0 -1
- package/dist/cjs/schema/nodes/{keywords_group.js → keyword_group.js} +6 -6
- package/dist/cjs/schema/nodes/{keywords_section.js → keywords.js} +7 -7
- package/dist/cjs/schema/nodes/keywords_element.js +1 -1
- package/dist/cjs/schema/nodes/manuscript.js +5 -2
- package/dist/cjs/transformer/builders.js +9 -86
- package/dist/cjs/transformer/decode.js +143 -162
- package/dist/cjs/transformer/encode.js +54 -45
- package/dist/cjs/transformer/highlight-markers.js +4 -4
- package/dist/cjs/transformer/html.js +5 -20
- package/dist/cjs/transformer/node-names.js +1 -1
- package/dist/cjs/transformer/node-title.js +1 -1
- package/dist/cjs/transformer/node-types.js +7 -6
- package/dist/cjs/transformer/object-types.js +1 -2
- package/dist/cjs/transformer/section-category.js +35 -17
- package/dist/es/index.js +1 -1
- package/dist/es/jats/importer/index.js +1 -1
- package/dist/es/jats/importer/jats-body-dom-parser.js +23 -227
- package/dist/es/jats/importer/jats-body-transformations.js +111 -202
- package/dist/es/jats/importer/jats-comments.js +97 -96
- package/dist/es/jats/importer/jats-front-parser.js +88 -82
- package/dist/es/jats/importer/jats-journal-meta-parser.js +51 -39
- package/dist/es/jats/importer/jats-parser-utils.js +16 -54
- package/dist/es/jats/importer/jats-reference-parser.js +27 -82
- package/dist/es/jats/importer/jats-references.js +30 -0
- package/dist/es/jats/importer/parse-jats-article.js +70 -174
- package/dist/es/jats/index.js +1 -1
- package/dist/es/jats/jats-exporter.js +33 -54
- package/dist/es/lib/section-group-type.js +27 -0
- package/dist/es/lib/utils.js +20 -0
- package/dist/es/schema/index.js +21 -18
- package/dist/es/schema/nodes/abstracts.js +24 -0
- package/dist/es/schema/nodes/affiliations.js +24 -0
- package/dist/es/schema/nodes/backmatter.js +24 -0
- package/dist/es/schema/nodes/body.js +24 -0
- package/dist/es/schema/nodes/citation.js +10 -15
- package/dist/es/schema/nodes/{comment_list.js → comments.js} +3 -3
- package/dist/es/schema/nodes/contributors.js +24 -0
- package/dist/es/schema/nodes/{meta_section.js → core_section.js} +5 -4
- package/dist/es/schema/nodes/cross_reference.js +4 -3
- package/dist/es/schema/nodes/inline_footnote.js +6 -5
- package/dist/es/schema/nodes/keyword.js +0 -1
- package/dist/es/schema/nodes/{keywords_group.js → keyword_group.js} +4 -4
- package/dist/es/schema/nodes/{keywords_section.js → keywords.js} +5 -5
- package/dist/es/schema/nodes/keywords_element.js +1 -1
- package/dist/es/schema/nodes/manuscript.js +3 -1
- package/dist/es/transformer/builders.js +6 -73
- package/dist/es/transformer/decode.js +143 -161
- package/dist/es/transformer/encode.js +57 -48
- package/dist/es/transformer/highlight-markers.js +1 -1
- package/dist/es/transformer/html.js +5 -20
- package/dist/es/transformer/node-names.js +1 -1
- package/dist/es/transformer/node-title.js +1 -1
- package/dist/es/transformer/node-types.js +7 -6
- package/dist/es/transformer/object-types.js +0 -1
- package/dist/es/transformer/section-category.js +33 -15
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jats/importer/index.d.ts +1 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +16 -19
- package/dist/types/jats/importer/jats-comments.d.ts +13 -9
- package/dist/types/jats/importer/jats-front-parser.d.ts +35 -12
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +4 -4
- package/dist/types/jats/importer/jats-parser-utils.d.ts +1 -6
- package/dist/types/jats/importer/jats-reference-parser.d.ts +2 -6
- package/dist/types/jats/importer/jats-references.d.ts +12 -0
- package/dist/types/jats/importer/parse-jats-article.d.ts +5 -17
- package/dist/types/jats/index.d.ts +1 -1
- package/dist/types/lib/section-group-type.d.ts +31 -0
- package/dist/types/lib/utils.d.ts +4 -1
- package/dist/types/schema/index.d.ts +4 -5
- package/dist/types/schema/nodes/{meta_section.d.ts → abstracts.d.ts} +1 -9
- package/dist/types/schema/nodes/affiliations.d.ts +17 -0
- package/dist/types/schema/nodes/backmatter.d.ts +17 -0
- package/dist/types/schema/nodes/body.d.ts +17 -0
- package/dist/types/schema/nodes/citation.d.ts +3 -5
- package/dist/types/schema/nodes/comments.d.ts +17 -0
- package/dist/types/schema/nodes/contributors.d.ts +17 -0
- package/dist/types/schema/nodes/core_section.d.ts +17 -0
- package/dist/types/schema/nodes/cross_reference.d.ts +1 -1
- package/dist/types/schema/nodes/inline_footnote.d.ts +1 -1
- package/dist/types/schema/nodes/keyword.d.ts +0 -1
- package/dist/types/schema/nodes/{contributors_element.d.ts → keyword_group.d.ts} +3 -4
- package/dist/types/schema/nodes/{comment_list.d.ts → keywords.d.ts} +3 -2
- package/dist/types/schema/nodes/manuscript.d.ts +1 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/builders.d.ts +2 -14
- package/dist/types/transformer/decode.d.ts +7 -9
- package/dist/types/transformer/encode.d.ts +1 -1
- package/dist/types/transformer/highlight-markers.d.ts +1 -0
- package/dist/types/transformer/object-types.d.ts +1 -2
- package/dist/types/transformer/section-category.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/lib/core-section-categories.js +0 -29
- package/dist/cjs/schema/nodes/affiliations_section.js +0 -36
- package/dist/cjs/schema/nodes/contributors_element.js +0 -49
- package/dist/cjs/schema/nodes/contributors_section.js +0 -36
- package/dist/es/lib/core-section-categories.js +0 -26
- package/dist/es/schema/nodes/affiliations_section.js +0 -32
- package/dist/es/schema/nodes/contributors_element.js +0 -46
- package/dist/es/schema/nodes/contributors_section.js +0 -32
- package/dist/types/lib/core-section-categories.d.ts +0 -8
- package/dist/types/schema/nodes/affiliations_section.d.ts +0 -11
- package/dist/types/schema/nodes/contributors_section.d.ts +0 -12
- package/dist/types/schema/nodes/keywords_group.d.ts +0 -26
- package/dist/types/schema/nodes/keywords_section.d.ts +0 -26
|
@@ -29,11 +29,12 @@ 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.
|
|
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 utils_1 = require("../lib/utils");
|
|
37
38
|
const schema_1 = require("../schema");
|
|
38
39
|
const builders_1 = require("./builders");
|
|
39
40
|
const highlight_markers_1 = require("./highlight-markers");
|
|
@@ -63,79 +64,86 @@ exports.sortSectionsByPriority = sortSectionsByPriority;
|
|
|
63
64
|
const getSections = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Section).sort(exports.sortSectionsByPriority);
|
|
64
65
|
const getAffiliations = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Affiliation);
|
|
65
66
|
const getContributors = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Contributor);
|
|
66
|
-
const
|
|
67
|
-
exports.
|
|
68
|
-
const
|
|
67
|
+
const getKeywordElements = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordsElement);
|
|
68
|
+
const getKeywordGroups = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordGroup);
|
|
69
|
+
const getKeywords = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Keyword);
|
|
70
|
+
const getTitles = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Titles)[0];
|
|
69
71
|
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
72
|
const hasParentSection = (id) => (section) => section.path &&
|
|
75
73
|
section.path.length > 1 &&
|
|
76
74
|
section.path[section.path.length - 2] === id;
|
|
77
75
|
class Decoder {
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
return
|
|
81
|
-
commentListNode,
|
|
82
|
-
]);
|
|
83
|
-
}
|
|
84
|
-
createCommentListNode() {
|
|
85
|
-
return schema_1.schema.nodes.comment_list.createAndFill({}, [
|
|
86
|
-
...this.comments.values(),
|
|
87
|
-
]);
|
|
76
|
+
createTitleNode() {
|
|
77
|
+
const titles = getTitles(this.modelMap) || (0, builders_1.buildTitles)();
|
|
78
|
+
return this.decode(titles);
|
|
88
79
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.createContributorSectionNode(rootSectionNodes);
|
|
95
|
-
}
|
|
80
|
+
createAffiliationsNode() {
|
|
81
|
+
const affiliations = getAffiliations(this.modelMap)
|
|
82
|
+
.map((a) => this.decode(a))
|
|
83
|
+
.filter(Boolean);
|
|
84
|
+
return schema_1.schema.nodes.affiliations.createAndFill({}, affiliations);
|
|
96
85
|
}
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
.map((
|
|
86
|
+
createContributorsNode() {
|
|
87
|
+
const contributors = getContributors(this.modelMap)
|
|
88
|
+
.map((c) => this.decode(c))
|
|
100
89
|
.filter(Boolean);
|
|
101
|
-
|
|
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
|
-
}
|
|
90
|
+
return schema_1.schema.nodes.contributors.createAndFill({}, contributors);
|
|
107
91
|
}
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
.map((
|
|
92
|
+
createKeywordsNode() {
|
|
93
|
+
const elements = getKeywordElements(this.modelMap)
|
|
94
|
+
.map((e) => this.decode(e))
|
|
111
95
|
.filter(Boolean);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
rootSectionNodes.unshift(node);
|
|
117
|
-
}
|
|
96
|
+
return schema_1.schema.nodes.keywords.createAndFill({}, [
|
|
97
|
+
schema_1.schema.nodes.section_title.create({}, schema_1.schema.text('Keywords')),
|
|
98
|
+
...elements,
|
|
99
|
+
]);
|
|
118
100
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
101
|
+
createCommentsNode() {
|
|
102
|
+
return schema_1.schema.nodes.comments.createAndFill({}, [
|
|
103
|
+
...this.comments.values(),
|
|
104
|
+
]);
|
|
123
105
|
}
|
|
124
106
|
createRootSectionNodes() {
|
|
125
|
-
let rootSections = getSections(this.modelMap)
|
|
107
|
+
let rootSections = getSections(this.modelMap)
|
|
108
|
+
.filter((section) => !section.path || section.path.length <= 1)
|
|
109
|
+
.filter((section) => section.category !== 'MPSectionCategory:contributors' &&
|
|
110
|
+
section.category !== 'MPSectionCategory:affiliations' &&
|
|
111
|
+
section.category !== 'MPSectionCategory:keywords');
|
|
126
112
|
rootSections = this.addGeneratedLabels(rootSections);
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
113
|
+
const sectionGroups = (0, utils_1.groupBy)(rootSections, (sec) => {
|
|
114
|
+
var _a;
|
|
115
|
+
return (0, section_category_1.chooseCoreSectionBySection)((_a = sec.category) !== null && _a !== void 0 ? _a : '');
|
|
116
|
+
});
|
|
117
|
+
this.ensureCoreSectionsExist(sectionGroups);
|
|
118
|
+
const absSectionNode = sectionGroups['MPSectionCategory:abstracts'].map((e) => this.decode(e));
|
|
119
|
+
const bodySectionNodes = sectionGroups['MPSectionCategory:body'].map((e) => this.decode(e));
|
|
120
|
+
const backmatterSectionNodes = sectionGroups['MPSectionCategory:backmatter'].map(e => this.decode(e));
|
|
121
|
+
const abstractCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.abstracts, absSectionNode);
|
|
122
|
+
const bodyCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.body, bodySectionNodes);
|
|
123
|
+
const backmatterCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.backmatter, backmatterSectionNodes);
|
|
124
|
+
return {
|
|
125
|
+
abstracts: abstractCoreSectionNodes,
|
|
126
|
+
body: bodyCoreSectionNodes,
|
|
127
|
+
backmatter: backmatterCoreSectionNodes,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
ensureCoreSectionsExist(coreSections) {
|
|
131
|
+
if (!coreSections['MPSectionCategory:abstracts']) {
|
|
132
|
+
coreSections['MPSectionCategory:abstracts'] = [];
|
|
133
|
+
}
|
|
134
|
+
if (!coreSections['MPSectionCategory:body']) {
|
|
135
|
+
coreSections['MPSectionCategory:body'] = [];
|
|
136
|
+
}
|
|
137
|
+
if (!coreSections['MPSectionCategory:backmatter']) {
|
|
138
|
+
coreSections['MPSectionCategory:backmatter'] = [];
|
|
135
139
|
}
|
|
136
|
-
return rootSectionNodes;
|
|
137
140
|
}
|
|
138
|
-
|
|
141
|
+
createAndFill(nodeType, content) {
|
|
142
|
+
return nodeType.createAndFill({
|
|
143
|
+
id: (0, id_1.generateNodeID)(nodeType),
|
|
144
|
+
}, content);
|
|
145
|
+
}
|
|
146
|
+
createCommentNodes(model) {
|
|
139
147
|
const comments = [];
|
|
140
148
|
for (const comment of this.getComments(model)) {
|
|
141
149
|
comments.push(this.decode(comment));
|
|
@@ -180,8 +188,8 @@ class Decoder {
|
|
|
180
188
|
},
|
|
181
189
|
[json_schema_1.ObjectTypes.BibliographyItem]: (data) => {
|
|
182
190
|
const model = data;
|
|
183
|
-
const
|
|
184
|
-
|
|
191
|
+
const comments = this.createCommentNodes(model);
|
|
192
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
185
193
|
return schema_1.schema.nodes.bibliography_item.create({
|
|
186
194
|
id: model._id,
|
|
187
195
|
type: model.type,
|
|
@@ -195,7 +203,7 @@ class Decoder {
|
|
|
195
203
|
page: model.page,
|
|
196
204
|
title: model.title,
|
|
197
205
|
literal: model.literal,
|
|
198
|
-
comments:
|
|
206
|
+
comments: comments.map((c) => c.attrs.id),
|
|
199
207
|
});
|
|
200
208
|
},
|
|
201
209
|
[object_types_1.ExtraObjectTypes.PlaceholderElement]: (data) => {
|
|
@@ -206,14 +214,14 @@ class Decoder {
|
|
|
206
214
|
},
|
|
207
215
|
[json_schema_1.ObjectTypes.Figure]: (data) => {
|
|
208
216
|
const model = data;
|
|
209
|
-
const
|
|
210
|
-
|
|
217
|
+
const comments = this.createCommentNodes(model);
|
|
218
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
211
219
|
return schema_1.schema.nodes.figure.create({
|
|
212
220
|
id: model._id,
|
|
213
221
|
contentType: model.contentType,
|
|
214
222
|
src: model.src,
|
|
215
223
|
position: model.position,
|
|
216
|
-
comments:
|
|
224
|
+
comments: comments.map((c) => c.attrs.id),
|
|
217
225
|
});
|
|
218
226
|
},
|
|
219
227
|
[json_schema_1.ObjectTypes.FigureElement]: (data) => {
|
|
@@ -242,8 +250,8 @@ class Decoder {
|
|
|
242
250
|
figures.push(schema_1.schema.nodes.figure.createAndFill());
|
|
243
251
|
}
|
|
244
252
|
const figcaption = this.getFigcaption(model);
|
|
245
|
-
const
|
|
246
|
-
|
|
253
|
+
const comments = this.createCommentNodes(model);
|
|
254
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
247
255
|
const content = [...paragraphs, ...figures, figcaption];
|
|
248
256
|
const listing = this.extractListing(model);
|
|
249
257
|
if (listing) {
|
|
@@ -264,7 +272,7 @@ class Decoder {
|
|
|
264
272
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
265
273
|
attribution: model.attribution,
|
|
266
274
|
alternatives: model.alternatives,
|
|
267
|
-
comments:
|
|
275
|
+
comments: comments.map((c) => c.attrs.id),
|
|
268
276
|
}, content);
|
|
269
277
|
},
|
|
270
278
|
[json_schema_1.ObjectTypes.Equation]: (data) => {
|
|
@@ -307,13 +315,13 @@ class Decoder {
|
|
|
307
315
|
if (isFootnote(model) &&
|
|
308
316
|
model.kind === collateByKind &&
|
|
309
317
|
model.containingObject === foonotesElementModel._id) {
|
|
310
|
-
const
|
|
311
|
-
|
|
318
|
+
const comments = this.createCommentNodes(model);
|
|
319
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
312
320
|
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
313
321
|
topNode: schema_1.schema.nodes.footnote.create({
|
|
314
322
|
id: model._id,
|
|
315
323
|
kind: model.kind,
|
|
316
|
-
comments:
|
|
324
|
+
comments: comments.map((c) => c.attrs.id),
|
|
317
325
|
}),
|
|
318
326
|
});
|
|
319
327
|
footnotesOfKind.push(footnote);
|
|
@@ -327,36 +335,51 @@ class Decoder {
|
|
|
327
335
|
},
|
|
328
336
|
[json_schema_1.ObjectTypes.Footnote]: (data) => {
|
|
329
337
|
const footnoteModel = data;
|
|
330
|
-
const
|
|
331
|
-
|
|
338
|
+
const comments = this.createCommentNodes(footnoteModel);
|
|
339
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
332
340
|
return this.parseContents(footnoteModel.contents || '<div></div>', undefined, this.getComments(footnoteModel), {
|
|
333
341
|
topNode: schema_1.schema.nodes.footnote.create({
|
|
334
342
|
id: footnoteModel._id,
|
|
335
343
|
kind: footnoteModel.kind,
|
|
336
|
-
comments:
|
|
344
|
+
comments: comments.map((c) => c.attrs.id),
|
|
337
345
|
}),
|
|
338
346
|
});
|
|
339
347
|
},
|
|
340
348
|
[json_schema_1.ObjectTypes.KeywordsElement]: (data) => {
|
|
341
349
|
const model = data;
|
|
342
|
-
const keywordGroups = this.
|
|
350
|
+
const keywordGroups = getKeywordGroups(this.modelMap).map((k) => this.decode(k));
|
|
343
351
|
return schema_1.schema.nodes.keywords_element.create({
|
|
344
352
|
id: model._id,
|
|
345
353
|
paragraphStyle: model.paragraphStyle,
|
|
346
354
|
}, keywordGroups);
|
|
347
355
|
},
|
|
356
|
+
[json_schema_1.ObjectTypes.KeywordGroup]: (data) => {
|
|
357
|
+
const keywordGroup = data;
|
|
358
|
+
const keywords = getKeywords(this.modelMap)
|
|
359
|
+
.filter((k) => k.containedGroup === keywordGroup._id)
|
|
360
|
+
.map((k) => this.decode(k));
|
|
361
|
+
const comments = this.createCommentNodes(keywordGroup);
|
|
362
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
363
|
+
return schema_1.schema.nodes.keyword_group.create({
|
|
364
|
+
id: keywordGroup._id,
|
|
365
|
+
type: keywordGroup.type,
|
|
366
|
+
comments: comments.map((c) => c.attrs.id),
|
|
367
|
+
}, keywords);
|
|
368
|
+
},
|
|
348
369
|
[json_schema_1.ObjectTypes.Keyword]: (data) => {
|
|
349
|
-
const
|
|
370
|
+
const keyword = data;
|
|
371
|
+
const comments = this.createCommentNodes(keyword);
|
|
372
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
350
373
|
return schema_1.schema.nodes.keyword.create({
|
|
351
|
-
id:
|
|
352
|
-
contents:
|
|
353
|
-
comments:
|
|
354
|
-
}, schema_1.schema.text(
|
|
374
|
+
id: keyword._id,
|
|
375
|
+
contents: keyword.name,
|
|
376
|
+
comments: comments.map((c) => c.attrs.id),
|
|
377
|
+
}, schema_1.schema.text(keyword.name));
|
|
355
378
|
},
|
|
356
379
|
[json_schema_1.ObjectTypes.ListElement]: (data) => {
|
|
357
380
|
const model = data;
|
|
358
|
-
const
|
|
359
|
-
|
|
381
|
+
const comments = this.createCommentNodes(model);
|
|
382
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
360
383
|
switch (model.elementType) {
|
|
361
384
|
case 'ol':
|
|
362
385
|
return this.parseContents(model.contents || '<ol></ol>', undefined, this.getComments(model), {
|
|
@@ -364,7 +387,7 @@ class Decoder {
|
|
|
364
387
|
id: model._id,
|
|
365
388
|
listStyleType: model.listStyleType,
|
|
366
389
|
paragraphStyle: model.paragraphStyle,
|
|
367
|
-
comments:
|
|
390
|
+
comments: comments.map((c) => c.attrs.id),
|
|
368
391
|
}),
|
|
369
392
|
});
|
|
370
393
|
case 'ul':
|
|
@@ -380,14 +403,14 @@ class Decoder {
|
|
|
380
403
|
},
|
|
381
404
|
[json_schema_1.ObjectTypes.Listing]: (data) => {
|
|
382
405
|
const model = data;
|
|
383
|
-
const
|
|
384
|
-
|
|
406
|
+
const comments = this.createCommentNodes(model);
|
|
407
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
385
408
|
return schema_1.schema.nodes.listing.createChecked({
|
|
386
409
|
id: model._id,
|
|
387
410
|
contents: model.contents,
|
|
388
411
|
language: model.language,
|
|
389
412
|
languageKey: model.languageKey,
|
|
390
|
-
comments:
|
|
413
|
+
comments: comments.map((c) => c.attrs.id),
|
|
391
414
|
});
|
|
392
415
|
},
|
|
393
416
|
[json_schema_1.ObjectTypes.ListingElement]: (data) => {
|
|
@@ -407,13 +430,13 @@ class Decoder {
|
|
|
407
430
|
throw new errors_1.MissingElement(model.containedObjectID);
|
|
408
431
|
}
|
|
409
432
|
const figcaption = this.getFigcaption(model);
|
|
410
|
-
const
|
|
411
|
-
|
|
433
|
+
const comments = this.createCommentNodes(model);
|
|
434
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
412
435
|
return schema_1.schema.nodes.listing_element.createChecked({
|
|
413
436
|
id: model._id,
|
|
414
437
|
suppressCaption: model.suppressCaption,
|
|
415
438
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
416
|
-
comments:
|
|
439
|
+
comments: comments.map((c) => c.attrs.id),
|
|
417
440
|
}, [listing, figcaption]);
|
|
418
441
|
},
|
|
419
442
|
[json_schema_1.ObjectTypes.MissingFigure]: (data) => {
|
|
@@ -425,14 +448,14 @@ class Decoder {
|
|
|
425
448
|
},
|
|
426
449
|
[json_schema_1.ObjectTypes.ParagraphElement]: (data) => {
|
|
427
450
|
const model = data;
|
|
428
|
-
const
|
|
429
|
-
|
|
451
|
+
const comments = this.createCommentNodes(model);
|
|
452
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
430
453
|
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
431
454
|
topNode: schema_1.schema.nodes.paragraph.create({
|
|
432
455
|
id: model._id,
|
|
433
456
|
paragraphStyle: model.paragraphStyle,
|
|
434
457
|
placeholder: model.placeholderInnerHTML,
|
|
435
|
-
comments:
|
|
458
|
+
comments: comments.map((c) => c.attrs.id),
|
|
436
459
|
}),
|
|
437
460
|
});
|
|
438
461
|
},
|
|
@@ -473,9 +496,6 @@ class Decoder {
|
|
|
473
496
|
for (const id of model.elementIDs) {
|
|
474
497
|
const element = this.getModel(id);
|
|
475
498
|
if (element) {
|
|
476
|
-
if (isKeywordsSection(model) && isParagraphElement(element)) {
|
|
477
|
-
continue;
|
|
478
|
-
}
|
|
479
499
|
elements.push(element);
|
|
480
500
|
}
|
|
481
501
|
else if (this.allowMissingElements) {
|
|
@@ -494,9 +514,7 @@ class Decoder {
|
|
|
494
514
|
}
|
|
495
515
|
}
|
|
496
516
|
}
|
|
497
|
-
const elementNodes = elements
|
|
498
|
-
.map(this.decode)
|
|
499
|
-
.filter(exports.isManuscriptNode);
|
|
517
|
+
const elementNodes = elements.map(e => this.decode(e));
|
|
500
518
|
const sectionTitle = 'section_title';
|
|
501
519
|
const sectionTitleNode = model.title
|
|
502
520
|
? this.parseContents(model.title, 'h1', this.getComments(model), {
|
|
@@ -514,26 +532,20 @@ class Decoder {
|
|
|
514
532
|
.map(this.creators[json_schema_1.ObjectTypes.Section]);
|
|
515
533
|
const sectionCategory = model.category || (0, section_category_1.guessSectionCategory)(elements);
|
|
516
534
|
const sectionNodeType = (0, section_category_1.chooseSectionNodeType)(sectionCategory);
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
content = (sectionLabelNode
|
|
525
|
-
? [sectionLabelNode, sectionTitleNode]
|
|
526
|
-
: [sectionTitleNode])
|
|
527
|
-
.concat(elementNodes)
|
|
528
|
-
.concat(nestedSections);
|
|
529
|
-
}
|
|
535
|
+
const comments = this.createCommentNodes(model);
|
|
536
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
537
|
+
const content = (sectionLabelNode
|
|
538
|
+
? [sectionLabelNode, sectionTitleNode]
|
|
539
|
+
: [sectionTitleNode])
|
|
540
|
+
.concat(elementNodes)
|
|
541
|
+
.concat(nestedSections);
|
|
530
542
|
const sectionNode = sectionNodeType.createAndFill({
|
|
531
543
|
id: model._id,
|
|
532
544
|
category: sectionCategory,
|
|
533
545
|
titleSuppressed: model.titleSuppressed,
|
|
534
546
|
pageBreakStyle: model.pageBreakStyle,
|
|
535
547
|
generatedLabel: model.generatedLabel,
|
|
536
|
-
comments:
|
|
548
|
+
comments: comments.map((c) => c.attrs.id),
|
|
537
549
|
}, content);
|
|
538
550
|
if (!sectionNode) {
|
|
539
551
|
console.error(model);
|
|
@@ -543,12 +555,12 @@ class Decoder {
|
|
|
543
555
|
},
|
|
544
556
|
[json_schema_1.ObjectTypes.Table]: (data) => {
|
|
545
557
|
const model = data;
|
|
546
|
-
const
|
|
547
|
-
|
|
558
|
+
const comments = this.createCommentNodes(model);
|
|
559
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
548
560
|
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
549
561
|
topNode: schema_1.schema.nodes.table.create({
|
|
550
562
|
id: model._id,
|
|
551
|
-
comments:
|
|
563
|
+
comments: comments.map((c) => c.attrs.id),
|
|
552
564
|
}),
|
|
553
565
|
});
|
|
554
566
|
},
|
|
@@ -557,8 +569,8 @@ class Decoder {
|
|
|
557
569
|
const table = this.createTable(model);
|
|
558
570
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
559
571
|
const figcaption = this.getFigcaption(model);
|
|
560
|
-
const
|
|
561
|
-
|
|
572
|
+
const comments = this.createCommentNodes(model);
|
|
573
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
562
574
|
const content = tableElementFooter
|
|
563
575
|
? [table, figcaption, tableElementFooter]
|
|
564
576
|
: [table, figcaption];
|
|
@@ -579,7 +591,7 @@ class Decoder {
|
|
|
579
591
|
suppressHeader: model.suppressHeader,
|
|
580
592
|
tableStyle: model.tableStyle,
|
|
581
593
|
paragraphStyle: model.paragraphStyle,
|
|
582
|
-
comments:
|
|
594
|
+
comments: comments.map((c) => c.attrs.id),
|
|
583
595
|
}, content);
|
|
584
596
|
},
|
|
585
597
|
[json_schema_1.ObjectTypes.TOCElement]: (data) => {
|
|
@@ -645,13 +657,21 @@ class Decoder {
|
|
|
645
657
|
};
|
|
646
658
|
this.getModel = (id) => this.modelMap.get(id);
|
|
647
659
|
this.createArticleNode = (manuscriptID) => {
|
|
648
|
-
const
|
|
649
|
-
const
|
|
650
|
-
const
|
|
660
|
+
const title = this.createTitleNode();
|
|
661
|
+
const contributors = this.createContributorsNode();
|
|
662
|
+
const affiliations = this.createAffiliationsNode();
|
|
663
|
+
const keywords = this.createKeywordsNode();
|
|
664
|
+
const { abstracts, body, backmatter } = this.createRootSectionNodes();
|
|
665
|
+
const comments = this.createCommentsNode();
|
|
651
666
|
const contents = [
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
667
|
+
title,
|
|
668
|
+
contributors,
|
|
669
|
+
affiliations,
|
|
670
|
+
keywords,
|
|
671
|
+
abstracts,
|
|
672
|
+
body,
|
|
673
|
+
backmatter,
|
|
674
|
+
comments,
|
|
655
675
|
];
|
|
656
676
|
return schema_1.schema.nodes.manuscript.create({
|
|
657
677
|
id: manuscriptID || this.getManuscriptID(),
|
|
@@ -693,23 +713,6 @@ class Decoder {
|
|
|
693
713
|
}
|
|
694
714
|
return parser.parse(template.content.firstElementChild, options);
|
|
695
715
|
};
|
|
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
716
|
this.getManuscriptID = () => {
|
|
714
717
|
for (const item of this.modelMap.values()) {
|
|
715
718
|
if ((0, object_types_1.isManuscript)(item)) {
|
|
@@ -794,27 +797,5 @@ class Decoder {
|
|
|
794
797
|
}
|
|
795
798
|
return listing;
|
|
796
799
|
}
|
|
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
|
-
}
|
|
816
|
-
}
|
|
817
|
-
return kwdGroupNodes;
|
|
818
|
-
}
|
|
819
800
|
}
|
|
820
801
|
exports.Decoder = Decoder;
|