@manuscripts/transform 2.3.34-LEAN-3911.2 → 2.3.35
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/__tests__/data/project-dump.json +825 -0
- package/dist/cjs/jats/importer/index.js +3 -3
- package/dist/cjs/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +9 -229
- package/dist/cjs/jats/importer/jats-body-transformations.js +0 -70
- package/dist/cjs/jats/importer/jats-comments.js +104 -27
- package/dist/cjs/jats/importer/jats-front-parser.js +321 -0
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +1 -8
- package/dist/cjs/jats/importer/jats-parser-utils.js +5 -39
- package/dist/cjs/jats/importer/jats-reference-parser.js +27 -16
- package/dist/cjs/jats/importer/jats-references.js +18 -18
- package/dist/cjs/jats/importer/parse-jats-article.js +78 -42
- package/dist/cjs/jats/index.js +3 -4
- package/dist/cjs/jats/jats-exporter.js +354 -251
- package/dist/cjs/lib/utils.js +1 -9
- package/dist/cjs/schema/nodes/inline_footnote.js +1 -0
- package/dist/cjs/transformer/__tests__/__helpers__/doc.js +37 -0
- package/dist/cjs/transformer/builders.js +219 -0
- package/dist/cjs/transformer/decode.js +874 -0
- package/dist/cjs/transformer/document-object-types.js +31 -0
- package/dist/cjs/transformer/encode.js +664 -0
- package/dist/cjs/transformer/footnote-category.js +20 -0
- package/dist/cjs/transformer/footnotes-order.js +60 -0
- package/dist/cjs/transformer/highlight-markers.js +138 -0
- package/dist/cjs/transformer/html.js +400 -0
- package/dist/cjs/transformer/id.js +6 -6
- package/dist/cjs/transformer/index.js +18 -0
- package/dist/cjs/{jats → transformer}/labels.js +3 -3
- package/dist/cjs/transformer/manuscript-dependencies.js +21 -0
- package/dist/cjs/transformer/model-map.js +26 -0
- package/dist/cjs/transformer/models.js +17 -0
- package/dist/cjs/transformer/object-types.js +57 -0
- package/dist/cjs/transformer/project-bundle.js +94 -0
- package/dist/cjs/transformer/serializer.js +23 -0
- package/dist/cjs/transformer/update-identifiers.js +93 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/__tests__/data/project-dump.json +825 -0
- package/dist/es/jats/importer/index.js +1 -2
- package/dist/es/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +10 -230
- package/dist/es/jats/importer/jats-body-transformations.js +0 -70
- package/dist/es/jats/importer/jats-comments.js +101 -26
- package/dist/es/jats/importer/jats-front-parser.js +315 -0
- package/dist/es/jats/importer/jats-journal-meta-parser.js +0 -6
- package/dist/es/jats/importer/jats-parser-utils.js +6 -40
- package/dist/es/jats/importer/jats-reference-parser.js +27 -16
- package/dist/es/jats/importer/jats-references.js +18 -18
- package/dist/es/jats/importer/parse-jats-article.js +77 -43
- package/dist/es/jats/index.js +1 -3
- package/dist/es/jats/jats-exporter.js +356 -253
- package/dist/es/lib/utils.js +0 -7
- package/dist/es/schema/nodes/inline_footnote.js +1 -0
- package/dist/es/transformer/__tests__/__helpers__/doc.js +29 -0
- package/dist/es/transformer/builders.js +186 -0
- package/dist/es/transformer/decode.js +864 -0
- package/dist/es/transformer/document-object-types.js +28 -0
- package/dist/es/transformer/encode.js +654 -0
- package/dist/{types/jats/importer/create-article-node.d.ts → es/transformer/footnote-category.js} +2 -3
- package/dist/es/transformer/footnotes-order.js +55 -0
- package/dist/es/transformer/highlight-markers.js +132 -0
- package/dist/es/transformer/html.js +393 -0
- package/dist/es/transformer/id.js +4 -5
- package/dist/es/transformer/index.js +16 -0
- package/dist/es/{jats → transformer}/labels.js +3 -3
- package/dist/es/transformer/manuscript-dependencies.js +17 -0
- package/dist/es/transformer/model-map.js +22 -0
- package/dist/es/transformer/models.js +16 -0
- package/dist/es/transformer/object-types.js +52 -0
- package/dist/es/transformer/project-bundle.js +85 -0
- package/dist/es/transformer/serializer.js +17 -0
- package/dist/es/transformer/update-identifiers.js +87 -0
- package/dist/es/version.js +1 -1
- package/dist/types/jats/importer/index.d.ts +1 -2
- package/dist/types/jats/importer/{jats-dom-parser.d.ts → jats-body-dom-parser.d.ts} +1 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +0 -5
- package/dist/types/jats/importer/jats-comments.d.ts +10 -4
- package/dist/types/jats/importer/jats-front-parser.d.ts +84 -0
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +0 -10
- package/dist/types/jats/importer/jats-references.d.ts +8 -19
- package/dist/types/jats/importer/parse-jats-article.d.ts +5 -12
- package/dist/types/jats/index.d.ts +1 -3
- package/dist/types/jats/jats-exporter.d.ts +29 -10
- package/dist/types/lib/utils.d.ts +0 -3
- package/dist/types/schema/nodes/bibliography_item.d.ts +6 -16
- package/dist/types/schema/nodes/contributor.d.ts +0 -10
- package/dist/types/schema/nodes/keyword_group.d.ts +0 -1
- package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +18 -0
- package/dist/types/transformer/builders.d.ts +61 -0
- package/dist/types/transformer/decode.d.ts +51 -0
- package/dist/types/transformer/document-object-types.d.ts +17 -0
- package/dist/types/transformer/encode.d.ts +29 -0
- package/dist/types/transformer/footnote-category.d.ts +17 -0
- package/dist/types/transformer/footnotes-order.d.ts +22 -0
- package/dist/types/transformer/highlight-markers.d.ts +31 -0
- package/dist/types/transformer/html.d.ts +36 -0
- package/dist/types/transformer/id.d.ts +3 -4
- package/dist/types/transformer/index.d.ts +16 -0
- package/dist/types/{jats → transformer}/labels.d.ts +1 -2
- package/dist/types/transformer/manuscript-dependencies.d.ts +4 -0
- package/dist/types/transformer/model-map.d.ts +19 -0
- package/dist/types/transformer/models.d.ts +48 -0
- package/dist/types/transformer/object-types.d.ts +30 -0
- package/dist/types/transformer/project-bundle.d.ts +30 -0
- package/dist/types/transformer/serializer.d.ts +19 -0
- package/dist/types/transformer/update-identifiers.d.ts +23 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -2
- package/dist/cjs/jats/importer/create-article-node.js +0 -31
- package/dist/cjs/jats/importer/jats-front-transformations.js +0 -262
- package/dist/es/jats/importer/create-article-node.js +0 -27
- package/dist/es/jats/importer/jats-front-transformations.js +0 -259
- package/dist/types/jats/importer/jats-front-transformations.d.ts +0 -38
- /package/dist/cjs/{jats → transformer}/filename.js +0 -0
- /package/dist/cjs/{jats → transformer}/timestamp.js +0 -0
- /package/dist/es/{jats → transformer}/filename.js +0 -0
- /package/dist/es/{jats → transformer}/timestamp.js +0 -0
- /package/dist/types/{jats → transformer}/filename.d.ts +0 -0
- /package/dist/types/{jats → transformer}/timestamp.d.ts +0 -0
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2019 Atypon Systems LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
18
|
+
var t = {};
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
22
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
23
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
24
|
+
t[p[i]] = s[p[i]];
|
|
25
|
+
}
|
|
26
|
+
return t;
|
|
27
|
+
};
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.Decoder = exports.sortSectionsByPriority = exports.getModelsByType = exports.getModelData = void 0;
|
|
33
|
+
const json_schema_1 = require("@manuscripts/json-schema");
|
|
34
|
+
const debug_1 = __importDefault(require("debug"));
|
|
35
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
36
|
+
const errors_1 = require("../errors");
|
|
37
|
+
const section_group_type_1 = require("../lib/section-group-type");
|
|
38
|
+
const schema_1 = require("../schema");
|
|
39
|
+
const builders_1 = require("./builders");
|
|
40
|
+
const highlight_markers_1 = require("./highlight-markers");
|
|
41
|
+
const id_1 = require("./id");
|
|
42
|
+
const object_types_1 = require("./object-types");
|
|
43
|
+
const section_category_1 = require("./section-category");
|
|
44
|
+
const timestamp_1 = require("./timestamp");
|
|
45
|
+
const warn = (0, debug_1.default)('manuscripts-transform');
|
|
46
|
+
const parser = prosemirror_model_1.DOMParser.fromSchema(schema_1.schema);
|
|
47
|
+
const getModelData = (model) => {
|
|
48
|
+
const { updatedAt, createdAt } = model, data = __rest(model, ["updatedAt", "createdAt"]);
|
|
49
|
+
return data;
|
|
50
|
+
};
|
|
51
|
+
exports.getModelData = getModelData;
|
|
52
|
+
const getModelsByType = (modelMap, objectType) => {
|
|
53
|
+
const output = [];
|
|
54
|
+
for (const model of modelMap.values()) {
|
|
55
|
+
if (model.objectType === objectType) {
|
|
56
|
+
output.push(model);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return output;
|
|
60
|
+
};
|
|
61
|
+
exports.getModelsByType = getModelsByType;
|
|
62
|
+
const sortSectionsByPriority = (a, b) => a.priority === b.priority ? 0 : Number(a.priority) - Number(b.priority);
|
|
63
|
+
exports.sortSectionsByPriority = sortSectionsByPriority;
|
|
64
|
+
const getSections = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Section).sort(exports.sortSectionsByPriority);
|
|
65
|
+
const getAffiliations = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Affiliation);
|
|
66
|
+
const getContributors = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Contributor);
|
|
67
|
+
const getAuthorNotes = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.AuthorNotes);
|
|
68
|
+
const getKeywordElements = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordsElement);
|
|
69
|
+
const getSupplements = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Supplement);
|
|
70
|
+
const getKeywordGroups = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordGroup);
|
|
71
|
+
const getKeywords = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Keyword);
|
|
72
|
+
const getTitles = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Titles)[0];
|
|
73
|
+
const hasParentSection = (id) => (section) => section.path &&
|
|
74
|
+
section.path.length > 1 &&
|
|
75
|
+
section.path[section.path.length - 2] === id;
|
|
76
|
+
const deprecatedCategories = [
|
|
77
|
+
'MPSectionCategory:contributors',
|
|
78
|
+
'MPSectionCategory:affiliations',
|
|
79
|
+
'MPSectionCategory:keywords',
|
|
80
|
+
];
|
|
81
|
+
class Decoder {
|
|
82
|
+
createTitleNode() {
|
|
83
|
+
const titles = getTitles(this.modelMap) || (0, builders_1.buildTitles)();
|
|
84
|
+
return this.decode(titles);
|
|
85
|
+
}
|
|
86
|
+
createAffiliationsNode() {
|
|
87
|
+
const affiliations = getAffiliations(this.modelMap)
|
|
88
|
+
.map((a) => this.decode(a))
|
|
89
|
+
.filter(Boolean);
|
|
90
|
+
if (!affiliations.length) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return schema_1.schema.nodes.affiliations.createAndFill({}, affiliations);
|
|
94
|
+
}
|
|
95
|
+
createContributorsNode() {
|
|
96
|
+
const contributors = getContributors(this.modelMap)
|
|
97
|
+
.map((c) => this.decode(c))
|
|
98
|
+
.filter(Boolean);
|
|
99
|
+
const content = [...contributors];
|
|
100
|
+
if (!content.length) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
return schema_1.schema.nodes.contributors.createAndFill({}, content);
|
|
104
|
+
}
|
|
105
|
+
createAuthorNotesNode() {
|
|
106
|
+
return getAuthorNotes(this.modelMap)
|
|
107
|
+
.map((authorNote) => this.decode(authorNote))
|
|
108
|
+
.filter(Boolean);
|
|
109
|
+
}
|
|
110
|
+
createKeywordsNode() {
|
|
111
|
+
const elements = getKeywordElements(this.modelMap)
|
|
112
|
+
.map((e) => this.decode(e))
|
|
113
|
+
.filter(Boolean);
|
|
114
|
+
if (!elements.length) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return schema_1.schema.nodes.keywords.createAndFill({}, [
|
|
118
|
+
schema_1.schema.nodes.section_title.create({}, schema_1.schema.text('Keywords')),
|
|
119
|
+
...elements,
|
|
120
|
+
]);
|
|
121
|
+
}
|
|
122
|
+
createSupplementsNode() {
|
|
123
|
+
const elements = getSupplements(this.modelMap)
|
|
124
|
+
.map((e) => this.decode(e))
|
|
125
|
+
.filter(Boolean);
|
|
126
|
+
if (!elements.length) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return schema_1.schema.nodes.supplements.createAndFill({}, [
|
|
130
|
+
schema_1.schema.nodes.section_title.create({}, schema_1.schema.text('SupplementaryMaterials')),
|
|
131
|
+
...elements,
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
createCommentsNode() {
|
|
135
|
+
return schema_1.schema.nodes.comments.createAndFill({}, [
|
|
136
|
+
...this.comments.values(),
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
createContentSections() {
|
|
140
|
+
let sections = getSections(this.modelMap);
|
|
141
|
+
sections = this.addGeneratedLabels(sections);
|
|
142
|
+
const groups = {
|
|
143
|
+
abstracts: [],
|
|
144
|
+
body: [],
|
|
145
|
+
backmatter: [],
|
|
146
|
+
};
|
|
147
|
+
for (const section of sections) {
|
|
148
|
+
if (section.path.length > 1) {
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const category = section.category;
|
|
152
|
+
if (category && deprecatedCategories.includes(category)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const group = category ? (0, section_category_1.getSectionGroupType)(category) : section_group_type_1.bodyType;
|
|
156
|
+
groups[group._id].push(this.decode(section));
|
|
157
|
+
}
|
|
158
|
+
const abstracts = schema_1.schema.nodes.abstracts.createAndFill({}, groups[section_group_type_1.abstractsType._id]);
|
|
159
|
+
const body = schema_1.schema.nodes.body.createAndFill({}, groups[section_group_type_1.bodyType._id]);
|
|
160
|
+
const backmatter = schema_1.schema.nodes.backmatter.createAndFill({}, groups[section_group_type_1.backmatterType._id]);
|
|
161
|
+
return [abstracts, body, backmatter];
|
|
162
|
+
}
|
|
163
|
+
createCommentNodes(model) {
|
|
164
|
+
const comments = [];
|
|
165
|
+
for (const comment of this.getComments(model)) {
|
|
166
|
+
comments.push(this.decode(comment));
|
|
167
|
+
}
|
|
168
|
+
return comments;
|
|
169
|
+
}
|
|
170
|
+
getComments(model) {
|
|
171
|
+
return Array.from(this.modelMap.values()).filter((c) => (0, object_types_1.isCommentAnnotation)(c) && c.target === model._id);
|
|
172
|
+
}
|
|
173
|
+
extractListing(model) {
|
|
174
|
+
if (model.listingID) {
|
|
175
|
+
return this.createListing(model.listingID);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
constructor(modelMap, allowMissingElements = false) {
|
|
179
|
+
this.comments = new Map();
|
|
180
|
+
this.creators = {
|
|
181
|
+
[json_schema_1.ObjectTypes.Titles]: (data) => {
|
|
182
|
+
const model = data;
|
|
183
|
+
const comments = this.createCommentNodes(model);
|
|
184
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
185
|
+
return this.parseContents(model.title, 'div', this.getComments(model), {
|
|
186
|
+
topNode: schema_1.schema.nodes.title.create({
|
|
187
|
+
id: model._id,
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
[json_schema_1.ObjectTypes.BibliographyElement]: (data) => {
|
|
192
|
+
var _a;
|
|
193
|
+
const model = data;
|
|
194
|
+
const referenceIDs = (_a = model.containedObjectIDs) === null || _a === void 0 ? void 0 : _a.filter((i) => i.startsWith('MPBibliographyItem'));
|
|
195
|
+
const references = [];
|
|
196
|
+
referenceIDs === null || referenceIDs === void 0 ? void 0 : referenceIDs.forEach((id) => {
|
|
197
|
+
const referenceModel = this.getModel(id);
|
|
198
|
+
if (referenceModel) {
|
|
199
|
+
return references.push(this.decode(referenceModel));
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
return schema_1.schema.nodes.bibliography_element.createChecked({
|
|
203
|
+
id: model._id,
|
|
204
|
+
contents: '',
|
|
205
|
+
paragraphStyle: model.paragraphStyle,
|
|
206
|
+
}, references);
|
|
207
|
+
},
|
|
208
|
+
[json_schema_1.ObjectTypes.BibliographyItem]: (data) => {
|
|
209
|
+
const model = data;
|
|
210
|
+
const comments = this.createCommentNodes(model);
|
|
211
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
212
|
+
return schema_1.schema.nodes.bibliography_item.create({
|
|
213
|
+
id: model._id,
|
|
214
|
+
type: model.type,
|
|
215
|
+
author: model.author,
|
|
216
|
+
issued: model.issued,
|
|
217
|
+
containerTitle: model['container-title'],
|
|
218
|
+
volume: model.volume,
|
|
219
|
+
issue: model.issue,
|
|
220
|
+
supplement: model.supplement,
|
|
221
|
+
doi: model.DOI,
|
|
222
|
+
page: model.page,
|
|
223
|
+
title: model.title,
|
|
224
|
+
literal: model.literal,
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
[object_types_1.ExtraObjectTypes.PlaceholderElement]: (data) => {
|
|
228
|
+
const model = data;
|
|
229
|
+
return schema_1.schema.nodes.placeholder_element.create({
|
|
230
|
+
id: model._id,
|
|
231
|
+
});
|
|
232
|
+
},
|
|
233
|
+
[json_schema_1.ObjectTypes.Figure]: (data) => {
|
|
234
|
+
const model = data;
|
|
235
|
+
const comments = this.createCommentNodes(model);
|
|
236
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
237
|
+
return schema_1.schema.nodes.figure.create({
|
|
238
|
+
id: model._id,
|
|
239
|
+
contentType: model.contentType,
|
|
240
|
+
src: model.src,
|
|
241
|
+
position: model.position,
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
[json_schema_1.ObjectTypes.FigureElement]: (data) => {
|
|
245
|
+
const model = data;
|
|
246
|
+
const paragraphIDs = model.containedObjectIDs.filter((i) => i.startsWith('MPParagraphElement'));
|
|
247
|
+
const figureIDs = model.containedObjectIDs.filter((i) => i.startsWith('MPFigure') || i.startsWith('MPMissingFigure'));
|
|
248
|
+
const paragraphs = [];
|
|
249
|
+
paragraphIDs.forEach((id) => {
|
|
250
|
+
const paragraphModel = this.getModel(id);
|
|
251
|
+
if (paragraphModel) {
|
|
252
|
+
return paragraphs.push(this.decode(paragraphModel));
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const figures = [];
|
|
256
|
+
figureIDs.forEach((id) => {
|
|
257
|
+
const figureModel = this.getModel(id);
|
|
258
|
+
if (!figureModel) {
|
|
259
|
+
return figures.push(schema_1.schema.nodes.placeholder.create({
|
|
260
|
+
id,
|
|
261
|
+
label: 'A figure',
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
return figures.push(this.decode(figureModel));
|
|
265
|
+
});
|
|
266
|
+
if (!figures.length) {
|
|
267
|
+
figures.push(schema_1.schema.nodes.figure.createAndFill());
|
|
268
|
+
}
|
|
269
|
+
const figcaption = this.getFigcaption(model);
|
|
270
|
+
const comments = this.createCommentNodes(model);
|
|
271
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
272
|
+
const content = [...paragraphs, ...figures, figcaption];
|
|
273
|
+
const listing = this.extractListing(model);
|
|
274
|
+
if (listing) {
|
|
275
|
+
content.push(listing);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const listing = schema_1.schema.nodes.listing.create();
|
|
279
|
+
content.push(listing);
|
|
280
|
+
}
|
|
281
|
+
return schema_1.schema.nodes.figure_element.createChecked({
|
|
282
|
+
id: model._id,
|
|
283
|
+
figureLayout: model.figureLayout,
|
|
284
|
+
label: model.label,
|
|
285
|
+
figureStyle: model.figureStyle,
|
|
286
|
+
alignment: model.alignment,
|
|
287
|
+
sizeFraction: model.sizeFraction,
|
|
288
|
+
suppressCaption: Boolean(model.suppressCaption),
|
|
289
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
290
|
+
attribution: model.attribution,
|
|
291
|
+
alternatives: model.alternatives,
|
|
292
|
+
}, content);
|
|
293
|
+
},
|
|
294
|
+
[json_schema_1.ObjectTypes.Equation]: (data) => {
|
|
295
|
+
const model = data;
|
|
296
|
+
return schema_1.schema.nodes.equation.createChecked({
|
|
297
|
+
id: model._id,
|
|
298
|
+
contents: model.contents,
|
|
299
|
+
format: model.format,
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
[json_schema_1.ObjectTypes.EquationElement]: (data) => {
|
|
303
|
+
const model = data;
|
|
304
|
+
const equationModel = this.getModel(model.containedObjectID);
|
|
305
|
+
let equation;
|
|
306
|
+
if (equationModel) {
|
|
307
|
+
equation = this.decode(equationModel);
|
|
308
|
+
}
|
|
309
|
+
else if (this.allowMissingElements) {
|
|
310
|
+
equation = schema_1.schema.nodes.placeholder.create({
|
|
311
|
+
id: model.containedObjectID,
|
|
312
|
+
label: 'An equation',
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
throw new errors_1.MissingElement(model.containedObjectID);
|
|
317
|
+
}
|
|
318
|
+
return schema_1.schema.nodes.equation_element.createChecked({
|
|
319
|
+
id: model._id,
|
|
320
|
+
label: model.label,
|
|
321
|
+
}, [equation]);
|
|
322
|
+
},
|
|
323
|
+
[json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
|
|
324
|
+
const foonotesElementModel = data;
|
|
325
|
+
const footnotesOfKind = [];
|
|
326
|
+
const footnoteOrder = (0, exports.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.FootnotesOrder).find((model) => model.containedObjectID === data._id);
|
|
327
|
+
if (footnoteOrder) {
|
|
328
|
+
footnoteOrder.footnotesList.map(({ id }) => {
|
|
329
|
+
const model = this.modelMap.get(id);
|
|
330
|
+
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
331
|
+
if (model.kind === collateByKind) {
|
|
332
|
+
const comments = this.createCommentNodes(model);
|
|
333
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
334
|
+
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
335
|
+
topNode: schema_1.schema.nodes.footnote.create({
|
|
336
|
+
id: model._id,
|
|
337
|
+
kind: model.kind,
|
|
338
|
+
}),
|
|
339
|
+
});
|
|
340
|
+
footnotesOfKind.push(footnote);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return schema_1.schema.nodes.footnotes_element.create({
|
|
345
|
+
id: foonotesElementModel._id,
|
|
346
|
+
kind: foonotesElementModel.collateByKind,
|
|
347
|
+
paragraphStyle: foonotesElementModel.paragraphStyle,
|
|
348
|
+
}, footnotesOfKind);
|
|
349
|
+
},
|
|
350
|
+
[json_schema_1.ObjectTypes.Footnote]: (data) => {
|
|
351
|
+
const footnoteModel = data;
|
|
352
|
+
const comments = this.createCommentNodes(footnoteModel);
|
|
353
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
354
|
+
return this.parseContents(footnoteModel.contents || '<div></div>', undefined, this.getComments(footnoteModel), {
|
|
355
|
+
topNode: schema_1.schema.nodes.footnote.create({
|
|
356
|
+
id: footnoteModel._id,
|
|
357
|
+
kind: footnoteModel.kind,
|
|
358
|
+
}),
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
[json_schema_1.ObjectTypes.KeywordsElement]: (data) => {
|
|
362
|
+
const model = data;
|
|
363
|
+
const keywordGroups = getKeywordGroups(this.modelMap).map((k) => this.decode(k));
|
|
364
|
+
return schema_1.schema.nodes.keywords_element.create({
|
|
365
|
+
id: model._id,
|
|
366
|
+
paragraphStyle: model.paragraphStyle,
|
|
367
|
+
}, keywordGroups);
|
|
368
|
+
},
|
|
369
|
+
[json_schema_1.ObjectTypes.KeywordGroup]: (data) => {
|
|
370
|
+
const keywordGroup = data;
|
|
371
|
+
const keywords = getKeywords(this.modelMap)
|
|
372
|
+
.filter((k) => k.containedGroup === keywordGroup._id)
|
|
373
|
+
.map((k) => this.decode(k));
|
|
374
|
+
const comments = this.createCommentNodes(keywordGroup);
|
|
375
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
376
|
+
return schema_1.schema.nodes.keyword_group.create({
|
|
377
|
+
id: keywordGroup._id,
|
|
378
|
+
type: keywordGroup.type,
|
|
379
|
+
}, keywords);
|
|
380
|
+
},
|
|
381
|
+
[json_schema_1.ObjectTypes.Keyword]: (data) => {
|
|
382
|
+
const keyword = data;
|
|
383
|
+
const comments = this.createCommentNodes(keyword);
|
|
384
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
385
|
+
return schema_1.schema.nodes.keyword.create({
|
|
386
|
+
id: keyword._id,
|
|
387
|
+
contents: keyword.name,
|
|
388
|
+
}, schema_1.schema.text(keyword.name));
|
|
389
|
+
},
|
|
390
|
+
[json_schema_1.ObjectTypes.ListElement]: (data) => {
|
|
391
|
+
const model = data;
|
|
392
|
+
const comments = this.createCommentNodes(model);
|
|
393
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
394
|
+
switch (model.elementType) {
|
|
395
|
+
case 'ol':
|
|
396
|
+
return this.parseContents(model.contents || '<ol></ol>', undefined, this.getComments(model), {
|
|
397
|
+
topNode: schema_1.schema.nodes.list.create({
|
|
398
|
+
id: model._id,
|
|
399
|
+
listStyleType: model.listStyleType || 'order',
|
|
400
|
+
paragraphStyle: model.paragraphStyle,
|
|
401
|
+
}),
|
|
402
|
+
});
|
|
403
|
+
case 'ul':
|
|
404
|
+
return this.parseContents(model.contents || '<ul></ul>', undefined, this.getComments(model), {
|
|
405
|
+
topNode: schema_1.schema.nodes.list.create({
|
|
406
|
+
id: model._id,
|
|
407
|
+
listStyleType: model.listStyleType || 'bullet',
|
|
408
|
+
paragraphStyle: model.paragraphStyle,
|
|
409
|
+
}),
|
|
410
|
+
});
|
|
411
|
+
default:
|
|
412
|
+
throw new Error('Unknown list element type');
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
[json_schema_1.ObjectTypes.Listing]: (data) => {
|
|
416
|
+
const model = data;
|
|
417
|
+
const comments = this.createCommentNodes(model);
|
|
418
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
419
|
+
return schema_1.schema.nodes.listing.createChecked({
|
|
420
|
+
id: model._id,
|
|
421
|
+
contents: model.contents,
|
|
422
|
+
language: model.language,
|
|
423
|
+
languageKey: model.languageKey,
|
|
424
|
+
});
|
|
425
|
+
},
|
|
426
|
+
[json_schema_1.ObjectTypes.ListingElement]: (data) => {
|
|
427
|
+
const model = data;
|
|
428
|
+
const listingModel = this.getModel(model.containedObjectID);
|
|
429
|
+
let listing;
|
|
430
|
+
if (listingModel) {
|
|
431
|
+
listing = this.decode(listingModel);
|
|
432
|
+
}
|
|
433
|
+
else if (this.allowMissingElements) {
|
|
434
|
+
listing = schema_1.schema.nodes.placeholder.create({
|
|
435
|
+
id: model.containedObjectID,
|
|
436
|
+
label: 'A listing',
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
throw new errors_1.MissingElement(model.containedObjectID);
|
|
441
|
+
}
|
|
442
|
+
const figcaption = this.getFigcaption(model);
|
|
443
|
+
const comments = this.createCommentNodes(model);
|
|
444
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
445
|
+
return schema_1.schema.nodes.listing_element.createChecked({
|
|
446
|
+
id: model._id,
|
|
447
|
+
suppressCaption: model.suppressCaption,
|
|
448
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
449
|
+
}, [listing, figcaption]);
|
|
450
|
+
},
|
|
451
|
+
[json_schema_1.ObjectTypes.MissingFigure]: (data) => {
|
|
452
|
+
const model = data;
|
|
453
|
+
return schema_1.schema.nodes.missing_figure.create({
|
|
454
|
+
id: model._id,
|
|
455
|
+
position: model.position,
|
|
456
|
+
});
|
|
457
|
+
},
|
|
458
|
+
[json_schema_1.ObjectTypes.ParagraphElement]: (data) => {
|
|
459
|
+
const model = data;
|
|
460
|
+
const comments = this.createCommentNodes(model);
|
|
461
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
462
|
+
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
463
|
+
topNode: schema_1.schema.nodes.paragraph.create({
|
|
464
|
+
id: model._id,
|
|
465
|
+
paragraphStyle: model.paragraphStyle,
|
|
466
|
+
placeholder: model.placeholderInnerHTML,
|
|
467
|
+
}),
|
|
468
|
+
});
|
|
469
|
+
},
|
|
470
|
+
[json_schema_1.ObjectTypes.QuoteElement]: (data) => {
|
|
471
|
+
const model = data;
|
|
472
|
+
switch (model.quoteType) {
|
|
473
|
+
case 'block':
|
|
474
|
+
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
475
|
+
topNode: schema_1.schema.nodes.blockquote_element.create({
|
|
476
|
+
id: model._id,
|
|
477
|
+
paragraphStyle: model.paragraphStyle,
|
|
478
|
+
placeholder: model.placeholderInnerHTML,
|
|
479
|
+
}),
|
|
480
|
+
});
|
|
481
|
+
case 'pull':
|
|
482
|
+
return this.parseContents(model.contents || '<p></p>', undefined, this.getComments(model), {
|
|
483
|
+
topNode: schema_1.schema.nodes.pullquote_element.create({
|
|
484
|
+
id: model._id,
|
|
485
|
+
paragraphStyle: model.paragraphStyle,
|
|
486
|
+
placeholder: model.placeholderInnerHTML,
|
|
487
|
+
}),
|
|
488
|
+
});
|
|
489
|
+
default:
|
|
490
|
+
throw new Error('Unknown block type');
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
[json_schema_1.ObjectTypes.TableElementFooter]: (data) => {
|
|
494
|
+
const model = data;
|
|
495
|
+
const contents = [];
|
|
496
|
+
const generalTableFootnotes = [];
|
|
497
|
+
const footnotesElements = [];
|
|
498
|
+
for (const containedObjectID of model.containedObjectIDs) {
|
|
499
|
+
const model = this.modelMap.get(containedObjectID);
|
|
500
|
+
if (model.objectType === json_schema_1.ObjectTypes.ParagraphElement) {
|
|
501
|
+
const paragraph = this.decode(model);
|
|
502
|
+
if (paragraph) {
|
|
503
|
+
generalTableFootnotes.push(paragraph);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
footnotesElements.push(this.decode(model));
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (generalTableFootnotes && generalTableFootnotes.length) {
|
|
511
|
+
contents.push(schema_1.schema.nodes.general_table_footnote.create({ id: (0, id_1.generateID)(object_types_1.ExtraObjectTypes.GeneralTableFootnote) }, [...generalTableFootnotes]));
|
|
512
|
+
}
|
|
513
|
+
if (footnotesElements && footnotesElements.length) {
|
|
514
|
+
contents.push(...footnotesElements);
|
|
515
|
+
}
|
|
516
|
+
return schema_1.schema.nodes.table_element_footer.create({
|
|
517
|
+
id: model._id,
|
|
518
|
+
}, contents);
|
|
519
|
+
},
|
|
520
|
+
[json_schema_1.ObjectTypes.AuthorNotes]: (data) => {
|
|
521
|
+
const model = data;
|
|
522
|
+
const content = model.containedObjectIDs.map((id) => this.decode(this.modelMap.get(id)));
|
|
523
|
+
if (content.length == 0) {
|
|
524
|
+
return null;
|
|
525
|
+
}
|
|
526
|
+
return schema_1.schema.nodes.author_notes.createAndFill({
|
|
527
|
+
id: model._id,
|
|
528
|
+
}, [...content]);
|
|
529
|
+
},
|
|
530
|
+
[json_schema_1.ObjectTypes.Corresponding]: (data) => {
|
|
531
|
+
const model = data;
|
|
532
|
+
return this.parseContents(model.contents, 'corresp', [], {
|
|
533
|
+
topNode: schema_1.schema.nodes.corresp.create({
|
|
534
|
+
id: model._id,
|
|
535
|
+
label: model.label,
|
|
536
|
+
}),
|
|
537
|
+
});
|
|
538
|
+
},
|
|
539
|
+
[json_schema_1.ObjectTypes.Section]: (data) => {
|
|
540
|
+
const model = data;
|
|
541
|
+
const elements = [];
|
|
542
|
+
if (model.elementIDs) {
|
|
543
|
+
for (const id of model.elementIDs) {
|
|
544
|
+
const element = this.getModel(id);
|
|
545
|
+
if (element) {
|
|
546
|
+
elements.push(element);
|
|
547
|
+
}
|
|
548
|
+
else if (this.allowMissingElements) {
|
|
549
|
+
const placeholderElement = {
|
|
550
|
+
_id: id,
|
|
551
|
+
containerID: model._id,
|
|
552
|
+
elementType: 'p',
|
|
553
|
+
objectType: object_types_1.ExtraObjectTypes.PlaceholderElement,
|
|
554
|
+
createdAt: (0, timestamp_1.timestamp)(),
|
|
555
|
+
updatedAt: (0, timestamp_1.timestamp)(),
|
|
556
|
+
};
|
|
557
|
+
elements.push(placeholderElement);
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
throw new errors_1.MissingElement(id);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
const elementNodes = elements.map((e) => this.decode(e));
|
|
565
|
+
const sectionTitle = 'section_title';
|
|
566
|
+
const sectionTitleNode = model.title
|
|
567
|
+
? this.parseContents(model.title, 'h1', this.getComments(model), {
|
|
568
|
+
topNode: schema_1.schema.nodes[sectionTitle].create(),
|
|
569
|
+
})
|
|
570
|
+
: schema_1.schema.nodes[sectionTitle].create();
|
|
571
|
+
let sectionLabelNode = undefined;
|
|
572
|
+
if (model.label) {
|
|
573
|
+
sectionLabelNode = this.parseContents(model.label, 'label', this.getComments(model), {
|
|
574
|
+
topNode: schema_1.schema.nodes.section_label.create(),
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
const nestedSections = getSections(this.modelMap)
|
|
578
|
+
.filter(hasParentSection(model._id))
|
|
579
|
+
.map(this.creators[json_schema_1.ObjectTypes.Section]);
|
|
580
|
+
const sectionCategory = model.category || (0, section_category_1.guessSectionCategory)(elements);
|
|
581
|
+
const sectionNodeType = (0, section_category_1.chooseSectionNodeType)(sectionCategory);
|
|
582
|
+
const comments = this.createCommentNodes(model);
|
|
583
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
584
|
+
const content = (sectionLabelNode
|
|
585
|
+
? [sectionLabelNode, sectionTitleNode]
|
|
586
|
+
: [sectionTitleNode])
|
|
587
|
+
.concat(elementNodes)
|
|
588
|
+
.concat(nestedSections);
|
|
589
|
+
const sectionNode = sectionNodeType.createAndFill({
|
|
590
|
+
id: model._id,
|
|
591
|
+
category: sectionCategory,
|
|
592
|
+
titleSuppressed: model.titleSuppressed,
|
|
593
|
+
pageBreakStyle: model.pageBreakStyle,
|
|
594
|
+
generatedLabel: model.generatedLabel,
|
|
595
|
+
}, content);
|
|
596
|
+
if (!sectionNode) {
|
|
597
|
+
console.error(model);
|
|
598
|
+
throw new Error('Invalid content for section ' + model._id);
|
|
599
|
+
}
|
|
600
|
+
return sectionNode;
|
|
601
|
+
},
|
|
602
|
+
[json_schema_1.ObjectTypes.Table]: (data) => {
|
|
603
|
+
const model = data;
|
|
604
|
+
return this.parseContents(model.contents, undefined, [], {
|
|
605
|
+
topNode: schema_1.schema.nodes.table.create({
|
|
606
|
+
id: model._id,
|
|
607
|
+
}),
|
|
608
|
+
});
|
|
609
|
+
},
|
|
610
|
+
[json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
611
|
+
const model = data;
|
|
612
|
+
const table = this.createTable(model);
|
|
613
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
614
|
+
const tableElementFooter = this.createTableElementFooter(model);
|
|
615
|
+
const figcaption = this.getFigcaption(model);
|
|
616
|
+
const comments = this.createCommentNodes(model);
|
|
617
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
618
|
+
const content = [figcaption, table];
|
|
619
|
+
if (tableColGroup) {
|
|
620
|
+
content.push(tableColGroup);
|
|
621
|
+
}
|
|
622
|
+
if (tableElementFooter) {
|
|
623
|
+
content.push(tableElementFooter);
|
|
624
|
+
}
|
|
625
|
+
const listing = model.listingID
|
|
626
|
+
? this.createListing(model.listingID)
|
|
627
|
+
: schema_1.schema.nodes.listing.create();
|
|
628
|
+
content.push(listing);
|
|
629
|
+
return schema_1.schema.nodes.table_element.createChecked({
|
|
630
|
+
id: model._id,
|
|
631
|
+
table: model.containedObjectID,
|
|
632
|
+
suppressCaption: model.suppressCaption,
|
|
633
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
634
|
+
suppressFooter: model.suppressFooter,
|
|
635
|
+
suppressHeader: model.suppressHeader,
|
|
636
|
+
tableStyle: model.tableStyle,
|
|
637
|
+
paragraphStyle: model.paragraphStyle,
|
|
638
|
+
}, content);
|
|
639
|
+
},
|
|
640
|
+
[json_schema_1.ObjectTypes.TOCElement]: (data) => {
|
|
641
|
+
const model = data;
|
|
642
|
+
return schema_1.schema.nodes.toc_element.create({
|
|
643
|
+
id: model._id,
|
|
644
|
+
contents: model.contents
|
|
645
|
+
? model.contents.replace(/\s+xmlns=".+?"/, '')
|
|
646
|
+
: '',
|
|
647
|
+
paragraphStyle: model.paragraphStyle,
|
|
648
|
+
});
|
|
649
|
+
},
|
|
650
|
+
[json_schema_1.ObjectTypes.CommentAnnotation]: (data) => {
|
|
651
|
+
const model = data;
|
|
652
|
+
return schema_1.schema.nodes.comment.create({
|
|
653
|
+
id: model._id,
|
|
654
|
+
contents: model.contents,
|
|
655
|
+
selector: model.selector,
|
|
656
|
+
target: model.target,
|
|
657
|
+
resolved: model.resolved,
|
|
658
|
+
contributions: model.contributions,
|
|
659
|
+
originalText: model.originalText,
|
|
660
|
+
});
|
|
661
|
+
},
|
|
662
|
+
[json_schema_1.ObjectTypes.Affiliation]: (data) => {
|
|
663
|
+
const model = data;
|
|
664
|
+
return schema_1.schema.nodes.affiliation.create({
|
|
665
|
+
id: model._id,
|
|
666
|
+
institution: model.institution,
|
|
667
|
+
addressLine1: model.addressLine1,
|
|
668
|
+
addressLine2: model.addressLine2,
|
|
669
|
+
addressLine3: model.addressLine3,
|
|
670
|
+
postCode: model.postCode,
|
|
671
|
+
country: model.country,
|
|
672
|
+
county: model.county,
|
|
673
|
+
city: model.city,
|
|
674
|
+
email: model.email,
|
|
675
|
+
department: model.department,
|
|
676
|
+
priority: model.priority,
|
|
677
|
+
}, schema_1.schema.text('_'));
|
|
678
|
+
},
|
|
679
|
+
[json_schema_1.ObjectTypes.Contributor]: (data) => {
|
|
680
|
+
const model = data;
|
|
681
|
+
return schema_1.schema.nodes.contributor.create({
|
|
682
|
+
id: model._id,
|
|
683
|
+
role: model.role,
|
|
684
|
+
affiliations: model.affiliations,
|
|
685
|
+
email: model.email,
|
|
686
|
+
isJointContributor: model.isJointContributor,
|
|
687
|
+
bibliographicName: model.bibliographicName,
|
|
688
|
+
userID: model.userID,
|
|
689
|
+
invitationID: model.invitationID,
|
|
690
|
+
isCorresponding: model.isCorresponding,
|
|
691
|
+
ORCIDIdentifier: model.ORCIDIdentifier,
|
|
692
|
+
footnote: model.footnote,
|
|
693
|
+
corresp: model.corresp,
|
|
694
|
+
priority: model.priority,
|
|
695
|
+
}, schema_1.schema.text('_'));
|
|
696
|
+
},
|
|
697
|
+
[json_schema_1.ObjectTypes.Supplement]: (data) => {
|
|
698
|
+
var _a, _b;
|
|
699
|
+
const model = data;
|
|
700
|
+
return schema_1.schema.nodes.supplement.create({
|
|
701
|
+
id: model._id,
|
|
702
|
+
href: model.href,
|
|
703
|
+
mimeType: (_a = model.MIME) === null || _a === void 0 ? void 0 : _a.split('/')[0],
|
|
704
|
+
mimeSubType: (_b = model.MIME) === null || _b === void 0 ? void 0 : _b.split('/')[1],
|
|
705
|
+
title: model.title,
|
|
706
|
+
});
|
|
707
|
+
},
|
|
708
|
+
};
|
|
709
|
+
this.decode = (model) => {
|
|
710
|
+
if (!this.creators[model.objectType]) {
|
|
711
|
+
warn(`No converter for ${model.objectType}`);
|
|
712
|
+
return null;
|
|
713
|
+
}
|
|
714
|
+
return this.creators[model.objectType](model);
|
|
715
|
+
};
|
|
716
|
+
this.getModel = (id) => this.modelMap.get(id);
|
|
717
|
+
this.createArticleNode = (manuscriptID) => {
|
|
718
|
+
const nodes = [
|
|
719
|
+
this.createTitleNode(),
|
|
720
|
+
this.createContributorsNode(),
|
|
721
|
+
this.createAffiliationsNode(),
|
|
722
|
+
...this.createAuthorNotesNode(),
|
|
723
|
+
this.createKeywordsNode(),
|
|
724
|
+
this.createSupplementsNode(),
|
|
725
|
+
...this.createContentSections(),
|
|
726
|
+
this.createCommentsNode(),
|
|
727
|
+
];
|
|
728
|
+
const contents = nodes.filter((node) => node !== false);
|
|
729
|
+
const props = this.getManuscript();
|
|
730
|
+
return schema_1.schema.nodes.manuscript.create({
|
|
731
|
+
id: manuscriptID || this.getManuscriptID(),
|
|
732
|
+
doi: (props === null || props === void 0 ? void 0 : props.DOI) || '',
|
|
733
|
+
articleType: props === null || props === void 0 ? void 0 : props.articleType,
|
|
734
|
+
prototype: props === null || props === void 0 ? void 0 : props.prototype,
|
|
735
|
+
primaryLanguageCode: props === null || props === void 0 ? void 0 : props.primaryLanguageCode,
|
|
736
|
+
}, contents);
|
|
737
|
+
};
|
|
738
|
+
this.addGeneratedLabels = (sections) => {
|
|
739
|
+
const nextLableCount = { Appendix: 1 };
|
|
740
|
+
return sections.map((section) => {
|
|
741
|
+
if (section.generatedLabel) {
|
|
742
|
+
const secType = section.category
|
|
743
|
+
? (0, section_category_1.chooseSecType)(section.category)
|
|
744
|
+
: undefined;
|
|
745
|
+
if (secType === 'appendices') {
|
|
746
|
+
section.label = `${(0, section_category_1.chooseSectionLableName)(secType)} ${nextLableCount['Appendix']}`;
|
|
747
|
+
nextLableCount['Appendix'] += 1;
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
delete section.label;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return section;
|
|
754
|
+
});
|
|
755
|
+
};
|
|
756
|
+
this.parseContents = (contents, wrapper, commentAnnotations = [], options) => {
|
|
757
|
+
const contentsWithComments = commentAnnotations.length
|
|
758
|
+
? (0, highlight_markers_1.insertHighlightMarkers)(contents, commentAnnotations)
|
|
759
|
+
: contents;
|
|
760
|
+
const wrappedContents = wrapper
|
|
761
|
+
? `<${wrapper}>${contentsWithComments}</${wrapper}>`
|
|
762
|
+
: contentsWithComments;
|
|
763
|
+
const html = wrappedContents.trim();
|
|
764
|
+
if (!html.length) {
|
|
765
|
+
throw new Error('No HTML to parse');
|
|
766
|
+
}
|
|
767
|
+
const template = document.createElement('template');
|
|
768
|
+
template.innerHTML = html;
|
|
769
|
+
if (!template.content.firstElementChild) {
|
|
770
|
+
throw new Error('No content could be parsed');
|
|
771
|
+
}
|
|
772
|
+
return parser.parse(template.content.firstElementChild, options);
|
|
773
|
+
};
|
|
774
|
+
this.getManuscriptID = () => {
|
|
775
|
+
for (const item of this.modelMap.values()) {
|
|
776
|
+
if ((0, object_types_1.isManuscript)(item)) {
|
|
777
|
+
return item._id;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
};
|
|
781
|
+
this.getManuscript = () => {
|
|
782
|
+
for (const item of this.modelMap.values()) {
|
|
783
|
+
if ((0, object_types_1.isManuscript)(item)) {
|
|
784
|
+
return item;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
this.getFigcaption = (model) => {
|
|
789
|
+
const titleNode = schema_1.schema.nodes.caption_title.create();
|
|
790
|
+
const captionTitle = model.title
|
|
791
|
+
? this.parseContents(model.title, 'caption_title', this.getComments(model), {
|
|
792
|
+
topNode: titleNode,
|
|
793
|
+
})
|
|
794
|
+
: titleNode;
|
|
795
|
+
if (model.caption && /<\/?[a-z][\s\S]*>/i.test(model.caption)) {
|
|
796
|
+
const captionDoc = document.createElement('div');
|
|
797
|
+
captionDoc.innerHTML = model.caption;
|
|
798
|
+
const content = [captionTitle];
|
|
799
|
+
const paragraphs = captionDoc.querySelectorAll('p');
|
|
800
|
+
for (const paragraph of paragraphs) {
|
|
801
|
+
const captionNode = schema_1.schema.nodes.caption.create();
|
|
802
|
+
const caption = this.parseContents(paragraph.outerHTML, 'caption', this.getComments(model), {
|
|
803
|
+
topNode: captionNode,
|
|
804
|
+
});
|
|
805
|
+
content.push(caption);
|
|
806
|
+
}
|
|
807
|
+
return schema_1.schema.nodes.figcaption.create({}, content);
|
|
808
|
+
}
|
|
809
|
+
const captionNode = schema_1.schema.nodes.caption.create();
|
|
810
|
+
const caption = model.caption
|
|
811
|
+
? this.parseContents(model.caption, 'caption', this.getComments(model), {
|
|
812
|
+
topNode: captionNode,
|
|
813
|
+
})
|
|
814
|
+
: captionNode;
|
|
815
|
+
return schema_1.schema.nodes.figcaption.create({}, [captionTitle, caption]);
|
|
816
|
+
};
|
|
817
|
+
this.modelMap = modelMap;
|
|
818
|
+
this.allowMissingElements = allowMissingElements;
|
|
819
|
+
}
|
|
820
|
+
createTable(model) {
|
|
821
|
+
const tableID = model.containedObjectID;
|
|
822
|
+
const tableModel = this.getModel(tableID);
|
|
823
|
+
let table;
|
|
824
|
+
if (tableModel) {
|
|
825
|
+
table = this.decode(tableModel);
|
|
826
|
+
}
|
|
827
|
+
else if (this.allowMissingElements) {
|
|
828
|
+
table = schema_1.schema.nodes.placeholder.create({
|
|
829
|
+
id: tableID,
|
|
830
|
+
label: 'A table',
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
else {
|
|
834
|
+
throw new errors_1.MissingElement(tableID);
|
|
835
|
+
}
|
|
836
|
+
return table;
|
|
837
|
+
}
|
|
838
|
+
createTableColGroup(model) {
|
|
839
|
+
const tableID = model.containedObjectID;
|
|
840
|
+
const tableModel = this.getModel(tableID);
|
|
841
|
+
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
842
|
+
return undefined;
|
|
843
|
+
}
|
|
844
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
845
|
+
topNode: schema_1.schema.nodes.table_colgroup.create(),
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
createTableElementFooter(model) {
|
|
849
|
+
const tableElementFooterID = model.tableElementFooterID;
|
|
850
|
+
if (!tableElementFooterID) {
|
|
851
|
+
return undefined;
|
|
852
|
+
}
|
|
853
|
+
const tableElementFooterModel = this.getModel(tableElementFooterID);
|
|
854
|
+
return tableElementFooterModel
|
|
855
|
+
? this.decode(tableElementFooterModel)
|
|
856
|
+
: undefined;
|
|
857
|
+
}
|
|
858
|
+
createListing(id) {
|
|
859
|
+
const listing = this.getModel(id);
|
|
860
|
+
if (listing) {
|
|
861
|
+
return this.decode(listing);
|
|
862
|
+
}
|
|
863
|
+
else if (this.allowMissingElements) {
|
|
864
|
+
return schema_1.schema.nodes.placeholder.create({
|
|
865
|
+
id,
|
|
866
|
+
label: 'A listing',
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
else {
|
|
870
|
+
throw new errors_1.MissingElement(id);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
exports.Decoder = Decoder;
|