@manuscripts/transform 1.5.2-LEAN-3032 → 1.5.2-LIT-528106
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 +7 -19
- package/dist/cjs/jats/jats-exporter.js +5 -10
- package/dist/cjs/lib/utils.js +13 -9
- package/dist/cjs/schema/index.js +3 -7
- package/dist/cjs/schema/nodes/affiliations_section.js +1 -1
- package/dist/cjs/schema/nodes/contributors_section.js +1 -1
- package/dist/cjs/schema/nodes/graphical_abstract_section.js +1 -0
- package/dist/cjs/schema/nodes/keywords_section.js +1 -1
- package/dist/cjs/schema/nodes/manuscript.js +1 -1
- package/dist/cjs/transformer/decode.js +19 -67
- package/dist/cjs/transformer/encode.js +35 -15
- package/dist/cjs/transformer/node-names.js +1 -1
- package/dist/cjs/transformer/node-title.js +1 -1
- package/dist/cjs/transformer/node-types.js +3 -6
- package/dist/cjs/transformer/section-category.js +8 -35
- package/dist/es/jats/importer/jats-body-dom-parser.js +7 -19
- package/dist/es/jats/jats-exporter.js +5 -10
- package/dist/es/lib/utils.js +11 -7
- package/dist/es/schema/index.js +3 -7
- package/dist/es/schema/nodes/affiliations_section.js +1 -1
- package/dist/es/schema/nodes/contributors_section.js +1 -1
- package/dist/es/schema/nodes/graphical_abstract_section.js +1 -0
- package/dist/es/schema/nodes/keywords_section.js +1 -1
- package/dist/es/schema/nodes/manuscript.js +1 -1
- package/dist/es/transformer/decode.js +20 -68
- package/dist/es/transformer/encode.js +36 -16
- package/dist/es/transformer/node-names.js +1 -1
- package/dist/es/transformer/node-title.js +1 -1
- package/dist/es/transformer/node-types.js +3 -6
- package/dist/es/transformer/section-category.js +7 -33
- package/dist/types/lib/utils.d.ts +2 -1
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/decode.d.ts +0 -3
- package/dist/types/transformer/encode.d.ts +1 -1
- package/dist/types/transformer/section-category.d.ts +0 -1
- package/package.json +1 -1
- package/dist/cjs/schema/nodes/core_section.js +0 -27
- package/dist/es/schema/nodes/core_section.js +0 -24
- package/dist/types/schema/nodes/core_section.d.ts +0 -25
|
@@ -501,7 +501,7 @@ const nodes = [
|
|
|
501
501
|
},
|
|
502
502
|
{
|
|
503
503
|
tag: 'sec[sec-type="affiliations"]',
|
|
504
|
-
node: '
|
|
504
|
+
node: 'affiliations_section',
|
|
505
505
|
getAttrs: (node) => {
|
|
506
506
|
const element = node;
|
|
507
507
|
return {
|
|
@@ -513,7 +513,7 @@ const nodes = [
|
|
|
513
513
|
{
|
|
514
514
|
tag: 'aff',
|
|
515
515
|
node: 'affiliation',
|
|
516
|
-
context: '
|
|
516
|
+
context: 'affiliations_section/',
|
|
517
517
|
getAttrs: (node) => {
|
|
518
518
|
const element = node;
|
|
519
519
|
const aff = {
|
|
@@ -560,7 +560,7 @@ const nodes = [
|
|
|
560
560
|
},
|
|
561
561
|
{
|
|
562
562
|
tag: 'sec[sec-type="contributors"]',
|
|
563
|
-
node: '
|
|
563
|
+
node: 'contributors_section',
|
|
564
564
|
getAttrs: (node) => {
|
|
565
565
|
const element = node;
|
|
566
566
|
return {
|
|
@@ -572,7 +572,7 @@ const nodes = [
|
|
|
572
572
|
{
|
|
573
573
|
tag: 'contrib',
|
|
574
574
|
node: 'contributor',
|
|
575
|
-
context: '
|
|
575
|
+
context: 'contributors_section/',
|
|
576
576
|
getAttrs: (node) => {
|
|
577
577
|
const element = node;
|
|
578
578
|
const contrib = {
|
|
@@ -627,7 +627,7 @@ const nodes = [
|
|
|
627
627
|
},
|
|
628
628
|
{
|
|
629
629
|
tag: 'sec[sec-type="keywords"]',
|
|
630
|
-
node: '
|
|
630
|
+
node: 'keywords_section',
|
|
631
631
|
getAttrs: (node) => {
|
|
632
632
|
const element = node;
|
|
633
633
|
return {
|
|
@@ -638,21 +638,9 @@ const nodes = [
|
|
|
638
638
|
},
|
|
639
639
|
{
|
|
640
640
|
tag: 'kwd-group-list',
|
|
641
|
-
context: '
|
|
641
|
+
context: 'keywords_section/',
|
|
642
642
|
node: 'keywords_element',
|
|
643
643
|
},
|
|
644
|
-
{
|
|
645
|
-
tag: 'sec[sec-type="abstracts"]',
|
|
646
|
-
node: 'abstracts',
|
|
647
|
-
},
|
|
648
|
-
{
|
|
649
|
-
tag: 'sec[sec-type="body"]',
|
|
650
|
-
node: 'body',
|
|
651
|
-
},
|
|
652
|
-
{
|
|
653
|
-
tag: 'sec[sec-type="backmatter"]',
|
|
654
|
-
node: 'backmatter',
|
|
655
|
-
},
|
|
656
644
|
{
|
|
657
645
|
tag: 'sec',
|
|
658
646
|
node: 'section',
|
|
@@ -732,7 +720,7 @@ const nodes = [
|
|
|
732
720
|
{
|
|
733
721
|
tag: 'title',
|
|
734
722
|
node: 'section_title',
|
|
735
|
-
context: 'section/|footnotes_section/|bibliography_section/|
|
|
723
|
+
context: 'section/|footnotes_section/|bibliography_section/|keywords_section/',
|
|
736
724
|
},
|
|
737
725
|
{
|
|
738
726
|
tag: 'title',
|
|
@@ -423,11 +423,9 @@ export class JATSExporter {
|
|
|
423
423
|
}
|
|
424
424
|
};
|
|
425
425
|
this.buildBody = (fragment) => {
|
|
426
|
+
const content = this.serializeFragment(fragment);
|
|
426
427
|
const body = this.document.createElement('body');
|
|
427
|
-
|
|
428
|
-
const serializedNode = this.serializeNode(cFragment);
|
|
429
|
-
body.append(...serializedNode.childNodes);
|
|
430
|
-
});
|
|
428
|
+
body.appendChild(content);
|
|
431
429
|
this.fixBody(body, fragment);
|
|
432
430
|
return body;
|
|
433
431
|
};
|
|
@@ -593,8 +591,8 @@ export class JATSExporter {
|
|
|
593
591
|
this.createSerializer = () => {
|
|
594
592
|
const getModel = (id) => id ? this.modelMap.get(id) : undefined;
|
|
595
593
|
const nodes = {
|
|
596
|
-
|
|
597
|
-
|
|
594
|
+
affiliations_section: () => '',
|
|
595
|
+
contributors_section: () => '',
|
|
598
596
|
table_element_footer: () => ['table-wrap-foot', 0],
|
|
599
597
|
contributor: () => '',
|
|
600
598
|
affiliation: () => '',
|
|
@@ -604,9 +602,6 @@ export class JATSExporter {
|
|
|
604
602
|
bibliography_item: () => '',
|
|
605
603
|
comment_list: () => '',
|
|
606
604
|
keywords_group: () => '',
|
|
607
|
-
body: () => ['body', 0],
|
|
608
|
-
abstracts: () => ['abstract', 0],
|
|
609
|
-
backmatter: () => ['backmatter', 0],
|
|
610
605
|
bibliography_section: (node) => [
|
|
611
606
|
'ref-list',
|
|
612
607
|
{ id: normalizeID(node.attrs.id) },
|
|
@@ -785,7 +780,7 @@ export class JATSExporter {
|
|
|
785
780
|
},
|
|
786
781
|
keyword: () => '',
|
|
787
782
|
keywords_element: () => '',
|
|
788
|
-
|
|
783
|
+
keywords_section: () => '',
|
|
789
784
|
link: (node) => {
|
|
790
785
|
const text = node.textContent;
|
|
791
786
|
if (!text) {
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -84,11 +84,15 @@ export const getTrimmedTextContent = (node, querySelector) => {
|
|
|
84
84
|
}
|
|
85
85
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
86
86
|
};
|
|
87
|
-
export
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
export function modelsEqual(model, model2) {
|
|
88
|
+
for (const v in model) {
|
|
89
|
+
for (const v2 in model2) {
|
|
90
|
+
const prepV = typeof v == 'object' ? JSON.stringify(v) : v;
|
|
91
|
+
const prepV2 = typeof v2 == 'object' ? JSON.stringify(v2) : v2;
|
|
92
|
+
if (prepV !== prepV2) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}, {});
|
|
97
|
+
return true;
|
|
98
|
+
}
|
package/dist/es/schema/index.js
CHANGED
|
@@ -29,7 +29,6 @@ import { comment } from './nodes/comment';
|
|
|
29
29
|
import { commentList } from './nodes/comment_list';
|
|
30
30
|
import { contributor } from './nodes/contributor';
|
|
31
31
|
import { contributorsSection } from './nodes/contributors_section';
|
|
32
|
-
import { coreSection } from './nodes/core_section';
|
|
33
32
|
import { crossReference } from './nodes/cross_reference';
|
|
34
33
|
import { doc } from './nodes/doc';
|
|
35
34
|
import { equation } from './nodes/equation';
|
|
@@ -152,9 +151,6 @@ export const schema = new Schema({
|
|
|
152
151
|
caption,
|
|
153
152
|
caption_title: captionTitle,
|
|
154
153
|
citation,
|
|
155
|
-
abstracts: coreSection,
|
|
156
|
-
body: coreSection,
|
|
157
|
-
backmatter: coreSection,
|
|
158
154
|
cross_reference: crossReference,
|
|
159
155
|
doc,
|
|
160
156
|
equation,
|
|
@@ -172,7 +168,7 @@ export const schema = new Schema({
|
|
|
172
168
|
inline_footnote: inlineFootnote,
|
|
173
169
|
keyword,
|
|
174
170
|
keywords_element: keywordsElement,
|
|
175
|
-
|
|
171
|
+
keywords_section: keywordsSection,
|
|
176
172
|
keywords_group: keywordsGroup,
|
|
177
173
|
link,
|
|
178
174
|
list_item: listItem,
|
|
@@ -203,7 +199,7 @@ export const schema = new Schema({
|
|
|
203
199
|
meta_section: metaSection,
|
|
204
200
|
contributor: contributor,
|
|
205
201
|
table_element_footer: tableElementFooter,
|
|
206
|
-
|
|
207
|
-
|
|
202
|
+
affiliations_section: affiliationsSection,
|
|
203
|
+
contributors_section: contributorsSection,
|
|
208
204
|
},
|
|
209
205
|
});
|
|
@@ -8,4 +8,4 @@ export const affiliationsSection = {
|
|
|
8
8
|
selectable: false,
|
|
9
9
|
toDOM: () => ['section', 0],
|
|
10
10
|
};
|
|
11
|
-
export const isAffiliationsSectionNode = (node) => node.type === node.type.schema.nodes.
|
|
11
|
+
export const isAffiliationsSectionNode = (node) => node.type === node.type.schema.nodes.affiliations_section;
|
|
@@ -8,4 +8,4 @@ export const contributorsSection = {
|
|
|
8
8
|
selectable: false,
|
|
9
9
|
toDOM: () => ['section', 0],
|
|
10
10
|
};
|
|
11
|
-
export const isContributorsSectionNode = (node) => node.type === node.type.schema.nodes.
|
|
11
|
+
export const isContributorsSectionNode = (node) => node.type === node.type.schema.nodes.contributors_section;
|
|
@@ -28,12 +28,11 @@ 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 { groupBy } from '../lib/utils';
|
|
32
31
|
import { schema, } from '../schema';
|
|
33
32
|
import { insertHighlightMarkers } from './highlight-markers';
|
|
34
33
|
import { generateNodeID } from './id';
|
|
35
34
|
import { ExtraObjectTypes, hasObjectType, isCommentAnnotation, isManuscript, } from './object-types';
|
|
36
|
-
import {
|
|
35
|
+
import { chooseSectionLableName, chooseSectionNodeType, chooseSecType, guessSectionCategory, } from './section-category';
|
|
37
36
|
import { timestamp } from './timestamp';
|
|
38
37
|
const warn = debug('manuscripts-transform');
|
|
39
38
|
const parser = DOMParser.fromSchema(schema);
|
|
@@ -54,7 +53,6 @@ export const sortSectionsByPriority = (a, b) => a.priority === b.priority ? 0 :
|
|
|
54
53
|
const getSections = (modelMap) => getModelsByType(modelMap, ObjectTypes.Section).sort(sortSectionsByPriority);
|
|
55
54
|
const getAffiliations = (modelMap) => getModelsByType(modelMap, ObjectTypes.Affiliation);
|
|
56
55
|
const getContributors = (modelMap) => getModelsByType(modelMap, ObjectTypes.Contributor);
|
|
57
|
-
const getKeywordElements = (modelMap) => getModelsByType(modelMap, ObjectTypes.KeywordsElement);
|
|
58
56
|
export const isManuscriptNode = (model) => model !== null;
|
|
59
57
|
const isParagraphElement = hasObjectType(ObjectTypes.ParagraphElement);
|
|
60
58
|
const isFootnote = hasObjectType(ObjectTypes.Footnote);
|
|
@@ -78,13 +76,10 @@ export class Decoder {
|
|
|
78
76
|
]);
|
|
79
77
|
}
|
|
80
78
|
handleMissingRootSectionNodes(rootSectionNodes) {
|
|
81
|
-
if (!rootSectionNodes.find((node) => node.type.name === '
|
|
82
|
-
this.createKeywordsSectionNode(rootSectionNodes);
|
|
83
|
-
}
|
|
84
|
-
if (!rootSectionNodes.find((node) => node.type.name === 'affiliations')) {
|
|
79
|
+
if (!rootSectionNodes.find((node) => node.type.name === 'affiliations_section')) {
|
|
85
80
|
this.createAffiliationSectionNode(rootSectionNodes);
|
|
86
81
|
}
|
|
87
|
-
if (!rootSectionNodes.find((node) => node.type.name === '
|
|
82
|
+
if (!rootSectionNodes.find((node) => node.type.name === 'contributors_section')) {
|
|
88
83
|
this.createContributorSectionNode(rootSectionNodes);
|
|
89
84
|
}
|
|
90
85
|
}
|
|
@@ -92,79 +87,37 @@ export class Decoder {
|
|
|
92
87
|
const affiliationNodes = getAffiliations(this.modelMap)
|
|
93
88
|
.map((affiliation) => this.decode(affiliation))
|
|
94
89
|
.filter(Boolean);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
if (affiliationNodes.length) {
|
|
91
|
+
const node = schema.nodes.affiliations_section.createAndFill({
|
|
92
|
+
id: generateNodeID(schema.nodes.section),
|
|
93
|
+
}, affiliationNodes);
|
|
94
|
+
rootSectionNodes.unshift(node);
|
|
95
|
+
}
|
|
99
96
|
}
|
|
100
97
|
createContributorSectionNode(rootSectionNodes) {
|
|
101
98
|
const contributorNodes = getContributors(this.modelMap)
|
|
102
99
|
.map((contributor) => this.decode(contributor))
|
|
103
100
|
.filter(Boolean);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}, contributorNodes);
|
|
107
|
-
rootSectionNodes.unshift(node);
|
|
108
|
-
}
|
|
109
|
-
createKeywordsSectionNode(rootSectionNodes) {
|
|
110
|
-
const keywordElementNodes = getKeywordElements(this.modelMap)
|
|
111
|
-
.map((keywordEl) => this.decode(keywordEl))
|
|
112
|
-
.filter(Boolean);
|
|
113
|
-
if (keywordElementNodes) {
|
|
114
|
-
const node = schema.nodes.keywords.createAndFill({
|
|
101
|
+
if (contributorNodes.length) {
|
|
102
|
+
const node = schema.nodes.contributors_section.createAndFill({
|
|
115
103
|
id: generateNodeID(schema.nodes.section),
|
|
116
|
-
},
|
|
117
|
-
schema.nodes.section_title.create({}, schema.text('Keywords')),
|
|
118
|
-
...keywordElementNodes,
|
|
119
|
-
]);
|
|
104
|
+
}, contributorNodes);
|
|
120
105
|
rootSectionNodes.unshift(node);
|
|
121
106
|
}
|
|
122
107
|
}
|
|
123
108
|
createRootSectionNodes() {
|
|
124
|
-
let rootSections = getSections(this.modelMap)
|
|
125
|
-
.filter((section) => !section.path || section.path.length <= 1)
|
|
126
|
-
.filter((section) => section.category !== 'MPSectionCategory:contributors' &&
|
|
127
|
-
section.category !== 'MPSectionCategory:affiliations' &&
|
|
128
|
-
section.category !== 'MPSectionCategory:keywords');
|
|
109
|
+
let rootSections = getSections(this.modelMap).filter((section) => !section.path || section.path.length <= 1);
|
|
129
110
|
rootSections = this.addGeneratedLabels(rootSections);
|
|
130
|
-
const
|
|
131
|
-
var _a;
|
|
132
|
-
return chooseCoreSectionBySection((_a = sec.category) !== null && _a !== void 0 ? _a : '');
|
|
133
|
-
});
|
|
134
|
-
this.ensureCoreSectionsExist(sectionGroups);
|
|
135
|
-
const absSectionNode = sectionGroups['MPSectionCategory:abstracts']
|
|
136
|
-
.map(this.decode)
|
|
137
|
-
.filter(isManuscriptNode);
|
|
138
|
-
const bodySectionNodes = sectionGroups['MPSectionCategory:body']
|
|
111
|
+
const rootSectionNodes = rootSections
|
|
139
112
|
.map(this.decode)
|
|
140
113
|
.filter(isManuscriptNode);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const backmatterCoreSectionNodes = this.createAndFill(schema.nodes.backmatter, backmatterSectionNodes);
|
|
147
|
-
return [
|
|
148
|
-
abstractCoreSectionNodes,
|
|
149
|
-
bodyCoreSectionNodes,
|
|
150
|
-
backmatterCoreSectionNodes,
|
|
151
|
-
];
|
|
152
|
-
}
|
|
153
|
-
ensureCoreSectionsExist(coreSections) {
|
|
154
|
-
if (!coreSections['MPSectionCategory:abstracts']) {
|
|
155
|
-
coreSections['MPSectionCategory:abstracts'] = [];
|
|
156
|
-
}
|
|
157
|
-
if (!coreSections['MPSectionCategory:body']) {
|
|
158
|
-
coreSections['MPSectionCategory:body'] = [];
|
|
159
|
-
}
|
|
160
|
-
if (!coreSections['MPSectionCategory:backmatter']) {
|
|
161
|
-
coreSections['MPSectionCategory:backmatter'] = [];
|
|
114
|
+
this.handleMissingRootSectionNodes(rootSectionNodes);
|
|
115
|
+
if (!rootSectionNodes.length) {
|
|
116
|
+
rootSectionNodes.push(schema.nodes.section.createAndFill({
|
|
117
|
+
id: generateNodeID(schema.nodes.section),
|
|
118
|
+
}));
|
|
162
119
|
}
|
|
163
|
-
|
|
164
|
-
createAndFill(nodeType, content) {
|
|
165
|
-
return nodeType.createAndFill({
|
|
166
|
-
id: generateNodeID(nodeType),
|
|
167
|
-
}, content);
|
|
120
|
+
return rootSectionNodes;
|
|
168
121
|
}
|
|
169
122
|
createCommentsNode(model) {
|
|
170
123
|
const comments = [];
|
|
@@ -669,7 +622,6 @@ export class Decoder {
|
|
|
669
622
|
this.getModel = (id) => this.modelMap.get(id);
|
|
670
623
|
this.createArticleNode = (manuscriptID) => {
|
|
671
624
|
const rootSectionNodes = this.createRootSectionNodes();
|
|
672
|
-
this.handleMissingRootSectionNodes(rootSectionNodes);
|
|
673
625
|
const metaSectionNode = this.createMetaSectionNode();
|
|
674
626
|
const contents = [...rootSectionNodes, metaSectionNode];
|
|
675
627
|
return schema.nodes.manuscript.create({
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { DOMSerializer } from 'prosemirror-model';
|
|
17
17
|
import serializeToXML from 'w3c-xmlserializer';
|
|
18
|
-
import { iterateChildren } from '../lib/utils';
|
|
18
|
+
import { iterateChildren, modelsEqual } from '../lib/utils';
|
|
19
19
|
import { hasGroup, isHighlightMarkerNode, isSectionNode, schema, } from '../schema';
|
|
20
20
|
import { buildAttribution } from './builders';
|
|
21
21
|
import { extractHighlightMarkers, isHighlightableModel, } from './highlight-markers';
|
|
22
|
+
import { generateID } from './id';
|
|
22
23
|
import { nodeTypesMap } from './node-types';
|
|
23
24
|
import { buildSectionCategory } from './section-category';
|
|
24
25
|
const serializer = DOMSerializer.fromSchema(schema);
|
|
@@ -417,6 +418,31 @@ const encoders = {
|
|
|
417
418
|
keywords_group: (node) => ({
|
|
418
419
|
type: node.attrs.type,
|
|
419
420
|
}),
|
|
421
|
+
keywords_section: (node, parent, path, priority) => ({
|
|
422
|
+
category: buildSectionCategory(node),
|
|
423
|
+
priority: priority.value++,
|
|
424
|
+
title: inlineContentsOfNodeType(node, node.type.schema.nodes.section_title),
|
|
425
|
+
path: path.concat([node.attrs.id]),
|
|
426
|
+
elementIDs: childElements(node)
|
|
427
|
+
.map((childNode) => childNode.attrs.id)
|
|
428
|
+
.filter((id) => id),
|
|
429
|
+
}),
|
|
430
|
+
affiliations_section: (node, parent, path, priority) => ({
|
|
431
|
+
category: buildSectionCategory(node),
|
|
432
|
+
priority: priority.value++,
|
|
433
|
+
path: path.concat([node.attrs.id]),
|
|
434
|
+
elementIDs: childElements(node)
|
|
435
|
+
.map((childNode) => childNode.attrs.id)
|
|
436
|
+
.filter((id) => id),
|
|
437
|
+
}),
|
|
438
|
+
contributors_section: (node, parent, path, priority) => ({
|
|
439
|
+
category: buildSectionCategory(node),
|
|
440
|
+
priority: priority.value++,
|
|
441
|
+
path: path.concat([node.attrs.id]),
|
|
442
|
+
elementIDs: childElements(node)
|
|
443
|
+
.map((childNode) => childNode.attrs.id)
|
|
444
|
+
.filter((id) => id),
|
|
445
|
+
}),
|
|
420
446
|
missing_figure: (node) => ({
|
|
421
447
|
position: node.attrs.position || undefined,
|
|
422
448
|
}),
|
|
@@ -536,25 +562,13 @@ export const modelFromNode = (node, parent, path, priority) => {
|
|
|
536
562
|
}
|
|
537
563
|
return { model, commentAnnotationsMap };
|
|
538
564
|
};
|
|
539
|
-
|
|
540
|
-
return (child.type === schema.nodes.abstracts ||
|
|
541
|
-
child.type === schema.nodes.body ||
|
|
542
|
-
child.type === schema.nodes.backmatter ||
|
|
543
|
-
child.type === schema.nodes.affiliations ||
|
|
544
|
-
child.type === schema.nodes.contributors ||
|
|
545
|
-
child.type === schema.nodes.keywords);
|
|
546
|
-
}
|
|
547
|
-
export const encode = (node) => {
|
|
565
|
+
export const encode = (node, preserveWithRepeatedID = false) => {
|
|
548
566
|
const models = new Map();
|
|
549
567
|
const priority = {
|
|
550
568
|
value: 1,
|
|
551
569
|
};
|
|
552
570
|
const placeholders = ['placeholder', 'placeholder_element'];
|
|
553
571
|
const addModel = (path, parent) => (child) => {
|
|
554
|
-
if (isCoreSection(child)) {
|
|
555
|
-
child.forEach(addModel([], child));
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
572
|
if (!child.attrs.id) {
|
|
559
573
|
return;
|
|
560
574
|
}
|
|
@@ -568,8 +582,14 @@ export const encode = (node) => {
|
|
|
568
582
|
return;
|
|
569
583
|
}
|
|
570
584
|
const { model } = modelFromNode(child, parent, path, priority);
|
|
571
|
-
|
|
572
|
-
|
|
585
|
+
const existingModel = models.get(model._id);
|
|
586
|
+
if (existingModel) {
|
|
587
|
+
if (preserveWithRepeatedID && !modelsEqual(model, existingModel)) {
|
|
588
|
+
model._id = generateID(model.objectType);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
throw Error(`Encountered duplicate ids in models map while encoding: ${model._id}`);
|
|
592
|
+
}
|
|
573
593
|
}
|
|
574
594
|
models.set(model._id, model);
|
|
575
595
|
child.forEach(addModel(path.concat(child.attrs.id), child));
|
|
@@ -35,6 +35,6 @@ export const nodeNames = new Map([
|
|
|
35
35
|
[schema.nodes.table_element, 'Table'],
|
|
36
36
|
[schema.nodes.blockquote_element, 'Block Quote'],
|
|
37
37
|
[schema.nodes.pullquote_element, 'Pull Quote'],
|
|
38
|
-
[schema.nodes.
|
|
38
|
+
[schema.nodes.keywords_section, 'Section'],
|
|
39
39
|
[schema.nodes.toc_section, 'Section'],
|
|
40
40
|
]);
|
|
@@ -45,7 +45,7 @@ export const nodeTitle = (node) => {
|
|
|
45
45
|
case nodes.section:
|
|
46
46
|
case nodes.bibliography_section:
|
|
47
47
|
case nodes.footnotes_section:
|
|
48
|
-
case nodes.
|
|
48
|
+
case nodes.keywords_section:
|
|
49
49
|
case nodes.toc_section:
|
|
50
50
|
case nodes.graphical_abstract_section:
|
|
51
51
|
return snippetOfNodeType(node, nodes.section_title);
|
|
@@ -16,9 +16,6 @@
|
|
|
16
16
|
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
17
|
import { GROUP_ELEMENT, GROUP_EXECUTABLE, GROUP_SECTION, hasGroup, schema, } from '../schema';
|
|
18
18
|
export const nodeTypesMap = new Map([
|
|
19
|
-
[schema.nodes.abstracts, ObjectTypes.Section],
|
|
20
|
-
[schema.nodes.body, ObjectTypes.Section],
|
|
21
|
-
[schema.nodes.backmatter, ObjectTypes.Section],
|
|
22
19
|
[schema.nodes.comment, ObjectTypes.CommentAnnotation],
|
|
23
20
|
[schema.nodes.bibliography_item, ObjectTypes.BibliographyItem],
|
|
24
21
|
[schema.nodes.bibliography_element, ObjectTypes.BibliographyElement],
|
|
@@ -40,7 +37,7 @@ export const nodeTypesMap = new Map([
|
|
|
40
37
|
[schema.nodes.inline_equation, ObjectTypes.InlineMathFragment],
|
|
41
38
|
[schema.nodes.keyword, ObjectTypes.Keyword],
|
|
42
39
|
[schema.nodes.keywords_element, ObjectTypes.KeywordsElement],
|
|
43
|
-
[schema.nodes.
|
|
40
|
+
[schema.nodes.keywords_section, ObjectTypes.Section],
|
|
44
41
|
[schema.nodes.keywords_group, ObjectTypes.KeywordGroup],
|
|
45
42
|
[schema.nodes.listing, ObjectTypes.Listing],
|
|
46
43
|
[schema.nodes.listing_element, ObjectTypes.ListingElement],
|
|
@@ -57,8 +54,8 @@ export const nodeTypesMap = new Map([
|
|
|
57
54
|
[schema.nodes.affiliation, ObjectTypes.Affiliation],
|
|
58
55
|
[schema.nodes.contributor, ObjectTypes.Contributor],
|
|
59
56
|
[schema.nodes.table_element_footer, ObjectTypes.TableElementFooter],
|
|
60
|
-
[schema.nodes.
|
|
61
|
-
[schema.nodes.
|
|
57
|
+
[schema.nodes.contributors_section, ObjectTypes.Section],
|
|
58
|
+
[schema.nodes.affiliations_section, ObjectTypes.Section],
|
|
62
59
|
]);
|
|
63
60
|
export const isExecutableNodeType = (type) => hasGroup(type, GROUP_EXECUTABLE);
|
|
64
61
|
export const isElementNodeType = (type) => hasGroup(type, GROUP_ELEMENT);
|
|
@@ -19,7 +19,7 @@ import { schema } from '../schema';
|
|
|
19
19
|
const sectionNodeTypes = [
|
|
20
20
|
schema.nodes.bibliography_section,
|
|
21
21
|
schema.nodes.footnotes_section,
|
|
22
|
-
schema.nodes.
|
|
22
|
+
schema.nodes.keywords_section,
|
|
23
23
|
schema.nodes.section,
|
|
24
24
|
schema.nodes.toc_section,
|
|
25
25
|
];
|
|
@@ -40,11 +40,11 @@ export const chooseSectionNodeType = (category) => {
|
|
|
40
40
|
case 'MPSectionCategory:endnotes':
|
|
41
41
|
return schema.nodes.footnotes_section;
|
|
42
42
|
case 'MPSectionCategory:keywords':
|
|
43
|
-
return schema.nodes.
|
|
43
|
+
return schema.nodes.keywords_section;
|
|
44
44
|
case 'MPSectionCategory:affiliations':
|
|
45
|
-
return schema.nodes.
|
|
45
|
+
return schema.nodes.affiliations_section;
|
|
46
46
|
case 'MPSectionCategory:contributors':
|
|
47
|
-
return schema.nodes.
|
|
47
|
+
return schema.nodes.contributors_section;
|
|
48
48
|
case 'MPSectionCategory:toc':
|
|
49
49
|
return schema.nodes.toc_section;
|
|
50
50
|
default:
|
|
@@ -82,15 +82,15 @@ export const buildSectionCategory = (node) => {
|
|
|
82
82
|
return 'MPSectionCategory:bibliography';
|
|
83
83
|
case schema.nodes.footnotes_section:
|
|
84
84
|
return 'MPSectionCategory:endnotes';
|
|
85
|
-
case schema.nodes.
|
|
85
|
+
case schema.nodes.keywords_section:
|
|
86
86
|
return 'MPSectionCategory:keywords';
|
|
87
87
|
case schema.nodes.toc_section:
|
|
88
88
|
return 'MPSectionCategory:toc';
|
|
89
89
|
case schema.nodes.graphical_abstract_section:
|
|
90
90
|
return 'MPSectionCategory:abstract-graphical';
|
|
91
|
-
case schema.nodes.
|
|
91
|
+
case schema.nodes.affiliations_section:
|
|
92
92
|
return 'MPSectionCategory:affiliations';
|
|
93
|
-
case schema.nodes.
|
|
93
|
+
case schema.nodes.contributors_section:
|
|
94
94
|
return 'MPSectionCategory:contributors';
|
|
95
95
|
default:
|
|
96
96
|
return node.attrs.category || undefined;
|
|
@@ -117,32 +117,6 @@ export const chooseSecType = (sectionCategory) => {
|
|
|
117
117
|
return suffix;
|
|
118
118
|
}
|
|
119
119
|
};
|
|
120
|
-
export const chooseCoreSectionBySection = (section) => {
|
|
121
|
-
switch (section) {
|
|
122
|
-
case 'MPSectionCategory:abstract':
|
|
123
|
-
case 'MPSectionCategory:abstract-teaser':
|
|
124
|
-
case 'MPSectionCategory:abstract-graphical':
|
|
125
|
-
return 'MPSectionCategory:abstracts';
|
|
126
|
-
case 'MPSectionCategory:acknowledgement':
|
|
127
|
-
case 'MPSectionCategory:availability':
|
|
128
|
-
case 'MPSectionCategory:conclusions':
|
|
129
|
-
case 'MPSectionCategory:bibliography':
|
|
130
|
-
case 'MPSectionCategory:discussion':
|
|
131
|
-
case 'MPSectionCategory:endnotes':
|
|
132
|
-
case 'MPSectionCategory:appendices':
|
|
133
|
-
case 'MPSectionCategory:competing-interests':
|
|
134
|
-
case 'MPSectionCategory:con':
|
|
135
|
-
case 'MPSectionCategory:deceased':
|
|
136
|
-
case 'MPSectionCategory:ethics-statement':
|
|
137
|
-
case 'MPSectionCategory:financial-disclosure':
|
|
138
|
-
case 'MPSectionCategory:supplementary-material':
|
|
139
|
-
case 'MPSectionCategory:supported-by':
|
|
140
|
-
case 'MPSectionCategory:abbreviations':
|
|
141
|
-
case 'MPSectionCategory:results':
|
|
142
|
-
return 'MPSectionCategory:backmatter';
|
|
143
|
-
}
|
|
144
|
-
return 'MPSectionCategory:body';
|
|
145
|
-
};
|
|
146
120
|
export const chooseSectionCategoryByType = (secType) => {
|
|
147
121
|
switch (secType) {
|
|
148
122
|
case 'abstract':
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { Model } from '@manuscripts/json-schema';
|
|
16
17
|
import { Node as ProsemirrorNode, ResolvedPos } from 'prosemirror-model';
|
|
17
18
|
import { ManuscriptEditorState, ManuscriptNode } from '../schema';
|
|
18
19
|
export declare function iterateChildren(node: ManuscriptNode, recurse?: boolean): Iterable<ManuscriptNode>;
|
|
@@ -27,4 +28,4 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
|
|
|
27
28
|
node: ProsemirrorNode;
|
|
28
29
|
} | undefined;
|
|
29
30
|
export declare const getTrimmedTextContent: (node: Element | Document, querySelector: string) => string | null | undefined;
|
|
30
|
-
export declare
|
|
31
|
+
export declare function modelsEqual(model: Model, model2: Model): boolean;
|
|
@@ -17,7 +17,7 @@ import { Fragment, Mark as ProsemirrorMark, MarkType, Node as ProsemirrorNode, N
|
|
|
17
17
|
import { EditorState, NodeSelection, Plugin, TextSelection, Transaction } from 'prosemirror-state';
|
|
18
18
|
import { EditorView, NodeView } from 'prosemirror-view';
|
|
19
19
|
export type Marks = 'bold' | 'code' | 'italic' | 'smallcaps' | 'strikethrough' | 'styled' | 'subscript' | 'superscript' | 'underline' | 'tracked_insert' | 'tracked_delete';
|
|
20
|
-
export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comment_list' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keyword' | 'keywords_element' | 'keywords_group' | '
|
|
20
|
+
export type Nodes = 'attribution' | 'bibliography_item' | 'bibliography_element' | 'bibliography_section' | 'blockquote_element' | 'bullet_list' | 'caption' | 'caption_title' | 'comment' | 'comment_list' | 'citation' | 'cross_reference' | 'doc' | 'equation' | 'equation_element' | 'figcaption' | 'figure' | 'graphical_abstract_section' | 'figure_element' | 'footnote' | 'footnotes_element' | 'footnotes_section' | 'hard_break' | 'highlight_marker' | 'inline_equation' | 'inline_footnote' | 'keyword' | 'keywords_element' | 'keywords_group' | 'keywords_section' | 'link' | 'list_item' | 'listing' | 'listing_element' | 'manuscript' | 'missing_figure' | 'ordered_list' | 'paragraph' | 'placeholder' | 'placeholder_element' | 'pullquote_element' | 'section' | 'section_label' | 'section_title' | 'section_title_plain' | 'table' | 'table_body' | 'table_cell' | 'table_element' | 'table_row' | 'table_colgroup' | 'table_col' | 'text' | 'toc_element' | 'toc_section' | 'affiliation' | 'meta_section' | 'contributor' | 'table_element_footer' | 'affiliations_section' | 'contributors_section';
|
|
21
21
|
export type ManuscriptSchema = Schema<Nodes, Marks>;
|
|
22
22
|
export type ManuscriptEditorState = EditorState;
|
|
23
23
|
export type ManuscriptEditorView = EditorView;
|
|
@@ -30,10 +30,7 @@ export declare class Decoder {
|
|
|
30
30
|
private handleMissingRootSectionNodes;
|
|
31
31
|
private createAffiliationSectionNode;
|
|
32
32
|
private createContributorSectionNode;
|
|
33
|
-
private createKeywordsSectionNode;
|
|
34
33
|
private createRootSectionNodes;
|
|
35
|
-
private ensureCoreSectionsExist;
|
|
36
|
-
private createAndFill;
|
|
37
34
|
private createCommentsNode;
|
|
38
35
|
private getComments;
|
|
39
36
|
private extractListing;
|
|
@@ -25,5 +25,5 @@ export declare const modelFromNode: (node: ManuscriptNode, parent: ManuscriptNod
|
|
|
25
25
|
interface PrioritizedValue {
|
|
26
26
|
value: number;
|
|
27
27
|
}
|
|
28
|
-
export declare const encode: (node: ManuscriptNode) => Map<string, Model>;
|
|
28
|
+
export declare const encode: (node: ManuscriptNode, preserveWithRepeatedID?: boolean) => Map<string, Model>;
|
|
29
29
|
export {};
|
|
@@ -25,7 +25,6 @@ export declare const guessSectionCategory: (elements: Element[]) => SectionCateg
|
|
|
25
25
|
export declare const buildSectionCategory: (node: ManuscriptNode) => SectionCategory | undefined;
|
|
26
26
|
export declare const chooseJatsFnType: (footnoteType: string) => string;
|
|
27
27
|
export declare const chooseSecType: (sectionCategory: SectionCategory) => SecType;
|
|
28
|
-
export declare const chooseCoreSectionBySection: (section: string) => string;
|
|
29
28
|
export declare const chooseSectionCategoryByType: (secType: string) => SectionCategory | undefined;
|
|
30
29
|
export declare const chooseSectionCategory: (section: HTMLElement) => SectionCategory | undefined;
|
|
31
30
|
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.2-
|
|
4
|
+
"version": "1.5.2-LIT-528106",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|