@manuscripts/transform 1.5.7 → 1.5.8-LEAN-3030-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +14 -12
- 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 +129 -165
- 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/labels.js +3 -17
- 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 +31 -31
- 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 +12 -10
- 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 +129 -164
- 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/labels.js +3 -17
- 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 +29 -29
- 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 +23 -0
- package/dist/types/lib/utils.d.ts +3 -2
- 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 +5 -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 +4 -3
- 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,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.
|
|
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,70 @@ 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
|
|
67
|
-
exports.
|
|
68
|
-
const
|
|
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;
|
|
77
74
|
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
|
-
]);
|
|
75
|
+
createTitleNode() {
|
|
76
|
+
const titles = getTitles(this.modelMap) || (0, builders_1.buildTitles)();
|
|
77
|
+
return this.decode(titles);
|
|
88
78
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
this.createContributorSectionNode(rootSectionNodes);
|
|
95
|
-
}
|
|
79
|
+
createAffiliationsNode() {
|
|
80
|
+
const affiliations = getAffiliations(this.modelMap)
|
|
81
|
+
.map((a) => this.decode(a))
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
return schema_1.schema.nodes.affiliations.createAndFill({}, affiliations);
|
|
96
84
|
}
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
.map((
|
|
85
|
+
createContributorsNode() {
|
|
86
|
+
const contributors = getContributors(this.modelMap)
|
|
87
|
+
.map((c) => this.decode(c))
|
|
100
88
|
.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
|
-
}
|
|
89
|
+
return schema_1.schema.nodes.contributors.createAndFill({}, contributors);
|
|
107
90
|
}
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
.map((
|
|
91
|
+
createKeywordsNode() {
|
|
92
|
+
const elements = getKeywordElements(this.modelMap)
|
|
93
|
+
.map((e) => this.decode(e))
|
|
111
94
|
.filter(Boolean);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
rootSectionNodes.unshift(node);
|
|
117
|
-
}
|
|
95
|
+
return schema_1.schema.nodes.keywords.createAndFill({}, [
|
|
96
|
+
schema_1.schema.nodes.section_title.create({}, schema_1.schema.text('Keywords')),
|
|
97
|
+
...elements,
|
|
98
|
+
]);
|
|
118
99
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
100
|
+
createCommentsNode() {
|
|
101
|
+
return schema_1.schema.nodes.comments.createAndFill({}, [
|
|
102
|
+
...this.comments.values(),
|
|
103
|
+
]);
|
|
123
104
|
}
|
|
124
|
-
|
|
125
|
-
let
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
105
|
+
createContentSections() {
|
|
106
|
+
let sections = getSections(this.modelMap);
|
|
107
|
+
sections = this.addGeneratedLabels(sections);
|
|
108
|
+
const groups = {
|
|
109
|
+
abstracts: [],
|
|
110
|
+
body: [],
|
|
111
|
+
backmatter: [],
|
|
112
|
+
};
|
|
113
|
+
for (const section of sections) {
|
|
114
|
+
const category = section.category;
|
|
115
|
+
const group = category
|
|
116
|
+
? (0, section_category_1.getSectionGroupType)(category)
|
|
117
|
+
: section_group_type_1.bodyType;
|
|
118
|
+
groups[group._id].push(this.decode(section));
|
|
135
119
|
}
|
|
136
|
-
|
|
120
|
+
const abstracts = schema_1.schema.nodes.abstracts.createAndFill({}, groups[section_group_type_1.abstractsType._id]);
|
|
121
|
+
const body = schema_1.schema.nodes.body.createAndFill({}, groups[section_group_type_1.bodyType._id]);
|
|
122
|
+
const backmatter = schema_1.schema.nodes.backmatter.createAndFill({}, groups[section_group_type_1.backmatterType._id]);
|
|
123
|
+
return {
|
|
124
|
+
abstracts,
|
|
125
|
+
body,
|
|
126
|
+
backmatter,
|
|
127
|
+
};
|
|
137
128
|
}
|
|
138
|
-
|
|
129
|
+
createCommentNodes(model) {
|
|
139
130
|
const comments = [];
|
|
140
131
|
for (const comment of this.getComments(model)) {
|
|
141
132
|
comments.push(this.decode(comment));
|
|
@@ -180,8 +171,8 @@ class Decoder {
|
|
|
180
171
|
},
|
|
181
172
|
[json_schema_1.ObjectTypes.BibliographyItem]: (data) => {
|
|
182
173
|
const model = data;
|
|
183
|
-
const
|
|
184
|
-
|
|
174
|
+
const comments = this.createCommentNodes(model);
|
|
175
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
185
176
|
return schema_1.schema.nodes.bibliography_item.create({
|
|
186
177
|
id: model._id,
|
|
187
178
|
type: model.type,
|
|
@@ -195,7 +186,7 @@ class Decoder {
|
|
|
195
186
|
page: model.page,
|
|
196
187
|
title: model.title,
|
|
197
188
|
literal: model.literal,
|
|
198
|
-
comments:
|
|
189
|
+
comments: comments.map((c) => c.attrs.id),
|
|
199
190
|
});
|
|
200
191
|
},
|
|
201
192
|
[object_types_1.ExtraObjectTypes.PlaceholderElement]: (data) => {
|
|
@@ -206,14 +197,14 @@ class Decoder {
|
|
|
206
197
|
},
|
|
207
198
|
[json_schema_1.ObjectTypes.Figure]: (data) => {
|
|
208
199
|
const model = data;
|
|
209
|
-
const
|
|
210
|
-
|
|
200
|
+
const comments = this.createCommentNodes(model);
|
|
201
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
211
202
|
return schema_1.schema.nodes.figure.create({
|
|
212
203
|
id: model._id,
|
|
213
204
|
contentType: model.contentType,
|
|
214
205
|
src: model.src,
|
|
215
206
|
position: model.position,
|
|
216
|
-
comments:
|
|
207
|
+
comments: comments.map((c) => c.attrs.id),
|
|
217
208
|
});
|
|
218
209
|
},
|
|
219
210
|
[json_schema_1.ObjectTypes.FigureElement]: (data) => {
|
|
@@ -242,8 +233,8 @@ class Decoder {
|
|
|
242
233
|
figures.push(schema_1.schema.nodes.figure.createAndFill());
|
|
243
234
|
}
|
|
244
235
|
const figcaption = this.getFigcaption(model);
|
|
245
|
-
const
|
|
246
|
-
|
|
236
|
+
const comments = this.createCommentNodes(model);
|
|
237
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
247
238
|
const content = [...paragraphs, ...figures, figcaption];
|
|
248
239
|
const listing = this.extractListing(model);
|
|
249
240
|
if (listing) {
|
|
@@ -264,7 +255,7 @@ class Decoder {
|
|
|
264
255
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
265
256
|
attribution: model.attribution,
|
|
266
257
|
alternatives: model.alternatives,
|
|
267
|
-
comments:
|
|
258
|
+
comments: comments.map((c) => c.attrs.id),
|
|
268
259
|
}, content);
|
|
269
260
|
},
|
|
270
261
|
[json_schema_1.ObjectTypes.Equation]: (data) => {
|
|
@@ -307,13 +298,13 @@ class Decoder {
|
|
|
307
298
|
if (isFootnote(model) &&
|
|
308
299
|
model.kind === collateByKind &&
|
|
309
300
|
model.containingObject === foonotesElementModel._id) {
|
|
310
|
-
const
|
|
311
|
-
|
|
301
|
+
const comments = this.createCommentNodes(model);
|
|
302
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
312
303
|
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
313
304
|
topNode: schema_1.schema.nodes.footnote.create({
|
|
314
305
|
id: model._id,
|
|
315
306
|
kind: model.kind,
|
|
316
|
-
comments:
|
|
307
|
+
comments: comments.map((c) => c.attrs.id),
|
|
317
308
|
}),
|
|
318
309
|
});
|
|
319
310
|
footnotesOfKind.push(footnote);
|
|
@@ -327,36 +318,51 @@ class Decoder {
|
|
|
327
318
|
},
|
|
328
319
|
[json_schema_1.ObjectTypes.Footnote]: (data) => {
|
|
329
320
|
const footnoteModel = data;
|
|
330
|
-
const
|
|
331
|
-
|
|
321
|
+
const comments = this.createCommentNodes(footnoteModel);
|
|
322
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
332
323
|
return this.parseContents(footnoteModel.contents || '<div></div>', undefined, this.getComments(footnoteModel), {
|
|
333
324
|
topNode: schema_1.schema.nodes.footnote.create({
|
|
334
325
|
id: footnoteModel._id,
|
|
335
326
|
kind: footnoteModel.kind,
|
|
336
|
-
comments:
|
|
327
|
+
comments: comments.map((c) => c.attrs.id),
|
|
337
328
|
}),
|
|
338
329
|
});
|
|
339
330
|
},
|
|
340
331
|
[json_schema_1.ObjectTypes.KeywordsElement]: (data) => {
|
|
341
332
|
const model = data;
|
|
342
|
-
const keywordGroups = this.
|
|
333
|
+
const keywordGroups = getKeywordGroups(this.modelMap).map((k) => this.decode(k));
|
|
343
334
|
return schema_1.schema.nodes.keywords_element.create({
|
|
344
335
|
id: model._id,
|
|
345
336
|
paragraphStyle: model.paragraphStyle,
|
|
346
337
|
}, keywordGroups);
|
|
347
338
|
},
|
|
339
|
+
[json_schema_1.ObjectTypes.KeywordGroup]: (data) => {
|
|
340
|
+
const keywordGroup = data;
|
|
341
|
+
const keywords = getKeywords(this.modelMap)
|
|
342
|
+
.filter((k) => k.containedGroup === keywordGroup._id)
|
|
343
|
+
.map((k) => this.decode(k));
|
|
344
|
+
const comments = this.createCommentNodes(keywordGroup);
|
|
345
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
346
|
+
return schema_1.schema.nodes.keyword_group.create({
|
|
347
|
+
id: keywordGroup._id,
|
|
348
|
+
type: keywordGroup.type,
|
|
349
|
+
comments: comments.map((c) => c.attrs.id),
|
|
350
|
+
}, keywords);
|
|
351
|
+
},
|
|
348
352
|
[json_schema_1.ObjectTypes.Keyword]: (data) => {
|
|
349
|
-
const
|
|
353
|
+
const keyword = data;
|
|
354
|
+
const comments = this.createCommentNodes(keyword);
|
|
355
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
350
356
|
return schema_1.schema.nodes.keyword.create({
|
|
351
|
-
id:
|
|
352
|
-
contents:
|
|
353
|
-
comments:
|
|
354
|
-
}, schema_1.schema.text(
|
|
357
|
+
id: keyword._id,
|
|
358
|
+
contents: keyword.name,
|
|
359
|
+
comments: comments.map((c) => c.attrs.id),
|
|
360
|
+
}, schema_1.schema.text(keyword.name));
|
|
355
361
|
},
|
|
356
362
|
[json_schema_1.ObjectTypes.ListElement]: (data) => {
|
|
357
363
|
const model = data;
|
|
358
|
-
const
|
|
359
|
-
|
|
364
|
+
const comments = this.createCommentNodes(model);
|
|
365
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
360
366
|
switch (model.elementType) {
|
|
361
367
|
case 'ol':
|
|
362
368
|
return this.parseContents(model.contents || '<ol></ol>', undefined, this.getComments(model), {
|
|
@@ -364,7 +370,7 @@ class Decoder {
|
|
|
364
370
|
id: model._id,
|
|
365
371
|
listStyleType: model.listStyleType,
|
|
366
372
|
paragraphStyle: model.paragraphStyle,
|
|
367
|
-
comments:
|
|
373
|
+
comments: comments.map((c) => c.attrs.id),
|
|
368
374
|
}),
|
|
369
375
|
});
|
|
370
376
|
case 'ul':
|
|
@@ -380,14 +386,14 @@ class Decoder {
|
|
|
380
386
|
},
|
|
381
387
|
[json_schema_1.ObjectTypes.Listing]: (data) => {
|
|
382
388
|
const model = data;
|
|
383
|
-
const
|
|
384
|
-
|
|
389
|
+
const comments = this.createCommentNodes(model);
|
|
390
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
385
391
|
return schema_1.schema.nodes.listing.createChecked({
|
|
386
392
|
id: model._id,
|
|
387
393
|
contents: model.contents,
|
|
388
394
|
language: model.language,
|
|
389
395
|
languageKey: model.languageKey,
|
|
390
|
-
comments:
|
|
396
|
+
comments: comments.map((c) => c.attrs.id),
|
|
391
397
|
});
|
|
392
398
|
},
|
|
393
399
|
[json_schema_1.ObjectTypes.ListingElement]: (data) => {
|
|
@@ -407,13 +413,13 @@ class Decoder {
|
|
|
407
413
|
throw new errors_1.MissingElement(model.containedObjectID);
|
|
408
414
|
}
|
|
409
415
|
const figcaption = this.getFigcaption(model);
|
|
410
|
-
const
|
|
411
|
-
|
|
416
|
+
const comments = this.createCommentNodes(model);
|
|
417
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
412
418
|
return schema_1.schema.nodes.listing_element.createChecked({
|
|
413
419
|
id: model._id,
|
|
414
420
|
suppressCaption: model.suppressCaption,
|
|
415
421
|
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
416
|
-
comments:
|
|
422
|
+
comments: comments.map((c) => c.attrs.id),
|
|
417
423
|
}, [listing, figcaption]);
|
|
418
424
|
},
|
|
419
425
|
[json_schema_1.ObjectTypes.MissingFigure]: (data) => {
|
|
@@ -425,14 +431,14 @@ class Decoder {
|
|
|
425
431
|
},
|
|
426
432
|
[json_schema_1.ObjectTypes.ParagraphElement]: (data) => {
|
|
427
433
|
const model = data;
|
|
428
|
-
const
|
|
429
|
-
|
|
434
|
+
const comments = this.createCommentNodes(model);
|
|
435
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
430
436
|
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
431
437
|
topNode: schema_1.schema.nodes.paragraph.create({
|
|
432
438
|
id: model._id,
|
|
433
439
|
paragraphStyle: model.paragraphStyle,
|
|
434
440
|
placeholder: model.placeholderInnerHTML,
|
|
435
|
-
comments:
|
|
441
|
+
comments: comments.map((c) => c.attrs.id),
|
|
436
442
|
}),
|
|
437
443
|
});
|
|
438
444
|
},
|
|
@@ -473,9 +479,6 @@ class Decoder {
|
|
|
473
479
|
for (const id of model.elementIDs) {
|
|
474
480
|
const element = this.getModel(id);
|
|
475
481
|
if (element) {
|
|
476
|
-
if (isKeywordsSection(model) && isParagraphElement(element)) {
|
|
477
|
-
continue;
|
|
478
|
-
}
|
|
479
482
|
elements.push(element);
|
|
480
483
|
}
|
|
481
484
|
else if (this.allowMissingElements) {
|
|
@@ -494,9 +497,7 @@ class Decoder {
|
|
|
494
497
|
}
|
|
495
498
|
}
|
|
496
499
|
}
|
|
497
|
-
const elementNodes = elements
|
|
498
|
-
.map(this.decode)
|
|
499
|
-
.filter(exports.isManuscriptNode);
|
|
500
|
+
const elementNodes = elements.map((e) => this.decode(e));
|
|
500
501
|
const sectionTitle = 'section_title';
|
|
501
502
|
const sectionTitleNode = model.title
|
|
502
503
|
? this.parseContents(model.title, 'h1', this.getComments(model), {
|
|
@@ -514,26 +515,20 @@ class Decoder {
|
|
|
514
515
|
.map(this.creators[json_schema_1.ObjectTypes.Section]);
|
|
515
516
|
const sectionCategory = model.category || (0, section_category_1.guessSectionCategory)(elements);
|
|
516
517
|
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
|
-
}
|
|
518
|
+
const comments = this.createCommentNodes(model);
|
|
519
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
520
|
+
const content = (sectionLabelNode
|
|
521
|
+
? [sectionLabelNode, sectionTitleNode]
|
|
522
|
+
: [sectionTitleNode])
|
|
523
|
+
.concat(elementNodes)
|
|
524
|
+
.concat(nestedSections);
|
|
530
525
|
const sectionNode = sectionNodeType.createAndFill({
|
|
531
526
|
id: model._id,
|
|
532
527
|
category: sectionCategory,
|
|
533
528
|
titleSuppressed: model.titleSuppressed,
|
|
534
529
|
pageBreakStyle: model.pageBreakStyle,
|
|
535
530
|
generatedLabel: model.generatedLabel,
|
|
536
|
-
comments:
|
|
531
|
+
comments: comments.map((c) => c.attrs.id),
|
|
537
532
|
}, content);
|
|
538
533
|
if (!sectionNode) {
|
|
539
534
|
console.error(model);
|
|
@@ -543,12 +538,12 @@ class Decoder {
|
|
|
543
538
|
},
|
|
544
539
|
[json_schema_1.ObjectTypes.Table]: (data) => {
|
|
545
540
|
const model = data;
|
|
546
|
-
const
|
|
547
|
-
|
|
541
|
+
const comments = this.createCommentNodes(model);
|
|
542
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
548
543
|
return this.parseContents(model.contents, undefined, this.getComments(model), {
|
|
549
544
|
topNode: schema_1.schema.nodes.table.create({
|
|
550
545
|
id: model._id,
|
|
551
|
-
comments:
|
|
546
|
+
comments: comments.map((c) => c.attrs.id),
|
|
552
547
|
}),
|
|
553
548
|
});
|
|
554
549
|
},
|
|
@@ -557,8 +552,8 @@ class Decoder {
|
|
|
557
552
|
const table = this.createTable(model);
|
|
558
553
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
559
554
|
const figcaption = this.getFigcaption(model);
|
|
560
|
-
const
|
|
561
|
-
|
|
555
|
+
const comments = this.createCommentNodes(model);
|
|
556
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
562
557
|
const content = tableElementFooter
|
|
563
558
|
? [table, figcaption, tableElementFooter]
|
|
564
559
|
: [table, figcaption];
|
|
@@ -579,7 +574,7 @@ class Decoder {
|
|
|
579
574
|
suppressHeader: model.suppressHeader,
|
|
580
575
|
tableStyle: model.tableStyle,
|
|
581
576
|
paragraphStyle: model.paragraphStyle,
|
|
582
|
-
comments:
|
|
577
|
+
comments: comments.map((c) => c.attrs.id),
|
|
583
578
|
}, content);
|
|
584
579
|
},
|
|
585
580
|
[json_schema_1.ObjectTypes.TOCElement]: (data) => {
|
|
@@ -645,13 +640,21 @@ class Decoder {
|
|
|
645
640
|
};
|
|
646
641
|
this.getModel = (id) => this.modelMap.get(id);
|
|
647
642
|
this.createArticleNode = (manuscriptID) => {
|
|
648
|
-
const
|
|
649
|
-
const
|
|
650
|
-
const
|
|
643
|
+
const title = this.createTitleNode();
|
|
644
|
+
const contributors = this.createContributorsNode();
|
|
645
|
+
const affiliations = this.createAffiliationsNode();
|
|
646
|
+
const keywords = this.createKeywordsNode();
|
|
647
|
+
const { abstracts, body, backmatter } = this.createContentSections();
|
|
648
|
+
const comments = this.createCommentsNode();
|
|
651
649
|
const contents = [
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
650
|
+
title,
|
|
651
|
+
contributors,
|
|
652
|
+
affiliations,
|
|
653
|
+
keywords,
|
|
654
|
+
abstracts,
|
|
655
|
+
body,
|
|
656
|
+
backmatter,
|
|
657
|
+
comments,
|
|
655
658
|
];
|
|
656
659
|
return schema_1.schema.nodes.manuscript.create({
|
|
657
660
|
id: manuscriptID || this.getManuscriptID(),
|
|
@@ -693,23 +696,6 @@ class Decoder {
|
|
|
693
696
|
}
|
|
694
697
|
return parser.parse(template.content.firstElementChild, options);
|
|
695
698
|
};
|
|
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
699
|
this.getManuscriptID = () => {
|
|
714
700
|
for (const item of this.modelMap.values()) {
|
|
715
701
|
if ((0, object_types_1.isManuscript)(item)) {
|
|
@@ -794,27 +780,5 @@ class Decoder {
|
|
|
794
780
|
}
|
|
795
781
|
return listing;
|
|
796
782
|
}
|
|
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
783
|
}
|
|
820
784
|
exports.Decoder = Decoder;
|
|
@@ -25,6 +25,7 @@ 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");
|
|
28
29
|
const node_types_1 = require("./node-types");
|
|
29
30
|
const section_category_1 = require("./section-category");
|
|
30
31
|
const serializer = prosemirror_model_1.DOMSerializer.fromSchema(schema_1.schema);
|
|
@@ -428,34 +429,9 @@ const encoders = {
|
|
|
428
429
|
elementType: 'div',
|
|
429
430
|
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
430
431
|
}),
|
|
431
|
-
|
|
432
|
+
keyword_group: (node) => ({
|
|
432
433
|
type: node.attrs.type,
|
|
433
434
|
}),
|
|
434
|
-
keywords_section: (node, parent, path, priority) => ({
|
|
435
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
436
|
-
priority: priority.value++,
|
|
437
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
438
|
-
path: path.concat([node.attrs.id]),
|
|
439
|
-
elementIDs: childElements(node)
|
|
440
|
-
.map((childNode) => childNode.attrs.id)
|
|
441
|
-
.filter((id) => id),
|
|
442
|
-
}),
|
|
443
|
-
affiliations_section: (node, parent, path, priority) => ({
|
|
444
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
445
|
-
priority: priority.value++,
|
|
446
|
-
path: path.concat([node.attrs.id]),
|
|
447
|
-
elementIDs: childElements(node)
|
|
448
|
-
.map((childNode) => childNode.attrs.id)
|
|
449
|
-
.filter((id) => id),
|
|
450
|
-
}),
|
|
451
|
-
contributors_section: (node, parent, path, priority) => ({
|
|
452
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
453
|
-
priority: priority.value++,
|
|
454
|
-
path: path.concat([node.attrs.id]),
|
|
455
|
-
elementIDs: childElements(node)
|
|
456
|
-
.map((childNode) => childNode.attrs.id)
|
|
457
|
-
.filter((id) => id),
|
|
458
|
-
}),
|
|
459
435
|
missing_figure: (node) => ({
|
|
460
436
|
position: node.attrs.position || undefined,
|
|
461
437
|
}),
|
|
@@ -577,28 +553,48 @@ const modelFromNode = (node, parent, path, priority) => {
|
|
|
577
553
|
return { model, comments };
|
|
578
554
|
};
|
|
579
555
|
exports.modelFromNode = modelFromNode;
|
|
580
|
-
const
|
|
556
|
+
const containerTypes = [
|
|
557
|
+
schema_1.schema.nodes.affiliations,
|
|
558
|
+
schema_1.schema.nodes.contributors,
|
|
559
|
+
schema_1.schema.nodes.affiliations,
|
|
560
|
+
schema_1.schema.nodes.keywords,
|
|
561
|
+
schema_1.schema.nodes.abstracts,
|
|
562
|
+
schema_1.schema.nodes.body,
|
|
563
|
+
schema_1.schema.nodes.backmatter,
|
|
564
|
+
schema_1.schema.nodes.comments,
|
|
565
|
+
];
|
|
566
|
+
const encode = (node, preserveWithRepeatedID = false) => {
|
|
581
567
|
const models = new Map();
|
|
582
568
|
const priority = {
|
|
583
569
|
value: 1,
|
|
584
570
|
};
|
|
585
571
|
const placeholders = ['placeholder', 'placeholder_element'];
|
|
586
|
-
const
|
|
572
|
+
const processNode = (path, parent) => (child) => {
|
|
573
|
+
if (containerTypes.includes(child.type)) {
|
|
574
|
+
child.forEach(processNode([], child));
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
587
577
|
if (!child.attrs.id) {
|
|
588
578
|
return;
|
|
589
579
|
}
|
|
590
580
|
if ((0, schema_1.isHighlightMarkerNode)(child)) {
|
|
591
581
|
return;
|
|
592
582
|
}
|
|
593
|
-
if (child.type
|
|
583
|
+
if (placeholders.includes(child.type.name)) {
|
|
594
584
|
return;
|
|
595
585
|
}
|
|
596
|
-
if (
|
|
586
|
+
if (parent.type === schema_1.schema.nodes.paragraph) {
|
|
597
587
|
return;
|
|
598
588
|
}
|
|
599
589
|
const { model, comments } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
600
|
-
|
|
601
|
-
|
|
590
|
+
const existingModel = models.get(model._id);
|
|
591
|
+
if (existingModel) {
|
|
592
|
+
if (preserveWithRepeatedID && !(0, utils_1.modelsEqual)(model, existingModel)) {
|
|
593
|
+
model._id = (0, id_1.generateID)(model.objectType);
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
597
|
+
}
|
|
602
598
|
}
|
|
603
599
|
comments.forEach((comment) => {
|
|
604
600
|
const proseMirrorComment = models.get(comment._id);
|
|
@@ -609,23 +605,36 @@ const encode = (node) => {
|
|
|
609
605
|
}
|
|
610
606
|
});
|
|
611
607
|
models.set(model._id, model);
|
|
612
|
-
child.forEach(
|
|
608
|
+
child.forEach(processNode(path.concat(child.attrs.id), child));
|
|
613
609
|
};
|
|
614
|
-
node.forEach((
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
610
|
+
node.forEach(processNode([], node));
|
|
611
|
+
if ((0, schema_1.isManuscriptNode)(node)) {
|
|
612
|
+
builders_1.auxiliaryObjectTypes.forEach((t) => {
|
|
613
|
+
const order = generateElementOrder(node, t);
|
|
614
|
+
if (order) {
|
|
615
|
+
models.set(order._id, order);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
620
619
|
return models;
|
|
621
620
|
};
|
|
622
621
|
exports.encode = encode;
|
|
623
|
-
const
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
models.set(model._id, model);
|
|
622
|
+
const generateElementOrder = (node, nodeType) => {
|
|
623
|
+
const ids = [];
|
|
624
|
+
node.descendants((n) => {
|
|
625
|
+
if (n.type === nodeType) {
|
|
626
|
+
ids.push(n.attrs.id);
|
|
629
627
|
}
|
|
628
|
+
return true;
|
|
630
629
|
});
|
|
630
|
+
if (!ids.length) {
|
|
631
|
+
return undefined;
|
|
632
|
+
}
|
|
633
|
+
const type = node_types_1.nodeTypesMap.get(nodeType);
|
|
634
|
+
if (!type) {
|
|
635
|
+
return undefined;
|
|
636
|
+
}
|
|
637
|
+
const order = (0, builders_1.buildElementsOrder)(type);
|
|
638
|
+
order.elements = ids;
|
|
639
|
+
return order;
|
|
631
640
|
};
|