@manuscripts/transform 1.5.3 → 1.5.4-LEAN-3030
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/jats/importer/jats-body-dom-parser.js +23 -18
- package/dist/cjs/jats/importer/jats-body-transformations.js +3 -3
- package/dist/cjs/jats/importer/parse-jats-article.js +11 -2
- package/dist/cjs/jats/jats-exporter.js +19 -12
- package/dist/cjs/lib/utils.js +10 -1
- package/dist/cjs/schema/index.js +19 -12
- package/dist/cjs/schema/nodes/affiliations.js +15 -0
- package/dist/cjs/schema/nodes/contributors.js +15 -0
- package/dist/cjs/schema/nodes/core_section.js +27 -0
- 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 +1 -1
- package/dist/cjs/schema/nodes/title.js +29 -0
- package/dist/cjs/transformer/builders.js +8 -3
- package/dist/cjs/transformer/decode.js +119 -105
- package/dist/cjs/transformer/encode.js +19 -26
- package/dist/cjs/transformer/html.js +6 -5
- package/dist/cjs/transformer/node-names.js +1 -1
- package/dist/cjs/transformer/node-title.js +7 -5
- package/dist/cjs/transformer/node-types.js +8 -4
- package/dist/cjs/transformer/project-bundle.js +22 -1
- package/dist/cjs/transformer/section-category.js +35 -8
- package/dist/es/jats/importer/jats-body-dom-parser.js +23 -18
- package/dist/es/jats/importer/jats-body-transformations.js +3 -3
- package/dist/es/jats/importer/parse-jats-article.js +11 -2
- package/dist/es/jats/jats-exporter.js +20 -13
- package/dist/es/lib/utils.js +8 -0
- package/dist/es/schema/index.js +19 -12
- package/dist/es/schema/nodes/{affiliations_section.js → affiliations.js} +3 -3
- package/dist/es/schema/nodes/{contributors_section.js → contributors.js} +3 -3
- package/dist/es/schema/nodes/core_section.js +24 -0
- 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 +1 -1
- package/dist/es/schema/nodes/title.js +26 -0
- package/dist/es/transformer/builders.js +6 -2
- package/dist/es/transformer/decode.js +120 -106
- package/dist/es/transformer/encode.js +19 -26
- package/dist/es/transformer/html.js +7 -6
- package/dist/es/transformer/node-names.js +1 -1
- package/dist/es/transformer/node-title.js +8 -6
- package/dist/es/transformer/node-types.js +8 -4
- package/dist/es/transformer/project-bundle.js +20 -0
- package/dist/es/transformer/section-category.js +33 -7
- package/dist/types/lib/utils.d.ts +1 -0
- package/dist/types/schema/index.d.ts +4 -3
- package/dist/types/schema/nodes/affiliations.d.ts +11 -0
- package/dist/types/schema/nodes/contributors.d.ts +11 -0
- package/dist/types/schema/nodes/core_section.d.ts +17 -0
- package/dist/types/schema/nodes/keyword.d.ts +0 -1
- package/dist/types/schema/nodes/{keywords_group.d.ts → keyword_group.d.ts} +3 -3
- package/dist/types/schema/nodes/{keywords_section.d.ts → keywords.d.ts} +3 -3
- package/dist/types/schema/nodes/title.d.ts +28 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/builders.d.ts +3 -2
- package/dist/types/transformer/decode.d.ts +6 -5
- package/dist/types/transformer/project-bundle.d.ts +2 -1
- package/dist/types/transformer/section-category.d.ts +1 -0
- package/package.json +2 -2
- package/dist/cjs/schema/nodes/affiliations_section.js +0 -15
- package/dist/cjs/schema/nodes/contributors_section.js +0 -15
- package/dist/types/schema/nodes/affiliations_section.d.ts +0 -11
- package/dist/types/schema/nodes/contributors_section.d.ts +0 -11
|
@@ -34,7 +34,9 @@ const json_schema_1 = require("@manuscripts/json-schema");
|
|
|
34
34
|
const debug_1 = __importDefault(require("debug"));
|
|
35
35
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
36
36
|
const errors_1 = require("../errors");
|
|
37
|
+
const utils_1 = require("../lib/utils");
|
|
37
38
|
const schema_1 = require("../schema");
|
|
39
|
+
const builders_1 = require("./builders");
|
|
38
40
|
const highlight_markers_1 = require("./highlight-markers");
|
|
39
41
|
const id_1 = require("./id");
|
|
40
42
|
const object_types_1 = require("./object-types");
|
|
@@ -62,18 +64,42 @@ exports.sortSectionsByPriority = sortSectionsByPriority;
|
|
|
62
64
|
const getSections = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Section).sort(exports.sortSectionsByPriority);
|
|
63
65
|
const getAffiliations = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Affiliation);
|
|
64
66
|
const getContributors = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Contributor);
|
|
67
|
+
const getKeywordElements = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordsElement);
|
|
68
|
+
const getKeywordGroups = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordGroup);
|
|
69
|
+
const getKeywords = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Keyword);
|
|
70
|
+
const getTitles = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Titles)[0];
|
|
65
71
|
const isManuscriptNode = (model) => model !== null;
|
|
66
72
|
exports.isManuscriptNode = isManuscriptNode;
|
|
67
|
-
const isParagraphElement = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.ParagraphElement);
|
|
68
73
|
const isFootnote = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Footnote);
|
|
69
|
-
const isKeyword = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Keyword);
|
|
70
|
-
const isKeywordsSection = (model) => model.category === 'MPSectionCategory:keywords';
|
|
71
|
-
const isAffiliationsSection = (model) => model.category === 'MPSectionCategory:affiliations';
|
|
72
|
-
const isContributorsSection = (model) => model.category === 'MPSectionCategory:contributors';
|
|
73
74
|
const hasParentSection = (id) => (section) => section.path &&
|
|
74
75
|
section.path.length > 1 &&
|
|
75
76
|
section.path[section.path.length - 2] === id;
|
|
76
77
|
class Decoder {
|
|
78
|
+
createTitleNode() {
|
|
79
|
+
const titles = getTitles(this.modelMap) || (0, builders_1.buildTitles)();
|
|
80
|
+
return this.decode(titles);
|
|
81
|
+
}
|
|
82
|
+
createAffiliationsNode() {
|
|
83
|
+
const affiliations = getAffiliations(this.modelMap)
|
|
84
|
+
.map((a) => this.decode(a))
|
|
85
|
+
.filter(Boolean);
|
|
86
|
+
return schema_1.schema.nodes.affiliations.createAndFill({}, affiliations);
|
|
87
|
+
}
|
|
88
|
+
createContributorsNode() {
|
|
89
|
+
const contributors = getContributors(this.modelMap)
|
|
90
|
+
.map((c) => this.decode(c))
|
|
91
|
+
.filter(Boolean);
|
|
92
|
+
return schema_1.schema.nodes.contributors.createAndFill({}, contributors);
|
|
93
|
+
}
|
|
94
|
+
createKeywordsNode() {
|
|
95
|
+
const elements = getKeywordElements(this.modelMap)
|
|
96
|
+
.map((e) => this.decode(e))
|
|
97
|
+
.filter(Boolean);
|
|
98
|
+
return schema_1.schema.nodes.keywords.createAndFill({}, [
|
|
99
|
+
schema_1.schema.nodes.section_title.create({}, schema_1.schema.text('Keywords')),
|
|
100
|
+
...elements,
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
77
103
|
createMetaSectionNode() {
|
|
78
104
|
const commentListNode = this.createCommentListNode();
|
|
79
105
|
return schema_1.schema.nodes.meta_section.createAndFill({}, [
|
|
@@ -85,49 +111,51 @@ class Decoder {
|
|
|
85
111
|
...this.comments.values(),
|
|
86
112
|
]);
|
|
87
113
|
}
|
|
88
|
-
handleMissingRootSectionNodes(rootSectionNodes) {
|
|
89
|
-
if (!rootSectionNodes.find((node) => node.type.name === 'affiliations_section')) {
|
|
90
|
-
this.createAffiliationSectionNode(rootSectionNodes);
|
|
91
|
-
}
|
|
92
|
-
if (!rootSectionNodes.find((node) => node.type.name === 'contributors_section')) {
|
|
93
|
-
this.createContributorSectionNode(rootSectionNodes);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
createAffiliationSectionNode(rootSectionNodes) {
|
|
97
|
-
const affiliationNodes = getAffiliations(this.modelMap)
|
|
98
|
-
.map((affiliation) => this.decode(affiliation))
|
|
99
|
-
.filter(Boolean);
|
|
100
|
-
if (affiliationNodes.length) {
|
|
101
|
-
const node = schema_1.schema.nodes.affiliations_section.createAndFill({
|
|
102
|
-
id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
|
|
103
|
-
}, affiliationNodes);
|
|
104
|
-
rootSectionNodes.unshift(node);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
createContributorSectionNode(rootSectionNodes) {
|
|
108
|
-
const contributorNodes = getContributors(this.modelMap)
|
|
109
|
-
.map((contributor) => this.decode(contributor))
|
|
110
|
-
.filter(Boolean);
|
|
111
|
-
if (contributorNodes.length) {
|
|
112
|
-
const node = schema_1.schema.nodes.contributors_section.createAndFill({
|
|
113
|
-
id: (0, id_1.generateNodeID)(schema_1.schema.nodes.section),
|
|
114
|
-
}, contributorNodes);
|
|
115
|
-
rootSectionNodes.unshift(node);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
114
|
createRootSectionNodes() {
|
|
119
|
-
let rootSections = getSections(this.modelMap)
|
|
115
|
+
let rootSections = getSections(this.modelMap)
|
|
116
|
+
.filter((section) => !section.path || section.path.length <= 1)
|
|
117
|
+
.filter((section) => section.category !== 'MPSectionCategory:contributors' &&
|
|
118
|
+
section.category !== 'MPSectionCategory:affiliations' &&
|
|
119
|
+
section.category !== 'MPSectionCategory:keywords');
|
|
120
120
|
rootSections = this.addGeneratedLabels(rootSections);
|
|
121
|
-
const
|
|
121
|
+
const sectionGroups = (0, utils_1.groupBy)(rootSections, (sec) => {
|
|
122
|
+
var _a;
|
|
123
|
+
return (0, section_category_1.chooseCoreSectionBySection)((_a = sec.category) !== null && _a !== void 0 ? _a : '');
|
|
124
|
+
});
|
|
125
|
+
this.ensureCoreSectionsExist(sectionGroups);
|
|
126
|
+
const absSectionNode = sectionGroups['MPSectionCategory:abstracts']
|
|
122
127
|
.map(this.decode)
|
|
123
128
|
.filter(exports.isManuscriptNode);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
const bodySectionNodes = sectionGroups['MPSectionCategory:body']
|
|
130
|
+
.map(this.decode)
|
|
131
|
+
.filter(exports.isManuscriptNode);
|
|
132
|
+
const backmatterSectionNodes = sectionGroups['MPSectionCategory:backmatter']
|
|
133
|
+
.map(this.decode)
|
|
134
|
+
.filter(exports.isManuscriptNode);
|
|
135
|
+
const abstractCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.abstracts, absSectionNode);
|
|
136
|
+
const bodyCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.body, bodySectionNodes);
|
|
137
|
+
const backmatterCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.backmatter, backmatterSectionNodes);
|
|
138
|
+
return {
|
|
139
|
+
abstracts: abstractCoreSectionNodes,
|
|
140
|
+
body: bodyCoreSectionNodes,
|
|
141
|
+
backmatter: backmatterCoreSectionNodes,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
ensureCoreSectionsExist(coreSections) {
|
|
145
|
+
if (!coreSections['MPSectionCategory:abstracts']) {
|
|
146
|
+
coreSections['MPSectionCategory:abstracts'] = [];
|
|
129
147
|
}
|
|
130
|
-
|
|
148
|
+
if (!coreSections['MPSectionCategory:body']) {
|
|
149
|
+
coreSections['MPSectionCategory:body'] = [];
|
|
150
|
+
}
|
|
151
|
+
if (!coreSections['MPSectionCategory:backmatter']) {
|
|
152
|
+
coreSections['MPSectionCategory:backmatter'] = [];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
createAndFill(nodeType, content) {
|
|
156
|
+
return nodeType.createAndFill({
|
|
157
|
+
id: (0, id_1.generateNodeID)(nodeType),
|
|
158
|
+
}, content);
|
|
131
159
|
}
|
|
132
160
|
createCommentsNode(model) {
|
|
133
161
|
const comments = [];
|
|
@@ -147,6 +175,14 @@ class Decoder {
|
|
|
147
175
|
constructor(modelMap, allowMissingElements = false) {
|
|
148
176
|
this.comments = new Map();
|
|
149
177
|
this.creators = {
|
|
178
|
+
[json_schema_1.ObjectTypes.Titles]: (data) => {
|
|
179
|
+
const model = data;
|
|
180
|
+
return this.parseContents(model.title, 'div', undefined, {
|
|
181
|
+
topNode: schema_1.schema.nodes.title.create({
|
|
182
|
+
id: model._id,
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
},
|
|
150
186
|
[json_schema_1.ObjectTypes.BibliographyElement]: (data) => {
|
|
151
187
|
var _a;
|
|
152
188
|
const model = data;
|
|
@@ -325,19 +361,32 @@ class Decoder {
|
|
|
325
361
|
},
|
|
326
362
|
[json_schema_1.ObjectTypes.KeywordsElement]: (data) => {
|
|
327
363
|
const model = data;
|
|
328
|
-
const keywordGroups = this.
|
|
364
|
+
const keywordGroups = getKeywordGroups(this.modelMap).map(k => this.decode(k));
|
|
329
365
|
return schema_1.schema.nodes.keywords_element.create({
|
|
330
366
|
id: model._id,
|
|
331
367
|
paragraphStyle: model.paragraphStyle,
|
|
332
368
|
}, keywordGroups);
|
|
333
369
|
},
|
|
370
|
+
[json_schema_1.ObjectTypes.KeywordGroup]: (data) => {
|
|
371
|
+
const keywordGroup = data;
|
|
372
|
+
const keywords = getKeywords(this.modelMap).filter(k => k.containedGroup === keywordGroup._id).map(k => this.decode(k));
|
|
373
|
+
const comments = this.createCommentsNode(keywordGroup);
|
|
374
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
375
|
+
return schema_1.schema.nodes.keyword_group.create({
|
|
376
|
+
id: keywordGroup._id,
|
|
377
|
+
type: keywordGroup.type,
|
|
378
|
+
comments: comments.map((c) => c.attrs.id),
|
|
379
|
+
}, keywords);
|
|
380
|
+
},
|
|
334
381
|
[json_schema_1.ObjectTypes.Keyword]: (data) => {
|
|
335
|
-
const
|
|
382
|
+
const keyword = data;
|
|
383
|
+
const comments = this.createCommentsNode(keyword);
|
|
384
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
336
385
|
return schema_1.schema.nodes.keyword.create({
|
|
337
|
-
id:
|
|
338
|
-
contents:
|
|
339
|
-
comments:
|
|
340
|
-
}, schema_1.schema.text(
|
|
386
|
+
id: keyword._id,
|
|
387
|
+
contents: keyword.name,
|
|
388
|
+
comments: comments.map((c) => c.attrs.id),
|
|
389
|
+
}, schema_1.schema.text(keyword.name));
|
|
341
390
|
},
|
|
342
391
|
[json_schema_1.ObjectTypes.ListElement]: (data) => {
|
|
343
392
|
const model = data;
|
|
@@ -459,9 +508,6 @@ class Decoder {
|
|
|
459
508
|
for (const id of model.elementIDs) {
|
|
460
509
|
const element = this.getModel(id);
|
|
461
510
|
if (element) {
|
|
462
|
-
if (isKeywordsSection(model) && isParagraphElement(element)) {
|
|
463
|
-
continue;
|
|
464
|
-
}
|
|
465
511
|
elements.push(element);
|
|
466
512
|
}
|
|
467
513
|
else if (this.allowMissingElements) {
|
|
@@ -502,17 +548,11 @@ class Decoder {
|
|
|
502
548
|
const sectionNodeType = (0, section_category_1.chooseSectionNodeType)(sectionCategory);
|
|
503
549
|
const commentNodes = this.createCommentsNode(model);
|
|
504
550
|
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
content = (sectionLabelNode
|
|
511
|
-
? [sectionLabelNode, sectionTitleNode]
|
|
512
|
-
: [sectionTitleNode])
|
|
513
|
-
.concat(elementNodes)
|
|
514
|
-
.concat(nestedSections);
|
|
515
|
-
}
|
|
551
|
+
const content = (sectionLabelNode
|
|
552
|
+
? [sectionLabelNode, sectionTitleNode]
|
|
553
|
+
: [sectionTitleNode])
|
|
554
|
+
.concat(elementNodes)
|
|
555
|
+
.concat(nestedSections);
|
|
516
556
|
const sectionNode = sectionNodeType.createAndFill({
|
|
517
557
|
id: model._id,
|
|
518
558
|
category: sectionCategory,
|
|
@@ -631,9 +671,22 @@ class Decoder {
|
|
|
631
671
|
};
|
|
632
672
|
this.getModel = (id) => this.modelMap.get(id);
|
|
633
673
|
this.createArticleNode = (manuscriptID) => {
|
|
634
|
-
const
|
|
635
|
-
const
|
|
636
|
-
const
|
|
674
|
+
const title = this.createTitleNode();
|
|
675
|
+
const contributors = this.createContributorsNode();
|
|
676
|
+
const affiliations = this.createAffiliationsNode();
|
|
677
|
+
const keywords = this.createKeywordsNode();
|
|
678
|
+
const { abstracts, body, backmatter } = this.createRootSectionNodes();
|
|
679
|
+
const meta = this.createMetaSectionNode();
|
|
680
|
+
const contents = [
|
|
681
|
+
title,
|
|
682
|
+
contributors,
|
|
683
|
+
affiliations,
|
|
684
|
+
keywords,
|
|
685
|
+
abstracts,
|
|
686
|
+
body,
|
|
687
|
+
backmatter,
|
|
688
|
+
meta,
|
|
689
|
+
];
|
|
637
690
|
return schema_1.schema.nodes.manuscript.create({
|
|
638
691
|
id: manuscriptID || this.getManuscriptID(),
|
|
639
692
|
}, contents);
|
|
@@ -674,23 +727,6 @@ class Decoder {
|
|
|
674
727
|
}
|
|
675
728
|
return parser.parse(template.content.firstElementChild, options);
|
|
676
729
|
};
|
|
677
|
-
this.getKeywords = (id) => {
|
|
678
|
-
const keywordsOfKind = [];
|
|
679
|
-
const keywordsByGroup = [...this.modelMap.values()].filter((m) => m.objectType === json_schema_1.ObjectTypes.Keyword &&
|
|
680
|
-
m.containedGroup === id);
|
|
681
|
-
for (const model of keywordsByGroup) {
|
|
682
|
-
if (isKeyword(model)) {
|
|
683
|
-
const keyword = this.parseContents(model.name || '', 'div', this.getComments(model), {
|
|
684
|
-
topNode: schema_1.schema.nodes.keyword.create({
|
|
685
|
-
id: model._id,
|
|
686
|
-
contents: model.name,
|
|
687
|
-
}),
|
|
688
|
-
});
|
|
689
|
-
keywordsOfKind.push(keyword);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
return keywordsOfKind;
|
|
693
|
-
};
|
|
694
730
|
this.getManuscriptID = () => {
|
|
695
731
|
for (const item of this.modelMap.values()) {
|
|
696
732
|
if ((0, object_types_1.isManuscript)(item)) {
|
|
@@ -775,27 +811,5 @@ class Decoder {
|
|
|
775
811
|
}
|
|
776
812
|
return listing;
|
|
777
813
|
}
|
|
778
|
-
getKeywordGroups() {
|
|
779
|
-
const kwdGroupNodes = [];
|
|
780
|
-
const kwdGroupsModels = [
|
|
781
|
-
...this.modelMap.values(),
|
|
782
|
-
].filter((model) => model.objectType === json_schema_1.ObjectTypes.KeywordGroup);
|
|
783
|
-
if (kwdGroupsModels.length > 0) {
|
|
784
|
-
for (const kwdGroupModel of kwdGroupsModels) {
|
|
785
|
-
const keywords = this.getKeywords(kwdGroupModel._id);
|
|
786
|
-
const commentNodes = this.createCommentsNode(kwdGroupModel);
|
|
787
|
-
commentNodes.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
788
|
-
const contents = [];
|
|
789
|
-
contents.push(...keywords);
|
|
790
|
-
const kwdGroupNode = schema_1.schema.nodes.keywords_group.create({
|
|
791
|
-
id: kwdGroupModel._id,
|
|
792
|
-
type: kwdGroupModel.type,
|
|
793
|
-
comments: commentNodes.map((c) => c.attrs.id),
|
|
794
|
-
}, contents);
|
|
795
|
-
kwdGroupNodes.push(kwdGroupNode);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
return kwdGroupNodes;
|
|
799
|
-
}
|
|
800
814
|
}
|
|
801
815
|
exports.Decoder = Decoder;
|
|
@@ -263,6 +263,12 @@ function figureElementEncoder(node) {
|
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
265
|
const encoders = {
|
|
266
|
+
title: (node) => ({
|
|
267
|
+
title: (0, exports.inlineContents)(node),
|
|
268
|
+
subtitle: node.attrs.subtitle,
|
|
269
|
+
runningTitle: node.attrs.runningTitle,
|
|
270
|
+
_id: node.attrs._id,
|
|
271
|
+
}),
|
|
266
272
|
bibliography_element: (node) => ({
|
|
267
273
|
elementType: 'div',
|
|
268
274
|
contents: '',
|
|
@@ -422,34 +428,9 @@ const encoders = {
|
|
|
422
428
|
elementType: 'div',
|
|
423
429
|
paragraphStyle: node.attrs.paragraphStyle || undefined,
|
|
424
430
|
}),
|
|
425
|
-
|
|
431
|
+
keyword_group: (node) => ({
|
|
426
432
|
type: node.attrs.type,
|
|
427
433
|
}),
|
|
428
|
-
keywords_section: (node, parent, path, priority) => ({
|
|
429
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
430
|
-
priority: priority.value++,
|
|
431
|
-
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
432
|
-
path: path.concat([node.attrs.id]),
|
|
433
|
-
elementIDs: childElements(node)
|
|
434
|
-
.map((childNode) => childNode.attrs.id)
|
|
435
|
-
.filter((id) => id),
|
|
436
|
-
}),
|
|
437
|
-
affiliations_section: (node, parent, path, priority) => ({
|
|
438
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
439
|
-
priority: priority.value++,
|
|
440
|
-
path: path.concat([node.attrs.id]),
|
|
441
|
-
elementIDs: childElements(node)
|
|
442
|
-
.map((childNode) => childNode.attrs.id)
|
|
443
|
-
.filter((id) => id),
|
|
444
|
-
}),
|
|
445
|
-
contributors_section: (node, parent, path, priority) => ({
|
|
446
|
-
category: (0, section_category_1.buildSectionCategory)(node),
|
|
447
|
-
priority: priority.value++,
|
|
448
|
-
path: path.concat([node.attrs.id]),
|
|
449
|
-
elementIDs: childElements(node)
|
|
450
|
-
.map((childNode) => childNode.attrs.id)
|
|
451
|
-
.filter((id) => id),
|
|
452
|
-
}),
|
|
453
434
|
missing_figure: (node) => ({
|
|
454
435
|
position: node.attrs.position || undefined,
|
|
455
436
|
}),
|
|
@@ -570,6 +551,14 @@ const modelFromNode = (node, parent, path, priority) => {
|
|
|
570
551
|
return { model, commentAnnotationsMap };
|
|
571
552
|
};
|
|
572
553
|
exports.modelFromNode = modelFromNode;
|
|
554
|
+
function isCoreSection(child) {
|
|
555
|
+
return (child.type === schema_1.schema.nodes.abstracts ||
|
|
556
|
+
child.type === schema_1.schema.nodes.body ||
|
|
557
|
+
child.type === schema_1.schema.nodes.backmatter ||
|
|
558
|
+
child.type === schema_1.schema.nodes.affiliations ||
|
|
559
|
+
child.type === schema_1.schema.nodes.contributors ||
|
|
560
|
+
child.type === schema_1.schema.nodes.keywords);
|
|
561
|
+
}
|
|
573
562
|
const encode = (node) => {
|
|
574
563
|
const models = new Map();
|
|
575
564
|
const priority = {
|
|
@@ -577,6 +566,10 @@ const encode = (node) => {
|
|
|
577
566
|
};
|
|
578
567
|
const placeholders = ['placeholder', 'placeholder_element'];
|
|
579
568
|
const addModel = (path, parent) => (child) => {
|
|
569
|
+
if (isCoreSection(child)) {
|
|
570
|
+
child.forEach(addModel([], child));
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
580
573
|
if (!child.attrs.id) {
|
|
581
574
|
return;
|
|
582
575
|
}
|
|
@@ -152,6 +152,7 @@ class HTMLTransformer {
|
|
|
152
152
|
this.buildFront = () => {
|
|
153
153
|
const manuscript = (0, project_bundle_1.findManuscript)(this.modelMap);
|
|
154
154
|
const journal = (0, project_bundle_1.findJournal)(this.modelMap);
|
|
155
|
+
const titles = (0, project_bundle_1.findTitles)(this.modelMap);
|
|
155
156
|
if (!manuscript) {
|
|
156
157
|
throw new Error('Manuscript not found in project modelMap');
|
|
157
158
|
}
|
|
@@ -170,14 +171,14 @@ class HTMLTransformer {
|
|
|
170
171
|
}
|
|
171
172
|
const articleMeta = this.document.createElement('div');
|
|
172
173
|
front.appendChild(articleMeta);
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
175
|
-
|
|
174
|
+
const title = this.document.createElement('h1');
|
|
175
|
+
if (titles.title) {
|
|
176
|
+
title.innerHTML = titles.title;
|
|
176
177
|
}
|
|
177
178
|
if (journal === null || journal === void 0 ? void 0 : journal.title) {
|
|
178
|
-
|
|
179
|
+
title.setAttribute('data-journal', journal.title);
|
|
179
180
|
}
|
|
180
|
-
articleMeta.appendChild(
|
|
181
|
+
articleMeta.appendChild(title);
|
|
181
182
|
if (manuscript.DOI) {
|
|
182
183
|
const articleID = this.document.createElement('article-id');
|
|
183
184
|
articleID.setAttribute('pub-id-type', 'doi');
|
|
@@ -38,6 +38,6 @@ exports.nodeNames = new Map([
|
|
|
38
38
|
[schema_1.schema.nodes.table_element, 'Table'],
|
|
39
39
|
[schema_1.schema.nodes.blockquote_element, 'Block Quote'],
|
|
40
40
|
[schema_1.schema.nodes.pullquote_element, 'Pull Quote'],
|
|
41
|
-
[schema_1.schema.nodes.
|
|
41
|
+
[schema_1.schema.nodes.keywords, 'Section'],
|
|
42
42
|
[schema_1.schema.nodes.toc_section, 'Section'],
|
|
43
43
|
]);
|
|
@@ -32,7 +32,7 @@ const textSnippet = (node, max = 100) => {
|
|
|
32
32
|
text += ' ';
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
|
-
return text.
|
|
35
|
+
return text.substring(0, max);
|
|
36
36
|
};
|
|
37
37
|
const snippetOfNodeType = (node, nodeType) => {
|
|
38
38
|
for (const child of (0, utils_1.iterateChildren)(node, true)) {
|
|
@@ -43,12 +43,14 @@ const snippetOfNodeType = (node, nodeType) => {
|
|
|
43
43
|
return null;
|
|
44
44
|
};
|
|
45
45
|
const nodeTitle = (node) => {
|
|
46
|
-
const nodes =
|
|
46
|
+
const nodes = schema_1.schema.nodes;
|
|
47
47
|
switch (node.type) {
|
|
48
|
+
case nodes.manuscript:
|
|
49
|
+
return snippetOfNodeType(node, nodes.title);
|
|
48
50
|
case nodes.section:
|
|
49
51
|
case nodes.bibliography_section:
|
|
50
52
|
case nodes.footnotes_section:
|
|
51
|
-
case nodes.
|
|
53
|
+
case nodes.keywords:
|
|
52
54
|
case nodes.toc_section:
|
|
53
55
|
case nodes.graphical_abstract_section:
|
|
54
56
|
return snippetOfNodeType(node, nodes.section_title);
|
|
@@ -72,9 +74,9 @@ const nodeTitle = (node) => {
|
|
|
72
74
|
};
|
|
73
75
|
exports.nodeTitle = nodeTitle;
|
|
74
76
|
const nodeTitlePlaceholder = (nodeType) => {
|
|
75
|
-
const nodes =
|
|
77
|
+
const nodes = schema_1.schema.nodes;
|
|
76
78
|
switch (nodeType) {
|
|
77
|
-
case nodes.
|
|
79
|
+
case nodes.manuscript:
|
|
78
80
|
return 'Untitled Manuscript';
|
|
79
81
|
case nodes.section:
|
|
80
82
|
return 'Untitled Section';
|
|
@@ -19,6 +19,9 @@ exports.isNodeType = exports.isSectionNodeType = exports.isElementNodeType = exp
|
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
const schema_1 = require("../schema");
|
|
21
21
|
exports.nodeTypesMap = new Map([
|
|
22
|
+
[schema_1.schema.nodes.abstracts, json_schema_1.ObjectTypes.Section],
|
|
23
|
+
[schema_1.schema.nodes.body, json_schema_1.ObjectTypes.Section],
|
|
24
|
+
[schema_1.schema.nodes.backmatter, json_schema_1.ObjectTypes.Section],
|
|
22
25
|
[schema_1.schema.nodes.comment, json_schema_1.ObjectTypes.CommentAnnotation],
|
|
23
26
|
[schema_1.schema.nodes.bibliography_item, json_schema_1.ObjectTypes.BibliographyItem],
|
|
24
27
|
[schema_1.schema.nodes.bibliography_element, json_schema_1.ObjectTypes.BibliographyElement],
|
|
@@ -40,8 +43,8 @@ exports.nodeTypesMap = new Map([
|
|
|
40
43
|
[schema_1.schema.nodes.inline_equation, json_schema_1.ObjectTypes.InlineMathFragment],
|
|
41
44
|
[schema_1.schema.nodes.keyword, json_schema_1.ObjectTypes.Keyword],
|
|
42
45
|
[schema_1.schema.nodes.keywords_element, json_schema_1.ObjectTypes.KeywordsElement],
|
|
43
|
-
[schema_1.schema.nodes.
|
|
44
|
-
[schema_1.schema.nodes.
|
|
46
|
+
[schema_1.schema.nodes.keywords, json_schema_1.ObjectTypes.Section],
|
|
47
|
+
[schema_1.schema.nodes.keyword_group, json_schema_1.ObjectTypes.KeywordGroup],
|
|
45
48
|
[schema_1.schema.nodes.listing, json_schema_1.ObjectTypes.Listing],
|
|
46
49
|
[schema_1.schema.nodes.listing_element, json_schema_1.ObjectTypes.ListingElement],
|
|
47
50
|
[schema_1.schema.nodes.manuscript, json_schema_1.ObjectTypes.Manuscript],
|
|
@@ -57,8 +60,9 @@ exports.nodeTypesMap = new Map([
|
|
|
57
60
|
[schema_1.schema.nodes.affiliation, json_schema_1.ObjectTypes.Affiliation],
|
|
58
61
|
[schema_1.schema.nodes.contributor, json_schema_1.ObjectTypes.Contributor],
|
|
59
62
|
[schema_1.schema.nodes.table_element_footer, json_schema_1.ObjectTypes.TableElementFooter],
|
|
60
|
-
[schema_1.schema.nodes.
|
|
61
|
-
[schema_1.schema.nodes.
|
|
63
|
+
[schema_1.schema.nodes.contributors, json_schema_1.ObjectTypes.Section],
|
|
64
|
+
[schema_1.schema.nodes.affiliations, json_schema_1.ObjectTypes.Section],
|
|
65
|
+
[schema_1.schema.nodes.title, json_schema_1.ObjectTypes.Titles],
|
|
62
66
|
]);
|
|
63
67
|
const isExecutableNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_EXECUTABLE);
|
|
64
68
|
exports.isExecutableNodeType = isExecutableNodeType;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.findManuscriptById = exports.findManuscriptModelByType = exports.findJournal = exports.findManuscript = exports.parseProjectBundle = void 0;
|
|
18
|
+
exports.findTitles = exports.findManuscriptById = exports.findManuscriptModelByType = exports.findJournal = exports.findManuscript = exports.parseProjectBundle = void 0;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
const decode_1 = require("./decode");
|
|
21
21
|
const object_types_1 = require("./object-types");
|
|
@@ -71,3 +71,24 @@ const findManuscriptById = (modelMap, manuscriptID) => {
|
|
|
71
71
|
throw new Error(`There is no manuscript found for the following _id (${manuscriptID})`);
|
|
72
72
|
};
|
|
73
73
|
exports.findManuscriptById = findManuscriptById;
|
|
74
|
+
const isTitle = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Titles);
|
|
75
|
+
const findTitles = (modelMap) => {
|
|
76
|
+
for (const model of modelMap.values()) {
|
|
77
|
+
if (isTitle(model)) {
|
|
78
|
+
return model;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const defaultTitle = {
|
|
82
|
+
_id: 'MPTitles:8EB79C14-9F61-483A-902F-A0B8EF5973C1',
|
|
83
|
+
createdAt: 1538472121.690101,
|
|
84
|
+
updatedAt: 1538472121.690101,
|
|
85
|
+
objectType: 'MPTitles',
|
|
86
|
+
title: 'main title',
|
|
87
|
+
subtitle: 'subtitle',
|
|
88
|
+
runningTitle: 'running title',
|
|
89
|
+
manuscriptID: 'MPManuscript:E3830344-E77B-42BA-BD77-3E95489712A0',
|
|
90
|
+
containerID: 'MPProject:1',
|
|
91
|
+
};
|
|
92
|
+
return defaultTitle;
|
|
93
|
+
};
|
|
94
|
+
exports.findTitles = findTitles;
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.chooseSecType = exports.chooseJatsFnType = exports.buildSectionCategory = exports.guessSectionCategory = exports.chooseSectionLableName = exports.chooseSectionNodeType = exports.isAnySectionNode = exports.getCoreSectionTitles = void 0;
|
|
18
|
+
exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.chooseCoreSectionBySection = exports.chooseSecType = exports.chooseJatsFnType = exports.buildSectionCategory = exports.guessSectionCategory = exports.chooseSectionLableName = exports.chooseSectionNodeType = exports.isAnySectionNode = exports.getCoreSectionTitles = void 0;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
const core_section_categories_1 = require("../lib/core-section-categories");
|
|
21
21
|
const schema_1 = require("../schema");
|
|
22
22
|
const sectionNodeTypes = [
|
|
23
23
|
schema_1.schema.nodes.bibliography_section,
|
|
24
24
|
schema_1.schema.nodes.footnotes_section,
|
|
25
|
-
schema_1.schema.nodes.
|
|
25
|
+
schema_1.schema.nodes.keywords,
|
|
26
26
|
schema_1.schema.nodes.section,
|
|
27
27
|
schema_1.schema.nodes.toc_section,
|
|
28
28
|
];
|
|
@@ -45,11 +45,11 @@ const chooseSectionNodeType = (category) => {
|
|
|
45
45
|
case 'MPSectionCategory:endnotes':
|
|
46
46
|
return schema_1.schema.nodes.footnotes_section;
|
|
47
47
|
case 'MPSectionCategory:keywords':
|
|
48
|
-
return schema_1.schema.nodes.
|
|
48
|
+
return schema_1.schema.nodes.keywords;
|
|
49
49
|
case 'MPSectionCategory:affiliations':
|
|
50
|
-
return schema_1.schema.nodes.
|
|
50
|
+
return schema_1.schema.nodes.affiliations;
|
|
51
51
|
case 'MPSectionCategory:contributors':
|
|
52
|
-
return schema_1.schema.nodes.
|
|
52
|
+
return schema_1.schema.nodes.contributors;
|
|
53
53
|
case 'MPSectionCategory:toc':
|
|
54
54
|
return schema_1.schema.nodes.toc_section;
|
|
55
55
|
default:
|
|
@@ -90,15 +90,15 @@ const buildSectionCategory = (node) => {
|
|
|
90
90
|
return 'MPSectionCategory:bibliography';
|
|
91
91
|
case schema_1.schema.nodes.footnotes_section:
|
|
92
92
|
return 'MPSectionCategory:endnotes';
|
|
93
|
-
case schema_1.schema.nodes.
|
|
93
|
+
case schema_1.schema.nodes.keywords:
|
|
94
94
|
return 'MPSectionCategory:keywords';
|
|
95
95
|
case schema_1.schema.nodes.toc_section:
|
|
96
96
|
return 'MPSectionCategory:toc';
|
|
97
97
|
case schema_1.schema.nodes.graphical_abstract_section:
|
|
98
98
|
return 'MPSectionCategory:abstract-graphical';
|
|
99
|
-
case schema_1.schema.nodes.
|
|
99
|
+
case schema_1.schema.nodes.affiliations:
|
|
100
100
|
return 'MPSectionCategory:affiliations';
|
|
101
|
-
case schema_1.schema.nodes.
|
|
101
|
+
case schema_1.schema.nodes.contributors:
|
|
102
102
|
return 'MPSectionCategory:contributors';
|
|
103
103
|
default:
|
|
104
104
|
return node.attrs.category || undefined;
|
|
@@ -128,6 +128,33 @@ const chooseSecType = (sectionCategory) => {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
exports.chooseSecType = chooseSecType;
|
|
131
|
+
const chooseCoreSectionBySection = (section) => {
|
|
132
|
+
switch (section) {
|
|
133
|
+
case 'MPSectionCategory:abstract':
|
|
134
|
+
case 'MPSectionCategory:abstract-teaser':
|
|
135
|
+
case 'MPSectionCategory:abstract-graphical':
|
|
136
|
+
return 'MPSectionCategory:abstracts';
|
|
137
|
+
case 'MPSectionCategory:acknowledgement':
|
|
138
|
+
case 'MPSectionCategory:availability':
|
|
139
|
+
case 'MPSectionCategory:conclusions':
|
|
140
|
+
case 'MPSectionCategory:bibliography':
|
|
141
|
+
case 'MPSectionCategory:discussion':
|
|
142
|
+
case 'MPSectionCategory:endnotes':
|
|
143
|
+
case 'MPSectionCategory:appendices':
|
|
144
|
+
case 'MPSectionCategory:competing-interests':
|
|
145
|
+
case 'MPSectionCategory:con':
|
|
146
|
+
case 'MPSectionCategory:deceased':
|
|
147
|
+
case 'MPSectionCategory:ethics-statement':
|
|
148
|
+
case 'MPSectionCategory:financial-disclosure':
|
|
149
|
+
case 'MPSectionCategory:supplementary-material':
|
|
150
|
+
case 'MPSectionCategory:supported-by':
|
|
151
|
+
case 'MPSectionCategory:abbreviations':
|
|
152
|
+
case 'MPSectionCategory:results':
|
|
153
|
+
return 'MPSectionCategory:backmatter';
|
|
154
|
+
}
|
|
155
|
+
return 'MPSectionCategory:body';
|
|
156
|
+
};
|
|
157
|
+
exports.chooseCoreSectionBySection = chooseCoreSectionBySection;
|
|
131
158
|
const chooseSectionCategoryByType = (secType) => {
|
|
132
159
|
switch (secType) {
|
|
133
160
|
case 'abstract':
|