@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.
- 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 +34 -55
- package/dist/cjs/lib/section-group-type.js +30 -0
- package/dist/cjs/lib/utils.js +1 -25
- 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 +147 -176
- package/dist/cjs/transformer/encode.js +66 -67
- package/dist/cjs/transformer/highlight-markers.js +48 -36
- package/dist/cjs/transformer/html.js +7 -23
- 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 +34 -55
- package/dist/es/lib/section-group-type.js +27 -0
- package/dist/es/lib/utils.js +0 -22
- 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 +147 -175
- package/dist/es/transformer/encode.js +70 -71
- package/dist/es/transformer/highlight-markers.js +44 -32
- package/dist/es/transformer/html.js +7 -23
- 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 +1 -4
- 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 +4 -4
- package/dist/types/transformer/highlight-markers.d.ts +7 -2
- package/dist/types/transformer/object-types.d.ts +1 -2
- package/dist/types/transformer/section-category.d.ts +4 -3
- package/package.json +1 -6
- 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,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
|
|
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;
|
|
74
|
+
const deprecatedCategories = [
|
|
75
|
+
'MPSectionCategory:contributors',
|
|
76
|
+
'MPSectionCategory:affiliations',
|
|
77
|
+
'MPSectionCategory:keywords',
|
|
78
|
+
];
|
|
77
79
|
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
|
-
]);
|
|
80
|
+
createTitleNode() {
|
|
81
|
+
const titles = getTitles(this.modelMap) || (0, builders_1.buildTitles)();
|
|
82
|
+
return this.decode(titles);
|
|
88
83
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
98
|
-
const
|
|
99
|
-
.map((
|
|
90
|
+
createContributorsNode() {
|
|
91
|
+
const contributors = getContributors(this.modelMap)
|
|
92
|
+
.map((c) => this.decode(c))
|
|
100
93
|
.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
|
-
}
|
|
94
|
+
return schema_1.schema.nodes.contributors.createAndFill({}, contributors);
|
|
107
95
|
}
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
.map((
|
|
96
|
+
createKeywordsNode() {
|
|
97
|
+
const elements = getKeywordElements(this.modelMap)
|
|
98
|
+
.map((e) => this.decode(e))
|
|
111
99
|
.filter(Boolean);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
105
|
+
createCommentsNode() {
|
|
106
|
+
return schema_1.schema.nodes.comments.createAndFill({}, [
|
|
107
|
+
...this.comments.values(),
|
|
108
|
+
]);
|
|
123
109
|
}
|
|
124
|
-
|
|
125
|
-
let
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
184
|
-
|
|
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:
|
|
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
|
|
210
|
-
|
|
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:
|
|
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
|
|
246
|
-
|
|
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:
|
|
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
|
|
311
|
-
|
|
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:
|
|
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
|
|
331
|
-
|
|
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:
|
|
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.
|
|
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
|
|
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:
|
|
352
|
-
contents:
|
|
353
|
-
comments:
|
|
354
|
-
}, schema_1.schema.text(
|
|
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
|
|
359
|
-
|
|
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:
|
|
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
|
|
384
|
-
|
|
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:
|
|
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
|
|
411
|
-
|
|
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:
|
|
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
|
|
429
|
-
|
|
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:
|
|
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
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
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:
|
|
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
|
|
547
|
-
|
|
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:
|
|
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
|
|
561
|
-
|
|
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:
|
|
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
|
|
649
|
-
const
|
|
650
|
-
const
|
|
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
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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(
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
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
|
-
|
|
788
|
-
id
|
|
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(
|
|
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;
|