@manuscripts/transform 1.5.8-LEAN-3030 → 1.5.8-LEAN-3030-2
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/lib/utils.js +1 -21
- package/dist/cjs/schema/nodes/cross_reference.js +1 -1
- package/dist/cjs/transformer/decode.js +27 -41
- package/dist/cjs/transformer/labels.js +3 -17
- package/dist/cjs/transformer/section-category.js +18 -36
- package/dist/es/lib/utils.js +0 -18
- package/dist/es/schema/nodes/cross_reference.js +1 -1
- package/dist/es/transformer/decode.js +28 -42
- package/dist/es/transformer/labels.js +3 -17
- package/dist/es/transformer/section-category.js +16 -34
- package/dist/types/lib/section-group-type.d.ts +5 -13
- package/dist/types/lib/utils.d.ts +0 -2
- package/dist/types/transformer/decode.d.ts +1 -3
- package/dist/types/transformer/section-category.d.ts +4 -3
- package/package.json +1 -1
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.modelsEqual = exports.
|
|
18
|
+
exports.modelsEqual = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
|
|
19
19
|
const bibliography_section_1 = require("../schema/nodes/bibliography_section");
|
|
20
20
|
const graphical_abstract_section_1 = require("../schema/nodes/graphical_abstract_section");
|
|
21
21
|
function* iterateChildren(node, recurse = false) {
|
|
@@ -61,17 +61,6 @@ const isInBibliographySection = ($pos) => {
|
|
|
61
61
|
return false;
|
|
62
62
|
};
|
|
63
63
|
exports.isInBibliographySection = isInBibliographySection;
|
|
64
|
-
const isAbstractsSectionNode = (node) => node.attrs.category === 'MPSectionCategory:abstracts';
|
|
65
|
-
const isInAbstractsSection = ($pos) => {
|
|
66
|
-
for (let i = $pos.depth; i > 0; i--) {
|
|
67
|
-
const node = $pos.node(i);
|
|
68
|
-
if (isAbstractsSectionNode(node)) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return false;
|
|
73
|
-
};
|
|
74
|
-
exports.isInAbstractsSection = isInAbstractsSection;
|
|
75
64
|
const findParentNodeClosestToPos = ($pos, predicate) => {
|
|
76
65
|
for (let i = $pos.depth; i > 0; i--) {
|
|
77
66
|
const node = $pos.node(i);
|
|
@@ -94,15 +83,6 @@ const getTrimmedTextContent = (node, querySelector) => {
|
|
|
94
83
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
95
84
|
};
|
|
96
85
|
exports.getTrimmedTextContent = getTrimmedTextContent;
|
|
97
|
-
const groupBy = (list, getKey) => list.reduce((previous, currentItem) => {
|
|
98
|
-
const group = getKey(currentItem);
|
|
99
|
-
if (!previous[group]) {
|
|
100
|
-
previous[group] = [];
|
|
101
|
-
}
|
|
102
|
-
previous[group].push(currentItem);
|
|
103
|
-
return previous;
|
|
104
|
-
}, {});
|
|
105
|
-
exports.groupBy = groupBy;
|
|
106
86
|
function modelsEqual(model, model2) {
|
|
107
87
|
for (const v in model) {
|
|
108
88
|
for (const v2 in model2) {
|
|
@@ -34,7 +34,7 @@ exports.crossReference = {
|
|
|
34
34
|
var _a;
|
|
35
35
|
const dom = p;
|
|
36
36
|
return {
|
|
37
|
-
|
|
37
|
+
rids: ((_a = dom.getAttribute('data-reference-id')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
|
|
38
38
|
label: dom.textContent,
|
|
39
39
|
};
|
|
40
40
|
},
|
|
@@ -34,11 +34,10 @@ 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
|
|
37
|
+
const section_group_type_1 = require("../lib/section-group-type");
|
|
38
38
|
const schema_1 = require("../schema");
|
|
39
39
|
const builders_1 = require("./builders");
|
|
40
40
|
const highlight_markers_1 = require("./highlight-markers");
|
|
41
|
-
const id_1 = require("./id");
|
|
42
41
|
const object_types_1 = require("./object-types");
|
|
43
42
|
const section_category_1 = require("./section-category");
|
|
44
43
|
const timestamp_1 = require("./timestamp");
|
|
@@ -103,45 +102,32 @@ class Decoder {
|
|
|
103
102
|
...this.comments.values(),
|
|
104
103
|
]);
|
|
105
104
|
}
|
|
106
|
-
|
|
107
|
-
let
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const sectionGroups = (0, utils_1.groupBy)(rootSections, (sec) => {
|
|
114
|
-
var _a;
|
|
115
|
-
return (0, section_category_1.chooseCoreSectionBySection)((_a = sec.category) !== null && _a !== void 0 ? _a : '');
|
|
116
|
-
});
|
|
117
|
-
this.ensureCoreSectionsExist(sectionGroups);
|
|
118
|
-
const absSectionNode = sectionGroups['MPSectionCategory:abstracts'].map((e) => this.decode(e));
|
|
119
|
-
const bodySectionNodes = sectionGroups['MPSectionCategory:body'].map((e) => this.decode(e));
|
|
120
|
-
const backmatterSectionNodes = sectionGroups['MPSectionCategory:backmatter'].map(e => this.decode(e));
|
|
121
|
-
const abstractCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.abstracts, absSectionNode);
|
|
122
|
-
const bodyCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.body, bodySectionNodes);
|
|
123
|
-
const backmatterCoreSectionNodes = this.createAndFill(schema_1.schema.nodes.backmatter, backmatterSectionNodes);
|
|
124
|
-
return {
|
|
125
|
-
abstracts: abstractCoreSectionNodes,
|
|
126
|
-
body: bodyCoreSectionNodes,
|
|
127
|
-
backmatter: backmatterCoreSectionNodes,
|
|
105
|
+
createContentSections() {
|
|
106
|
+
let sections = getSections(this.modelMap);
|
|
107
|
+
sections = this.addGeneratedLabels(sections);
|
|
108
|
+
const groups = {
|
|
109
|
+
abstracts: [],
|
|
110
|
+
body: [],
|
|
111
|
+
backmatter: [],
|
|
128
112
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
coreSections['MPSectionCategory:backmatter'] = [];
|
|
113
|
+
for (const section of sections) {
|
|
114
|
+
if (section.path.length > 1) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const category = section.category;
|
|
118
|
+
const group = category
|
|
119
|
+
? (0, section_category_1.getSectionGroupType)(category)
|
|
120
|
+
: section_group_type_1.bodyType;
|
|
121
|
+
groups[group._id].push(this.decode(section));
|
|
139
122
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
123
|
+
const abstracts = schema_1.schema.nodes.abstracts.createAndFill({}, groups[section_group_type_1.abstractsType._id]);
|
|
124
|
+
const body = schema_1.schema.nodes.body.createAndFill({}, groups[section_group_type_1.bodyType._id]);
|
|
125
|
+
const backmatter = schema_1.schema.nodes.backmatter.createAndFill({}, groups[section_group_type_1.backmatterType._id]);
|
|
126
|
+
return {
|
|
127
|
+
abstracts,
|
|
128
|
+
body,
|
|
129
|
+
backmatter,
|
|
130
|
+
};
|
|
145
131
|
}
|
|
146
132
|
createCommentNodes(model) {
|
|
147
133
|
const comments = [];
|
|
@@ -514,7 +500,7 @@ class Decoder {
|
|
|
514
500
|
}
|
|
515
501
|
}
|
|
516
502
|
}
|
|
517
|
-
const elementNodes = elements.map(e => this.decode(e));
|
|
503
|
+
const elementNodes = elements.map((e) => this.decode(e));
|
|
518
504
|
const sectionTitle = 'section_title';
|
|
519
505
|
const sectionTitleNode = model.title
|
|
520
506
|
? this.parseContents(model.title, 'h1', this.getComments(model), {
|
|
@@ -661,7 +647,7 @@ class Decoder {
|
|
|
661
647
|
const contributors = this.createContributorsNode();
|
|
662
648
|
const affiliations = this.createAffiliationsNode();
|
|
663
649
|
const keywords = this.createKeywordsNode();
|
|
664
|
-
const { abstracts, body, backmatter } = this.
|
|
650
|
+
const { abstracts, body, backmatter } = this.createContentSections();
|
|
665
651
|
const comments = this.createCommentsNode();
|
|
666
652
|
const contents = [
|
|
667
653
|
title,
|
|
@@ -30,6 +30,7 @@ const labelProperties = new Map([
|
|
|
30
30
|
[schema_1.schema.nodes.equation_element, 'equationElementLabel'],
|
|
31
31
|
[schema_1.schema.nodes.listing_element, 'listingElementLabel'],
|
|
32
32
|
]);
|
|
33
|
+
const excludedTypes = [schema_1.schema.nodes.graphical_abstract_section];
|
|
33
34
|
const chooseLabel = (nodeType, manuscript) => {
|
|
34
35
|
const labelProperty = labelProperties.get(nodeType);
|
|
35
36
|
if (labelProperty) {
|
|
@@ -54,25 +55,10 @@ const buildTargets = (fragment, manuscript) => {
|
|
|
54
55
|
return `${counter.label} ${counter.index}`;
|
|
55
56
|
};
|
|
56
57
|
const targets = new Map();
|
|
57
|
-
|
|
58
|
-
fragment.forEach((node) => {
|
|
59
|
-
if (node.attrs.category === 'MPSectionCategory:abstracts') {
|
|
60
|
-
node.forEach((child) => {
|
|
61
|
-
if (child.type === node.type.schema.nodes.graphical_abstract_section) {
|
|
62
|
-
child.forEach((item) => {
|
|
63
|
-
if (item.type === node.type.schema.nodes.figure_element) {
|
|
64
|
-
figures.push(item.attrs.id);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
fragment.descendants((node) => {
|
|
58
|
+
fragment.descendants((node, pos, parent) => {
|
|
72
59
|
var _a;
|
|
73
60
|
if (node.type.name in counters) {
|
|
74
|
-
|
|
75
|
-
if (isInGraphicalAbstract) {
|
|
61
|
+
if (parent && excludedTypes.includes(parent.type)) {
|
|
76
62
|
return;
|
|
77
63
|
}
|
|
78
64
|
const label = buildLabel(node.type);
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.
|
|
18
|
+
exports.chooseSectionCategoryFromTitle = exports.chooseSectionCategory = exports.chooseSectionCategoryByType = exports.getSectionGroupType = exports.chooseSecType = exports.chooseJatsFnType = exports.buildSectionCategory = exports.guessSectionCategory = exports.chooseSectionLableName = exports.chooseSectionNodeType = exports.isAnySectionNode = void 0;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
|
+
const section_group_type_1 = require("../lib/section-group-type");
|
|
20
21
|
const schema_1 = require("../schema");
|
|
21
22
|
const sectionNodeTypes = [
|
|
22
23
|
schema_1.schema.nodes.bibliography_section,
|
|
@@ -37,10 +38,6 @@ const chooseSectionNodeType = (category) => {
|
|
|
37
38
|
return schema_1.schema.nodes.footnotes_section;
|
|
38
39
|
case 'MPSectionCategory:keywords':
|
|
39
40
|
return schema_1.schema.nodes.keywords;
|
|
40
|
-
case 'MPSectionCategory:affiliations':
|
|
41
|
-
return schema_1.schema.nodes.affiliations;
|
|
42
|
-
case 'MPSectionCategory:contributors':
|
|
43
|
-
return schema_1.schema.nodes.contributors;
|
|
44
41
|
case 'MPSectionCategory:toc':
|
|
45
42
|
return schema_1.schema.nodes.toc_section;
|
|
46
43
|
default:
|
|
@@ -87,10 +84,6 @@ const buildSectionCategory = (node) => {
|
|
|
87
84
|
return 'MPSectionCategory:toc';
|
|
88
85
|
case schema_1.schema.nodes.graphical_abstract_section:
|
|
89
86
|
return 'MPSectionCategory:abstract-graphical';
|
|
90
|
-
case schema_1.schema.nodes.affiliations:
|
|
91
|
-
return 'MPSectionCategory:affiliations';
|
|
92
|
-
case schema_1.schema.nodes.contributors:
|
|
93
|
-
return 'MPSectionCategory:contributors';
|
|
94
87
|
default:
|
|
95
88
|
return node.attrs.category || undefined;
|
|
96
89
|
}
|
|
@@ -119,33 +112,32 @@ const chooseSecType = (sectionCategory) => {
|
|
|
119
112
|
}
|
|
120
113
|
};
|
|
121
114
|
exports.chooseSecType = chooseSecType;
|
|
122
|
-
const
|
|
123
|
-
switch (
|
|
115
|
+
const getSectionGroupType = (category) => {
|
|
116
|
+
switch (category) {
|
|
124
117
|
case 'MPSectionCategory:abstract':
|
|
125
|
-
case 'MPSectionCategory:abstract-teaser':
|
|
126
118
|
case 'MPSectionCategory:abstract-graphical':
|
|
127
|
-
return
|
|
128
|
-
case 'MPSectionCategory:acknowledgement':
|
|
129
|
-
case 'MPSectionCategory:availability':
|
|
130
|
-
case 'MPSectionCategory:conclusions':
|
|
131
|
-
case 'MPSectionCategory:bibliography':
|
|
132
|
-
case 'MPSectionCategory:discussion':
|
|
133
|
-
case 'MPSectionCategory:endnotes':
|
|
134
|
-
case 'MPSectionCategory:appendices':
|
|
119
|
+
return section_group_type_1.abstractsType;
|
|
135
120
|
case 'MPSectionCategory:competing-interests':
|
|
136
121
|
case 'MPSectionCategory:con':
|
|
137
|
-
case 'MPSectionCategory:deceased':
|
|
138
122
|
case 'MPSectionCategory:ethics-statement':
|
|
139
123
|
case 'MPSectionCategory:financial-disclosure':
|
|
140
124
|
case 'MPSectionCategory:supplementary-material':
|
|
141
125
|
case 'MPSectionCategory:supported-by':
|
|
142
|
-
case 'MPSectionCategory:
|
|
143
|
-
case 'MPSectionCategory:
|
|
144
|
-
|
|
126
|
+
case 'MPSectionCategory:availability':
|
|
127
|
+
case 'MPSectionCategory:acknowledgement':
|
|
128
|
+
case 'MPSectionCategory:endnotes':
|
|
129
|
+
case 'MPSectionCategory:bibliography':
|
|
130
|
+
case 'MPSectionCategory:appendices':
|
|
131
|
+
case 'MPSectionCategory:deceased':
|
|
132
|
+
case 'MPSectionCategory:equal':
|
|
133
|
+
case 'MPSectionCategory:present-address':
|
|
134
|
+
case 'MPSectionCategory:presented-at':
|
|
135
|
+
case 'MPSectionCategory:previously-at':
|
|
136
|
+
return section_group_type_1.backmatterType;
|
|
145
137
|
}
|
|
146
|
-
return
|
|
138
|
+
return section_group_type_1.bodyType;
|
|
147
139
|
};
|
|
148
|
-
exports.
|
|
140
|
+
exports.getSectionGroupType = getSectionGroupType;
|
|
149
141
|
const chooseSectionCategoryByType = (secType) => {
|
|
150
142
|
switch (secType) {
|
|
151
143
|
case 'abstract':
|
|
@@ -205,16 +197,6 @@ const chooseSectionCategoryByType = (secType) => {
|
|
|
205
197
|
return 'MPSectionCategory:supported-by';
|
|
206
198
|
case 'ethics-statement':
|
|
207
199
|
return 'MPSectionCategory:ethics-statement';
|
|
208
|
-
case 'body':
|
|
209
|
-
return 'MPSectionCategory:body';
|
|
210
|
-
case 'backmatter':
|
|
211
|
-
return 'MPSectionCategory:backmatter';
|
|
212
|
-
case 'abstracts':
|
|
213
|
-
return 'MPSectionCategory:abstracts';
|
|
214
|
-
case 'affiliations':
|
|
215
|
-
return 'MPSectionCategory:affiliations';
|
|
216
|
-
case 'contributors':
|
|
217
|
-
return 'MPSectionCategory:contributors';
|
|
218
200
|
default:
|
|
219
201
|
return undefined;
|
|
220
202
|
}
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -54,16 +54,6 @@ export const isInBibliographySection = ($pos) => {
|
|
|
54
54
|
}
|
|
55
55
|
return false;
|
|
56
56
|
};
|
|
57
|
-
const isAbstractsSectionNode = (node) => node.attrs.category === 'MPSectionCategory:abstracts';
|
|
58
|
-
export const isInAbstractsSection = ($pos) => {
|
|
59
|
-
for (let i = $pos.depth; i > 0; i--) {
|
|
60
|
-
const node = $pos.node(i);
|
|
61
|
-
if (isAbstractsSectionNode(node)) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
};
|
|
67
57
|
export const findParentNodeClosestToPos = ($pos, predicate) => {
|
|
68
58
|
for (let i = $pos.depth; i > 0; i--) {
|
|
69
59
|
const node = $pos.node(i);
|
|
@@ -84,14 +74,6 @@ export const getTrimmedTextContent = (node, querySelector) => {
|
|
|
84
74
|
}
|
|
85
75
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
86
76
|
};
|
|
87
|
-
export const groupBy = (list, getKey) => list.reduce((previous, currentItem) => {
|
|
88
|
-
const group = getKey(currentItem);
|
|
89
|
-
if (!previous[group]) {
|
|
90
|
-
previous[group] = [];
|
|
91
|
-
}
|
|
92
|
-
previous[group].push(currentItem);
|
|
93
|
-
return previous;
|
|
94
|
-
}, {});
|
|
95
77
|
export function modelsEqual(model, model2) {
|
|
96
78
|
for (const v in model) {
|
|
97
79
|
for (const v2 in model2) {
|
|
@@ -31,7 +31,7 @@ export const crossReference = {
|
|
|
31
31
|
var _a;
|
|
32
32
|
const dom = p;
|
|
33
33
|
return {
|
|
34
|
-
|
|
34
|
+
rids: ((_a = dom.getAttribute('data-reference-id')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
|
|
35
35
|
label: dom.textContent,
|
|
36
36
|
};
|
|
37
37
|
},
|
|
@@ -28,13 +28,12 @@ import { ObjectTypes, } from '@manuscripts/json-schema';
|
|
|
28
28
|
import debug from 'debug';
|
|
29
29
|
import { DOMParser } from 'prosemirror-model';
|
|
30
30
|
import { MissingElement } from '../errors';
|
|
31
|
-
import {
|
|
31
|
+
import { abstractsType, backmatterType, bodyType, } from '../lib/section-group-type';
|
|
32
32
|
import { schema, } from '../schema';
|
|
33
33
|
import { buildTitles } from './builders';
|
|
34
34
|
import { insertHighlightMarkers } from './highlight-markers';
|
|
35
|
-
import { generateNodeID } from './id';
|
|
36
35
|
import { ExtraObjectTypes, hasObjectType, isCommentAnnotation, isManuscript, } from './object-types';
|
|
37
|
-
import {
|
|
36
|
+
import { chooseSectionLableName, chooseSectionNodeType, chooseSecType, getSectionGroupType, guessSectionCategory, } from './section-category';
|
|
38
37
|
import { timestamp } from './timestamp';
|
|
39
38
|
const warn = debug('manuscripts-transform');
|
|
40
39
|
const parser = DOMParser.fromSchema(schema);
|
|
@@ -94,45 +93,32 @@ export class Decoder {
|
|
|
94
93
|
...this.comments.values(),
|
|
95
94
|
]);
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
let
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const sectionGroups = groupBy(rootSections, (sec) => {
|
|
105
|
-
var _a;
|
|
106
|
-
return chooseCoreSectionBySection((_a = sec.category) !== null && _a !== void 0 ? _a : '');
|
|
107
|
-
});
|
|
108
|
-
this.ensureCoreSectionsExist(sectionGroups);
|
|
109
|
-
const absSectionNode = sectionGroups['MPSectionCategory:abstracts'].map((e) => this.decode(e));
|
|
110
|
-
const bodySectionNodes = sectionGroups['MPSectionCategory:body'].map((e) => this.decode(e));
|
|
111
|
-
const backmatterSectionNodes = sectionGroups['MPSectionCategory:backmatter'].map(e => this.decode(e));
|
|
112
|
-
const abstractCoreSectionNodes = this.createAndFill(schema.nodes.abstracts, absSectionNode);
|
|
113
|
-
const bodyCoreSectionNodes = this.createAndFill(schema.nodes.body, bodySectionNodes);
|
|
114
|
-
const backmatterCoreSectionNodes = this.createAndFill(schema.nodes.backmatter, backmatterSectionNodes);
|
|
115
|
-
return {
|
|
116
|
-
abstracts: abstractCoreSectionNodes,
|
|
117
|
-
body: bodyCoreSectionNodes,
|
|
118
|
-
backmatter: backmatterCoreSectionNodes,
|
|
96
|
+
createContentSections() {
|
|
97
|
+
let sections = getSections(this.modelMap);
|
|
98
|
+
sections = this.addGeneratedLabels(sections);
|
|
99
|
+
const groups = {
|
|
100
|
+
abstracts: [],
|
|
101
|
+
body: [],
|
|
102
|
+
backmatter: [],
|
|
119
103
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
coreSections['MPSectionCategory:backmatter'] = [];
|
|
104
|
+
for (const section of sections) {
|
|
105
|
+
if (section.path.length > 1) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const category = section.category;
|
|
109
|
+
const group = category
|
|
110
|
+
? getSectionGroupType(category)
|
|
111
|
+
: bodyType;
|
|
112
|
+
groups[group._id].push(this.decode(section));
|
|
130
113
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
114
|
+
const abstracts = schema.nodes.abstracts.createAndFill({}, groups[abstractsType._id]);
|
|
115
|
+
const body = schema.nodes.body.createAndFill({}, groups[bodyType._id]);
|
|
116
|
+
const backmatter = schema.nodes.backmatter.createAndFill({}, groups[backmatterType._id]);
|
|
117
|
+
return {
|
|
118
|
+
abstracts,
|
|
119
|
+
body,
|
|
120
|
+
backmatter,
|
|
121
|
+
};
|
|
136
122
|
}
|
|
137
123
|
createCommentNodes(model) {
|
|
138
124
|
const comments = [];
|
|
@@ -505,7 +491,7 @@ export class Decoder {
|
|
|
505
491
|
}
|
|
506
492
|
}
|
|
507
493
|
}
|
|
508
|
-
const elementNodes = elements.map(e => this.decode(e));
|
|
494
|
+
const elementNodes = elements.map((e) => this.decode(e));
|
|
509
495
|
const sectionTitle = 'section_title';
|
|
510
496
|
const sectionTitleNode = model.title
|
|
511
497
|
? this.parseContents(model.title, 'h1', this.getComments(model), {
|
|
@@ -652,7 +638,7 @@ export class Decoder {
|
|
|
652
638
|
const contributors = this.createContributorsNode();
|
|
653
639
|
const affiliations = this.createAffiliationsNode();
|
|
654
640
|
const keywords = this.createKeywordsNode();
|
|
655
|
-
const { abstracts, body, backmatter } = this.
|
|
641
|
+
const { abstracts, body, backmatter } = this.createContentSections();
|
|
656
642
|
const comments = this.createCommentsNode();
|
|
657
643
|
const contents = [
|
|
658
644
|
title,
|
|
@@ -27,6 +27,7 @@ const labelProperties = new Map([
|
|
|
27
27
|
[schema.nodes.equation_element, 'equationElementLabel'],
|
|
28
28
|
[schema.nodes.listing_element, 'listingElementLabel'],
|
|
29
29
|
]);
|
|
30
|
+
const excludedTypes = [schema.nodes.graphical_abstract_section];
|
|
30
31
|
const chooseLabel = (nodeType, manuscript) => {
|
|
31
32
|
const labelProperty = labelProperties.get(nodeType);
|
|
32
33
|
if (labelProperty) {
|
|
@@ -51,25 +52,10 @@ export const buildTargets = (fragment, manuscript) => {
|
|
|
51
52
|
return `${counter.label} ${counter.index}`;
|
|
52
53
|
};
|
|
53
54
|
const targets = new Map();
|
|
54
|
-
|
|
55
|
-
fragment.forEach((node) => {
|
|
56
|
-
if (node.attrs.category === 'MPSectionCategory:abstracts') {
|
|
57
|
-
node.forEach((child) => {
|
|
58
|
-
if (child.type === node.type.schema.nodes.graphical_abstract_section) {
|
|
59
|
-
child.forEach((item) => {
|
|
60
|
-
if (item.type === node.type.schema.nodes.figure_element) {
|
|
61
|
-
figures.push(item.attrs.id);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
fragment.descendants((node) => {
|
|
55
|
+
fragment.descendants((node, pos, parent) => {
|
|
69
56
|
var _a;
|
|
70
57
|
if (node.type.name in counters) {
|
|
71
|
-
|
|
72
|
-
if (isInGraphicalAbstract) {
|
|
58
|
+
if (parent && excludedTypes.includes(parent.type)) {
|
|
73
59
|
return;
|
|
74
60
|
}
|
|
75
61
|
const label = buildLabel(node.type);
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
|
+
import { abstractsType, backmatterType, bodyType, } from '../lib/section-group-type';
|
|
17
18
|
import { schema } from '../schema';
|
|
18
19
|
const sectionNodeTypes = [
|
|
19
20
|
schema.nodes.bibliography_section,
|
|
@@ -33,10 +34,6 @@ export const chooseSectionNodeType = (category) => {
|
|
|
33
34
|
return schema.nodes.footnotes_section;
|
|
34
35
|
case 'MPSectionCategory:keywords':
|
|
35
36
|
return schema.nodes.keywords;
|
|
36
|
-
case 'MPSectionCategory:affiliations':
|
|
37
|
-
return schema.nodes.affiliations;
|
|
38
|
-
case 'MPSectionCategory:contributors':
|
|
39
|
-
return schema.nodes.contributors;
|
|
40
37
|
case 'MPSectionCategory:toc':
|
|
41
38
|
return schema.nodes.toc_section;
|
|
42
39
|
default:
|
|
@@ -80,10 +77,6 @@ export const buildSectionCategory = (node) => {
|
|
|
80
77
|
return 'MPSectionCategory:toc';
|
|
81
78
|
case schema.nodes.graphical_abstract_section:
|
|
82
79
|
return 'MPSectionCategory:abstract-graphical';
|
|
83
|
-
case schema.nodes.affiliations:
|
|
84
|
-
return 'MPSectionCategory:affiliations';
|
|
85
|
-
case schema.nodes.contributors:
|
|
86
|
-
return 'MPSectionCategory:contributors';
|
|
87
80
|
default:
|
|
88
81
|
return node.attrs.category || undefined;
|
|
89
82
|
}
|
|
@@ -109,31 +102,30 @@ export const chooseSecType = (sectionCategory) => {
|
|
|
109
102
|
return suffix;
|
|
110
103
|
}
|
|
111
104
|
};
|
|
112
|
-
export const
|
|
113
|
-
switch (
|
|
105
|
+
export const getSectionGroupType = (category) => {
|
|
106
|
+
switch (category) {
|
|
114
107
|
case 'MPSectionCategory:abstract':
|
|
115
|
-
case 'MPSectionCategory:abstract-teaser':
|
|
116
108
|
case 'MPSectionCategory:abstract-graphical':
|
|
117
|
-
return
|
|
118
|
-
case 'MPSectionCategory:acknowledgement':
|
|
119
|
-
case 'MPSectionCategory:availability':
|
|
120
|
-
case 'MPSectionCategory:conclusions':
|
|
121
|
-
case 'MPSectionCategory:bibliography':
|
|
122
|
-
case 'MPSectionCategory:discussion':
|
|
123
|
-
case 'MPSectionCategory:endnotes':
|
|
124
|
-
case 'MPSectionCategory:appendices':
|
|
109
|
+
return abstractsType;
|
|
125
110
|
case 'MPSectionCategory:competing-interests':
|
|
126
111
|
case 'MPSectionCategory:con':
|
|
127
|
-
case 'MPSectionCategory:deceased':
|
|
128
112
|
case 'MPSectionCategory:ethics-statement':
|
|
129
113
|
case 'MPSectionCategory:financial-disclosure':
|
|
130
114
|
case 'MPSectionCategory:supplementary-material':
|
|
131
115
|
case 'MPSectionCategory:supported-by':
|
|
132
|
-
case 'MPSectionCategory:
|
|
133
|
-
case 'MPSectionCategory:
|
|
134
|
-
|
|
116
|
+
case 'MPSectionCategory:availability':
|
|
117
|
+
case 'MPSectionCategory:acknowledgement':
|
|
118
|
+
case 'MPSectionCategory:endnotes':
|
|
119
|
+
case 'MPSectionCategory:bibliography':
|
|
120
|
+
case 'MPSectionCategory:appendices':
|
|
121
|
+
case 'MPSectionCategory:deceased':
|
|
122
|
+
case 'MPSectionCategory:equal':
|
|
123
|
+
case 'MPSectionCategory:present-address':
|
|
124
|
+
case 'MPSectionCategory:presented-at':
|
|
125
|
+
case 'MPSectionCategory:previously-at':
|
|
126
|
+
return backmatterType;
|
|
135
127
|
}
|
|
136
|
-
return
|
|
128
|
+
return bodyType;
|
|
137
129
|
};
|
|
138
130
|
export const chooseSectionCategoryByType = (secType) => {
|
|
139
131
|
switch (secType) {
|
|
@@ -194,16 +186,6 @@ export const chooseSectionCategoryByType = (secType) => {
|
|
|
194
186
|
return 'MPSectionCategory:supported-by';
|
|
195
187
|
case 'ethics-statement':
|
|
196
188
|
return 'MPSectionCategory:ethics-statement';
|
|
197
|
-
case 'body':
|
|
198
|
-
return 'MPSectionCategory:body';
|
|
199
|
-
case 'backmatter':
|
|
200
|
-
return 'MPSectionCategory:backmatter';
|
|
201
|
-
case 'abstracts':
|
|
202
|
-
return 'MPSectionCategory:abstracts';
|
|
203
|
-
case 'affiliations':
|
|
204
|
-
return 'MPSectionCategory:affiliations';
|
|
205
|
-
case 'contributors':
|
|
206
|
-
return 'MPSectionCategory:contributors';
|
|
207
189
|
default:
|
|
208
190
|
return undefined;
|
|
209
191
|
}
|
|
@@ -13,19 +13,11 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
export type SectionGroupTypeID = 'abstracts' | 'body' | 'backmatter';
|
|
16
17
|
export type SectionGroupType = {
|
|
17
|
-
_id:
|
|
18
|
-
title: string;
|
|
19
|
-
};
|
|
20
|
-
export declare const abstractsType: {
|
|
21
|
-
_id: string;
|
|
22
|
-
title: string;
|
|
23
|
-
};
|
|
24
|
-
export declare const bodyType: {
|
|
25
|
-
_id: string;
|
|
26
|
-
title: string;
|
|
27
|
-
};
|
|
28
|
-
export declare const backmatterType: {
|
|
29
|
-
_id: string;
|
|
18
|
+
_id: SectionGroupTypeID;
|
|
30
19
|
title: string;
|
|
31
20
|
};
|
|
21
|
+
export declare const abstractsType: SectionGroupType;
|
|
22
|
+
export declare const bodyType: SectionGroupType;
|
|
23
|
+
export declare const backmatterType: SectionGroupType;
|
|
@@ -20,7 +20,6 @@ export declare function iterateChildren(node: ManuscriptNode, recurse?: boolean)
|
|
|
20
20
|
export declare const findNodePositions: (state: ManuscriptEditorState, predicate: (node: ManuscriptNode) => boolean) => number[];
|
|
21
21
|
export declare const isInGraphicalAbstractSection: ($pos: ResolvedPos) => boolean;
|
|
22
22
|
export declare const isInBibliographySection: ($pos: ResolvedPos) => boolean;
|
|
23
|
-
export declare const isInAbstractsSection: ($pos: ResolvedPos) => boolean;
|
|
24
23
|
export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate: (node: ProsemirrorNode) => boolean) => {
|
|
25
24
|
pos: number;
|
|
26
25
|
start: number;
|
|
@@ -28,5 +27,4 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
|
|
|
28
27
|
node: ProsemirrorNode;
|
|
29
28
|
} | undefined;
|
|
30
29
|
export declare const getTrimmedTextContent: (node: Element | Document | null, querySelector: string) => string | null | undefined;
|
|
31
|
-
export declare const groupBy: <T, K extends string | number | symbol>(list: T[], getKey: (item: T) => K) => Record<K, T[]>;
|
|
32
30
|
export declare function modelsEqual(model: Model, model2: Model): boolean;
|
|
@@ -29,9 +29,7 @@ export declare class Decoder {
|
|
|
29
29
|
private createContributorsNode;
|
|
30
30
|
private createKeywordsNode;
|
|
31
31
|
private createCommentsNode;
|
|
32
|
-
private
|
|
33
|
-
private ensureCoreSectionsExist;
|
|
34
|
-
private createAndFill;
|
|
32
|
+
private createContentSections;
|
|
35
33
|
private createCommentNodes;
|
|
36
34
|
private getComments;
|
|
37
35
|
private extractListing;
|
|
@@ -14,17 +14,18 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Element } from '@manuscripts/json-schema';
|
|
17
|
+
import { SectionGroupType } from '../lib/section-group-type';
|
|
17
18
|
import { ManuscriptNode, ManuscriptNodeType } from '../schema';
|
|
18
19
|
export declare const isAnySectionNode: (node: ManuscriptNode) => boolean;
|
|
19
|
-
export type SectionCategory = 'MPSectionCategory:abstract' | 'MPSectionCategory:abstract-teaser' | 'MPSectionCategory:abstract-graphical' | 'MPSectionCategory:acknowledgement' | 'MPSectionCategory:availability' | 'MPSectionCategory:bibliography' | 'MPSectionCategory:conclusions' | 'MPSectionCategory:discussion' | 'MPSectionCategory:endnotes' | 'MPSectionCategory:introduction' | 'MPSectionCategory:keywords' | 'MPSectionCategory:materials-method' | 'MPSectionCategory:results' | 'MPSectionCategory:toc' | 'MPSectionCategory:floating-element' | 'MPSectionCategory:appendices' | 'MPSectionCategory:competing-interests' | 'MPSectionCategory:financial-disclosure' | 'MPSectionCategory:con' | 'MPSectionCategory:deceased' | 'MPSectionCategory:equal' | 'MPSectionCategory:present-address' | 'MPSectionCategory:presented-at' | 'MPSectionCategory:previously-at' | 'MPSectionCategory:supplementary-material' | 'MPSectionCategory:supported-by' | 'MPSectionCategory:ethics-statement'
|
|
20
|
-
export type SecType = 'abstract' | 'abstract-teaser' | 'abstract-graphical' | 'acknowledgments' | 'availability' | 'bibliography' | 'conclusions' | 'data-availability' | 'discussion' | 'endnotes' | 'intro' | 'keywords' | 'materials' | 'methods' | 'results' | 'toc' | 'floating-element' | 'appendices' | 'competing-interests' | 'financial-disclosure' | 'con' | 'deceased' | 'equal' | 'present-address' | 'presented-at' | 'previously-at' | 'supplementary-material' | 'supported-by' | 'ethics-statement'
|
|
20
|
+
export type SectionCategory = 'MPSectionCategory:abstract' | 'MPSectionCategory:abstract-teaser' | 'MPSectionCategory:abstract-graphical' | 'MPSectionCategory:acknowledgement' | 'MPSectionCategory:availability' | 'MPSectionCategory:bibliography' | 'MPSectionCategory:conclusions' | 'MPSectionCategory:discussion' | 'MPSectionCategory:endnotes' | 'MPSectionCategory:introduction' | 'MPSectionCategory:keywords' | 'MPSectionCategory:materials-method' | 'MPSectionCategory:results' | 'MPSectionCategory:toc' | 'MPSectionCategory:floating-element' | 'MPSectionCategory:appendices' | 'MPSectionCategory:competing-interests' | 'MPSectionCategory:financial-disclosure' | 'MPSectionCategory:con' | 'MPSectionCategory:deceased' | 'MPSectionCategory:equal' | 'MPSectionCategory:present-address' | 'MPSectionCategory:presented-at' | 'MPSectionCategory:previously-at' | 'MPSectionCategory:supplementary-material' | 'MPSectionCategory:supported-by' | 'MPSectionCategory:ethics-statement';
|
|
21
|
+
export type SecType = 'abstract' | 'abstract-teaser' | 'abstract-graphical' | 'acknowledgments' | 'availability' | 'bibliography' | 'conclusions' | 'data-availability' | 'discussion' | 'endnotes' | 'intro' | 'keywords' | 'materials' | 'methods' | 'results' | 'toc' | 'floating-element' | 'appendices' | 'competing-interests' | 'financial-disclosure' | 'con' | 'deceased' | 'equal' | 'present-address' | 'presented-at' | 'previously-at' | 'supplementary-material' | 'supported-by' | 'ethics-statement';
|
|
21
22
|
export declare const chooseSectionNodeType: (category?: SectionCategory) => ManuscriptNodeType;
|
|
22
23
|
export declare const chooseSectionLableName: (type?: SecType) => string;
|
|
23
24
|
export declare const guessSectionCategory: (elements: Element[]) => SectionCategory | undefined;
|
|
24
25
|
export declare const buildSectionCategory: (node: ManuscriptNode) => SectionCategory | undefined;
|
|
25
26
|
export declare const chooseJatsFnType: (footnoteType: string) => string;
|
|
26
27
|
export declare const chooseSecType: (sectionCategory: SectionCategory) => SecType;
|
|
27
|
-
export declare const
|
|
28
|
+
export declare const getSectionGroupType: (category: string) => SectionGroupType;
|
|
28
29
|
export declare const chooseSectionCategoryByType: (secType: string) => SectionCategory | undefined;
|
|
29
30
|
export declare const chooseSectionCategory: (section: HTMLElement) => SectionCategory | undefined;
|
|
30
31
|
export declare const chooseSectionCategoryFromTitle: (title: string | null) => SectionCategory | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "1.5.8-LEAN-3030",
|
|
4
|
+
"version": "1.5.8-LEAN-3030-2",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|