@manuscripts/transform 1.5.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/jats/importer/index.js +1 -3
- package/dist/cjs/jats/importer/jats-body-dom-parser.js +23 -227
- package/dist/cjs/jats/importer/jats-body-transformations.js +110 -201
- package/dist/cjs/jats/importer/jats-comments.js +100 -98
- package/dist/cjs/jats/importer/jats-front-parser.js +87 -81
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +51 -39
- package/dist/cjs/jats/importer/jats-parser-utils.js +17 -56
- package/dist/cjs/jats/importer/jats-reference-parser.js +24 -79
- package/dist/cjs/jats/importer/jats-references.js +34 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +67 -173
- package/dist/cjs/jats/index.js +1 -3
- package/dist/cjs/jats/jats-exporter.js +34 -55
- package/dist/cjs/lib/section-group-type.js +30 -0
- package/dist/cjs/lib/utils.js +1 -25
- package/dist/cjs/schema/index.js +20 -17
- package/dist/cjs/schema/nodes/abstracts.js +27 -0
- package/dist/cjs/schema/nodes/affiliations.js +27 -0
- package/dist/cjs/schema/nodes/backmatter.js +27 -0
- package/dist/cjs/schema/nodes/body.js +27 -0
- package/dist/cjs/schema/nodes/citation.js +10 -15
- package/dist/cjs/schema/nodes/{comment_list.js → comments.js} +4 -4
- package/dist/cjs/schema/nodes/contributors.js +27 -0
- package/dist/cjs/schema/nodes/{meta_section.js → core_section.js} +6 -5
- package/dist/cjs/schema/nodes/cross_reference.js +4 -3
- package/dist/cjs/schema/nodes/inline_footnote.js +6 -5
- package/dist/cjs/schema/nodes/keyword.js +0 -1
- package/dist/cjs/schema/nodes/{keywords_group.js → keyword_group.js} +6 -6
- package/dist/cjs/schema/nodes/{keywords_section.js → keywords.js} +7 -7
- package/dist/cjs/schema/nodes/keywords_element.js +1 -1
- package/dist/cjs/schema/nodes/manuscript.js +5 -2
- package/dist/cjs/transformer/builders.js +9 -86
- package/dist/cjs/transformer/decode.js +147 -176
- package/dist/cjs/transformer/encode.js +66 -67
- package/dist/cjs/transformer/highlight-markers.js +48 -36
- package/dist/cjs/transformer/html.js +7 -23
- package/dist/cjs/transformer/labels.js +3 -17
- package/dist/cjs/transformer/node-names.js +1 -1
- package/dist/cjs/transformer/node-title.js +1 -1
- package/dist/cjs/transformer/node-types.js +7 -6
- package/dist/cjs/transformer/object-types.js +1 -2
- package/dist/cjs/transformer/section-category.js +31 -31
- package/dist/es/index.js +1 -1
- package/dist/es/jats/importer/index.js +1 -1
- package/dist/es/jats/importer/jats-body-dom-parser.js +23 -227
- package/dist/es/jats/importer/jats-body-transformations.js +111 -202
- package/dist/es/jats/importer/jats-comments.js +97 -96
- package/dist/es/jats/importer/jats-front-parser.js +88 -82
- package/dist/es/jats/importer/jats-journal-meta-parser.js +51 -39
- package/dist/es/jats/importer/jats-parser-utils.js +16 -54
- package/dist/es/jats/importer/jats-reference-parser.js +27 -82
- package/dist/es/jats/importer/jats-references.js +30 -0
- package/dist/es/jats/importer/parse-jats-article.js +70 -174
- package/dist/es/jats/index.js +1 -1
- package/dist/es/jats/jats-exporter.js +34 -55
- package/dist/es/lib/section-group-type.js +27 -0
- package/dist/es/lib/utils.js +0 -22
- package/dist/es/schema/index.js +21 -18
- package/dist/es/schema/nodes/abstracts.js +24 -0
- package/dist/es/schema/nodes/affiliations.js +24 -0
- package/dist/es/schema/nodes/backmatter.js +24 -0
- package/dist/es/schema/nodes/body.js +24 -0
- package/dist/es/schema/nodes/citation.js +10 -15
- package/dist/es/schema/nodes/{comment_list.js → comments.js} +3 -3
- package/dist/es/schema/nodes/contributors.js +24 -0
- package/dist/es/schema/nodes/{meta_section.js → core_section.js} +5 -4
- package/dist/es/schema/nodes/cross_reference.js +4 -3
- package/dist/es/schema/nodes/inline_footnote.js +6 -5
- package/dist/es/schema/nodes/keyword.js +0 -1
- package/dist/es/schema/nodes/{keywords_group.js → keyword_group.js} +4 -4
- package/dist/es/schema/nodes/{keywords_section.js → keywords.js} +5 -5
- package/dist/es/schema/nodes/keywords_element.js +1 -1
- package/dist/es/schema/nodes/manuscript.js +3 -1
- package/dist/es/transformer/builders.js +6 -73
- package/dist/es/transformer/decode.js +147 -175
- package/dist/es/transformer/encode.js +70 -71
- package/dist/es/transformer/highlight-markers.js +44 -32
- package/dist/es/transformer/html.js +7 -23
- package/dist/es/transformer/labels.js +3 -17
- package/dist/es/transformer/node-names.js +1 -1
- package/dist/es/transformer/node-title.js +1 -1
- package/dist/es/transformer/node-types.js +7 -6
- package/dist/es/transformer/object-types.js +0 -1
- package/dist/es/transformer/section-category.js +29 -29
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jats/importer/index.d.ts +1 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +16 -19
- package/dist/types/jats/importer/jats-comments.d.ts +13 -9
- package/dist/types/jats/importer/jats-front-parser.d.ts +35 -12
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +4 -4
- package/dist/types/jats/importer/jats-parser-utils.d.ts +1 -6
- package/dist/types/jats/importer/jats-reference-parser.d.ts +2 -6
- package/dist/types/jats/importer/jats-references.d.ts +12 -0
- package/dist/types/jats/importer/parse-jats-article.d.ts +5 -17
- package/dist/types/jats/index.d.ts +1 -1
- package/dist/types/lib/section-group-type.d.ts +23 -0
- package/dist/types/lib/utils.d.ts +1 -4
- package/dist/types/schema/index.d.ts +4 -5
- package/dist/types/schema/nodes/{meta_section.d.ts → abstracts.d.ts} +1 -9
- package/dist/types/schema/nodes/affiliations.d.ts +17 -0
- package/dist/types/schema/nodes/backmatter.d.ts +17 -0
- package/dist/types/schema/nodes/body.d.ts +17 -0
- package/dist/types/schema/nodes/citation.d.ts +3 -5
- package/dist/types/schema/nodes/comments.d.ts +17 -0
- package/dist/types/schema/nodes/contributors.d.ts +17 -0
- package/dist/types/schema/nodes/core_section.d.ts +17 -0
- package/dist/types/schema/nodes/cross_reference.d.ts +1 -1
- package/dist/types/schema/nodes/inline_footnote.d.ts +1 -1
- package/dist/types/schema/nodes/keyword.d.ts +0 -1
- package/dist/types/schema/nodes/{contributors_element.d.ts → keyword_group.d.ts} +3 -4
- package/dist/types/schema/nodes/{comment_list.d.ts → keywords.d.ts} +3 -2
- package/dist/types/schema/nodes/manuscript.d.ts +1 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/builders.d.ts +2 -14
- package/dist/types/transformer/decode.d.ts +5 -9
- package/dist/types/transformer/encode.d.ts +4 -4
- package/dist/types/transformer/highlight-markers.d.ts +7 -2
- package/dist/types/transformer/object-types.d.ts +1 -2
- package/dist/types/transformer/section-category.d.ts +4 -3
- package/package.json +1 -6
- package/dist/cjs/lib/core-section-categories.js +0 -29
- package/dist/cjs/schema/nodes/affiliations_section.js +0 -36
- package/dist/cjs/schema/nodes/contributors_element.js +0 -49
- package/dist/cjs/schema/nodes/contributors_section.js +0 -36
- package/dist/es/lib/core-section-categories.js +0 -26
- package/dist/es/schema/nodes/affiliations_section.js +0 -32
- package/dist/es/schema/nodes/contributors_element.js +0 -46
- package/dist/es/schema/nodes/contributors_section.js +0 -32
- package/dist/types/lib/core-section-categories.d.ts +0 -8
- package/dist/types/schema/nodes/affiliations_section.d.ts +0 -11
- package/dist/types/schema/nodes/contributors_section.d.ts +0 -12
- package/dist/types/schema/nodes/keywords_group.d.ts +0 -26
- package/dist/types/schema/nodes/keywords_section.d.ts +0 -26
|
@@ -13,30 +13,19 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
const isAuxiliaryObjectReference = hasObjectType(ObjectTypes.AuxiliaryObjectReference);
|
|
19
|
-
const excludedObjectTypes = [ObjectTypes.Contributor, ObjectTypes.Affiliation];
|
|
20
|
-
export function flatten(arrays) {
|
|
21
|
-
return [].concat(...arrays);
|
|
22
|
-
}
|
|
23
|
-
export const fixBodyPMNode = (output, models, referenceIdsMap = new Map()) => {
|
|
24
|
-
const replacements = referenceIdsMap;
|
|
16
|
+
import { generateID, nodeTypesMap } from '../../transformer';
|
|
17
|
+
export const updateDocumentIDs = (node, replacements) => {
|
|
25
18
|
const warnings = [];
|
|
26
|
-
recurseDoc(
|
|
27
|
-
recurseDoc(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
replacements,
|
|
31
|
-
};
|
|
19
|
+
recurseDoc(node, (n) => updateNodeID(n, replacements, warnings));
|
|
20
|
+
recurseDoc(node, (n) => updateNodeRID(n, replacements, warnings));
|
|
21
|
+
recurseDoc(node, (n) => updateNodeRIDS(n, replacements, warnings));
|
|
22
|
+
return warnings;
|
|
32
23
|
};
|
|
33
24
|
function recurseDoc(node, fn) {
|
|
34
25
|
fn(node);
|
|
35
|
-
|
|
36
|
-
node.content.forEach((n) => recurseDoc(n, fn));
|
|
37
|
-
}
|
|
26
|
+
node.descendants((n) => fn(n));
|
|
38
27
|
}
|
|
39
|
-
const
|
|
28
|
+
const updateNodeID = (node, replacements, warnings) => {
|
|
40
29
|
if (!('id' in node.attrs)) {
|
|
41
30
|
return;
|
|
42
31
|
}
|
|
@@ -45,9 +34,6 @@ const addMissingID = (node, replacements, warnings) => {
|
|
|
45
34
|
warnings.push(`Unknown object type for node type ${node.type.name}`);
|
|
46
35
|
return;
|
|
47
36
|
}
|
|
48
|
-
if (excludedObjectTypes.includes(objectType)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
37
|
const previousID = node.attrs.id;
|
|
52
38
|
const nextID = generateID(objectType);
|
|
53
39
|
if (previousID) {
|
|
@@ -60,7 +46,7 @@ const addMissingID = (node, replacements, warnings) => {
|
|
|
60
46
|
}
|
|
61
47
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { id: nextID });
|
|
62
48
|
};
|
|
63
|
-
const
|
|
49
|
+
const updateNodeRID = (node, replacements, warnings) => {
|
|
64
50
|
const previousRID = node.attrs.rid;
|
|
65
51
|
if (!('rid' in node.attrs) || !previousRID) {
|
|
66
52
|
return;
|
|
@@ -71,36 +57,12 @@ const addMissingRID = (node, replacements, warnings) => {
|
|
|
71
57
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { rid: replacements.get(previousRID) });
|
|
72
58
|
}
|
|
73
59
|
};
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
warnings.push(`Missing replacement for model.referencedObject ${referencedObject}`);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
models.forEach((model) => {
|
|
86
|
-
var _a;
|
|
87
|
-
if (isAuxiliaryObjectReference(model)) {
|
|
88
|
-
if (model.referencedObject) {
|
|
89
|
-
model.referencedObject = getReferenceId(model.referencedObject);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const referencedObjects = [];
|
|
93
|
-
(_a = model.referencedObjects) === null || _a === void 0 ? void 0 : _a.map((reference) => {
|
|
94
|
-
const referenceId = getReferenceId(reference);
|
|
95
|
-
if (referenceId) {
|
|
96
|
-
referencedObjects.push(referenceId);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
model.referencedObjects = referencedObjects;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return warnings;
|
|
60
|
+
const updateNodeRIDS = (node, replacements, warnings) => {
|
|
61
|
+
const previousRIDs = node.attrs.rids;
|
|
62
|
+
if (!('rids' in node.attrs) || !previousRIDs.length) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { rids: previousRIDs.map((r) => replacements.get(r) || r) });
|
|
104
66
|
};
|
|
105
67
|
const JATS_TO_HTML_MAPPING = new Map([
|
|
106
68
|
['bold', 'b'],
|
|
@@ -138,6 +100,6 @@ export const htmlFromJatsNode = (element, createElement) => {
|
|
|
138
100
|
return undefined;
|
|
139
101
|
}
|
|
140
102
|
const temp = createElement('template');
|
|
141
|
-
renameJatsNodesToHTML(element, temp
|
|
103
|
+
renameJatsNodesToHTML(element, temp, createElement);
|
|
142
104
|
return temp.innerHTML;
|
|
143
105
|
};
|
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { getTrimmedTextContent } from '../../lib/utils';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
17
|
+
import { buildBibliographicDate, buildBibliographicName, buildBibliographyItem, } from '../../transformer/builders';
|
|
18
|
+
import { isJATSComment, parseJATSComment } from './jats-comments';
|
|
19
|
+
import { htmlFromJatsNode } from './jats-parser-utils';
|
|
20
|
+
import { References } from './jats-references';
|
|
20
21
|
const chooseBibliographyItemType = (publicationType) => {
|
|
21
22
|
switch (publicationType) {
|
|
22
23
|
case 'book':
|
|
@@ -28,37 +29,31 @@ const chooseBibliographyItemType = (publicationType) => {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
export const jatsReferenceParser = {
|
|
31
|
-
parseReferences(
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const references = referenceNodes.map((referenceNode) => {
|
|
32
|
+
parseReferences(elements, createElement) {
|
|
33
|
+
const references = new References();
|
|
34
|
+
elements.forEach((element) => {
|
|
35
35
|
var _a;
|
|
36
|
-
const publicationType =
|
|
36
|
+
const publicationType = element.getAttribute('publication-type');
|
|
37
37
|
const authorNodes = [
|
|
38
|
-
...
|
|
38
|
+
...element.querySelectorAll('person-group[person-group-type="author"] > *'),
|
|
39
39
|
];
|
|
40
40
|
const bibliographyItem = buildBibliographyItem({
|
|
41
41
|
type: chooseBibliographyItemType(publicationType),
|
|
42
42
|
});
|
|
43
|
-
const titleNode =
|
|
43
|
+
const titleNode = element.querySelector('article-title');
|
|
44
44
|
if (titleNode) {
|
|
45
45
|
bibliographyItem.title = (_a = htmlFromJatsNode(titleNode, createElement)) === null || _a === void 0 ? void 0 : _a.trim();
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
const mixedCitation =
|
|
47
|
+
const comments = [];
|
|
48
|
+
const mixedCitation = element.querySelector('mixed-citation');
|
|
49
49
|
mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
|
|
50
|
-
if (item
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const { queryText } = instruction;
|
|
55
|
-
queriesText.push(queryText);
|
|
50
|
+
if (isJATSComment(item)) {
|
|
51
|
+
const comment = parseJATSComment(item);
|
|
52
|
+
if (comment) {
|
|
53
|
+
comments.push(comment);
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
});
|
|
59
|
-
if (queriesText.length) {
|
|
60
|
-
referenceQueries.set(bibliographyItem._id, queriesText);
|
|
61
|
-
}
|
|
62
57
|
if (authorNodes.length <= 0) {
|
|
63
58
|
mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
|
|
64
59
|
var _a, _b, _c;
|
|
@@ -69,34 +64,34 @@ export const jatsReferenceParser = {
|
|
|
69
64
|
}
|
|
70
65
|
});
|
|
71
66
|
}
|
|
72
|
-
const source = getTrimmedTextContent(
|
|
67
|
+
const source = getTrimmedTextContent(element, 'source');
|
|
73
68
|
if (source) {
|
|
74
69
|
bibliographyItem['container-title'] = source;
|
|
75
70
|
}
|
|
76
|
-
const volume = getTrimmedTextContent(
|
|
71
|
+
const volume = getTrimmedTextContent(element, 'volume');
|
|
77
72
|
if (volume) {
|
|
78
73
|
bibliographyItem.volume = volume;
|
|
79
74
|
}
|
|
80
|
-
const issue = getTrimmedTextContent(
|
|
75
|
+
const issue = getTrimmedTextContent(element, 'issue');
|
|
81
76
|
if (issue) {
|
|
82
77
|
bibliographyItem.issue = issue;
|
|
83
78
|
}
|
|
84
|
-
const supplement = getTrimmedTextContent(
|
|
79
|
+
const supplement = getTrimmedTextContent(element, 'supplement');
|
|
85
80
|
if (supplement) {
|
|
86
81
|
bibliographyItem.supplement = supplement;
|
|
87
82
|
}
|
|
88
|
-
const fpage = getTrimmedTextContent(
|
|
89
|
-
const lpage = getTrimmedTextContent(
|
|
83
|
+
const fpage = getTrimmedTextContent(element, 'fpage');
|
|
84
|
+
const lpage = getTrimmedTextContent(element, 'lpage');
|
|
90
85
|
if (fpage) {
|
|
91
86
|
bibliographyItem.page = lpage ? `${fpage}-${lpage}` : fpage;
|
|
92
87
|
}
|
|
93
|
-
const year = getTrimmedTextContent(
|
|
88
|
+
const year = getTrimmedTextContent(element, 'year');
|
|
94
89
|
if (year) {
|
|
95
90
|
bibliographyItem.issued = buildBibliographicDate({
|
|
96
91
|
'date-parts': [[year]],
|
|
97
92
|
});
|
|
98
93
|
}
|
|
99
|
-
const doi = getTrimmedTextContent(
|
|
94
|
+
const doi = getTrimmedTextContent(element, 'pub-id[pub-id-type="doi"]');
|
|
100
95
|
if (doi) {
|
|
101
96
|
bibliographyItem.DOI = doi;
|
|
102
97
|
}
|
|
@@ -124,59 +119,9 @@ export const jatsReferenceParser = {
|
|
|
124
119
|
if (authors.length) {
|
|
125
120
|
bibliographyItem.author = authors;
|
|
126
121
|
}
|
|
127
|
-
const id =
|
|
128
|
-
|
|
129
|
-
referenceIDs.set(id, bibliographyItem._id);
|
|
130
|
-
}
|
|
131
|
-
return bibliographyItem;
|
|
122
|
+
const id = element.getAttribute('id');
|
|
123
|
+
references.add(bibliographyItem, id, comments);
|
|
132
124
|
});
|
|
133
|
-
return
|
|
134
|
-
references,
|
|
135
|
-
referenceIDs,
|
|
136
|
-
referenceQueries,
|
|
137
|
-
};
|
|
138
|
-
},
|
|
139
|
-
parseCrossReferences(crossReferenceNodes, referenceIDs) {
|
|
140
|
-
return flatten(crossReferenceNodes.map((crossReferenceNode) => {
|
|
141
|
-
const rid = crossReferenceNode.getAttribute('rid');
|
|
142
|
-
if (!rid) {
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
const modelNodes = [];
|
|
146
|
-
const refType = crossReferenceNode.getAttribute('ref-type');
|
|
147
|
-
switch (refType) {
|
|
148
|
-
case 'bibr':
|
|
149
|
-
{
|
|
150
|
-
const rids = rid
|
|
151
|
-
.split(/\s+/)
|
|
152
|
-
.filter((id) => referenceIDs.has(id))
|
|
153
|
-
.map((id) => referenceIDs.get(id));
|
|
154
|
-
if (rids.length) {
|
|
155
|
-
const citation = buildCitation('', rids);
|
|
156
|
-
modelNodes.push(citation);
|
|
157
|
-
crossReferenceNode.setAttribute('rid', citation._id);
|
|
158
|
-
crossReferenceNode.setAttribute('data-reference-embedded-citation', JSON.stringify(citation.embeddedCitationItems.map(({ _id: id, bibliographyItem }) => ({
|
|
159
|
-
id,
|
|
160
|
-
bibliographyItem,
|
|
161
|
-
}))));
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
crossReferenceNode.removeAttribute('rid');
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
break;
|
|
168
|
-
case 'fn':
|
|
169
|
-
break;
|
|
170
|
-
default:
|
|
171
|
-
{
|
|
172
|
-
const rids = rid.trim().split(/\s+/);
|
|
173
|
-
const auxiliaryObjectReference = buildAuxiliaryObjectReference('', rids);
|
|
174
|
-
modelNodes.push(auxiliaryObjectReference);
|
|
175
|
-
crossReferenceNode.setAttribute('rid', auxiliaryObjectReference._id);
|
|
176
|
-
}
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
return modelNodes;
|
|
180
|
-
}));
|
|
125
|
+
return references;
|
|
181
126
|
},
|
|
182
127
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export class References {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.items = new Map();
|
|
4
|
+
this.IDs = new Map();
|
|
5
|
+
this.comments = new Map();
|
|
6
|
+
}
|
|
7
|
+
add(item, id, comments) {
|
|
8
|
+
this.items.set(item._id, item);
|
|
9
|
+
this.comments.set(item._id, comments);
|
|
10
|
+
if (id) {
|
|
11
|
+
this.IDs.set(id, item._id);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
getBibliographyItems() {
|
|
15
|
+
return [...this.items.values()];
|
|
16
|
+
}
|
|
17
|
+
getComments(id) {
|
|
18
|
+
return this.getValue(id, this.comments) || [];
|
|
19
|
+
}
|
|
20
|
+
getValue(id, map) {
|
|
21
|
+
const value = map.get(id);
|
|
22
|
+
if (value) {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
const id2 = this.IDs.get(id);
|
|
26
|
+
if (id2) {
|
|
27
|
+
return map.get(id2);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -13,220 +13,116 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { ObjectTypes, } from '@manuscripts/json-schema';
|
|
17
|
-
import { DOMParser } from 'prosemirror-model';
|
|
18
16
|
import { InvalidInput } from '../../errors';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { auxiliaryObjectTypes, nodeTypesMap } from '../../transformer';
|
|
22
|
-
import { buildElementsOrder, buildJournal, buildManuscript, } from '../../transformer/builders';
|
|
23
|
-
import { encode, inlineContents } from '../../transformer/encode';
|
|
24
|
-
import { createEmptyFootnotesOrder, createOrderedFootnotesIDs, handleFootnotesOrder, } from '../../transformer/footnotes-order';
|
|
17
|
+
import { buildBibliographyElement, buildSection, encode, } from '../../transformer';
|
|
18
|
+
import { buildManuscript } from '../../transformer/builders';
|
|
25
19
|
import { generateID } from '../../transformer/id';
|
|
26
20
|
import { findManuscript } from '../../transformer/project-bundle';
|
|
27
21
|
import { jatsBodyDOMParser } from './jats-body-dom-parser';
|
|
28
22
|
import { jatsBodyTransformations } from './jats-body-transformations';
|
|
29
|
-
import { createComments, createReferenceComments,
|
|
23
|
+
import { createComments, createReferenceComments, markComments, } from './jats-comments';
|
|
30
24
|
import { jatsFrontParser } from './jats-front-parser';
|
|
31
|
-
import {
|
|
25
|
+
import { updateDocumentIDs } from './jats-parser-utils';
|
|
32
26
|
import { jatsReferenceParser } from './jats-reference-parser';
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
topNode: schema.nodes.section_title.create(),
|
|
39
|
-
});
|
|
40
|
-
return inlineContents(titleNode);
|
|
41
|
-
}
|
|
42
|
-
throw new InvalidInput('Invalid title content for: ' + htmlTitle);
|
|
43
|
-
};
|
|
44
|
-
export const parseJATSFront = async (front) => {
|
|
45
|
-
var _a, _b, _c;
|
|
46
|
-
const journalMeta = jatsFrontParser.parseJournal(front.querySelector('journal-meta'));
|
|
47
|
-
const journal = Object.assign(Object.assign({}, buildJournal()), journalMeta);
|
|
48
|
-
const articleMeta = front.querySelector('article-meta');
|
|
49
|
-
const title = (_a = articleMeta === null || articleMeta === void 0 ? void 0 : articleMeta.querySelector('title-group > article-title')) === null || _a === void 0 ? void 0 : _a.innerHTML;
|
|
50
|
-
const subtitle = (_b = articleMeta === null || articleMeta === void 0 ? void 0 : articleMeta.querySelector('title-group > subtitle')) === null || _b === void 0 ? void 0 : _b.innerHTML;
|
|
51
|
-
const runningTitle = (_c = articleMeta === null || articleMeta === void 0 ? void 0 : articleMeta.querySelector('title-group > alt-title[alt-title-type="right-running"]')) === null || _c === void 0 ? void 0 : _c.innerHTML;
|
|
52
|
-
const manuscriptMeta = Object.assign({}, jatsFrontParser.parseCounts(articleMeta === null || articleMeta === void 0 ? void 0 : articleMeta.querySelector('counts')));
|
|
53
|
-
const titles = {
|
|
54
|
-
objectType: ObjectTypes.Titles,
|
|
55
|
-
_id: generateID(ObjectTypes.Titles),
|
|
56
|
-
title: title ? inlineContentsFromJATSTitle(title) : undefined,
|
|
57
|
-
subtitle: subtitle ? inlineContentsFromJATSTitle(subtitle) : undefined,
|
|
58
|
-
runningTitle: runningTitle
|
|
59
|
-
? inlineContentsFromJATSTitle(runningTitle)
|
|
60
|
-
: undefined,
|
|
61
|
-
};
|
|
62
|
-
const { affiliations, affiliationIDs } = jatsFrontParser.parseAffiliationNodes([
|
|
27
|
+
export const parseJATSFront = (doc, front) => {
|
|
28
|
+
const createElement = createElementFn(doc);
|
|
29
|
+
const journal = jatsFrontParser.parseJournal(front.querySelector('journal-meta'));
|
|
30
|
+
const titles = jatsFrontParser.parseTitles(front.querySelector('article-meta > title-group'), createElement);
|
|
31
|
+
const { affiliations, affiliationIDs } = jatsFrontParser.parseAffiliations([
|
|
63
32
|
...front.querySelectorAll('article-meta > contrib-group > aff'),
|
|
64
33
|
]);
|
|
65
|
-
const { footnotes, footnoteIDs } = jatsFrontParser.
|
|
34
|
+
const { footnotes, footnoteIDs } = jatsFrontParser.parseAuthorNotes([
|
|
66
35
|
...front.querySelectorAll('article-meta > author-notes > fn:not([fn-type])'),
|
|
67
36
|
]);
|
|
68
|
-
const { correspondingList, correspondingIDs } = jatsFrontParser.
|
|
37
|
+
const { correspondingList, correspondingIDs } = jatsFrontParser.parseCorresp([
|
|
69
38
|
...front.querySelectorAll('article-meta > author-notes > corresp'),
|
|
70
39
|
]);
|
|
71
|
-
const authors = jatsFrontParser.
|
|
40
|
+
const authors = jatsFrontParser.parseContributors([
|
|
72
41
|
...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
|
|
73
42
|
], affiliationIDs, footnoteIDs, correspondingIDs);
|
|
74
|
-
const history = jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
|
|
75
43
|
const supplements = jatsFrontParser.parseSupplements([
|
|
76
44
|
...front.querySelectorAll('article-meta > supplementary-material'),
|
|
77
45
|
]);
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
};
|
|
92
|
-
export const parseJATSReferences = (back, body, createElement) => {
|
|
93
|
-
const bibliographyItems = [];
|
|
94
|
-
const crossReferences = [];
|
|
95
|
-
let referenceQueriesMap;
|
|
96
|
-
let referenceIdsMap;
|
|
97
|
-
if (back) {
|
|
98
|
-
const { references, referenceIDs, referenceQueries } = jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
|
|
99
|
-
bibliographyItems.push(...references);
|
|
100
|
-
referenceQueriesMap = new Map([...referenceQueries]);
|
|
101
|
-
referenceIdsMap = new Map([...referenceIDs]);
|
|
102
|
-
if (body) {
|
|
103
|
-
crossReferences.push(...jatsReferenceParser.parseCrossReferences([...body.querySelectorAll('xref'), ...back.querySelectorAll('xref')], referenceIDs));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
references: generateModelIDs(bibliographyItems),
|
|
108
|
-
crossReferences: generateModelIDs(crossReferences),
|
|
109
|
-
referenceQueriesMap,
|
|
110
|
-
referenceIdsMap,
|
|
111
|
-
};
|
|
46
|
+
const history = jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
|
|
47
|
+
const counts = jatsFrontParser.parseCounts(front.querySelector('article-meta counts'));
|
|
48
|
+
const manuscript = Object.assign(Object.assign(Object.assign({}, buildManuscript()), counts), history);
|
|
49
|
+
return generateIDs([
|
|
50
|
+
manuscript,
|
|
51
|
+
titles,
|
|
52
|
+
journal,
|
|
53
|
+
...footnotes,
|
|
54
|
+
...authors,
|
|
55
|
+
...affiliations,
|
|
56
|
+
...correspondingList,
|
|
57
|
+
...supplements,
|
|
58
|
+
]);
|
|
112
59
|
};
|
|
113
|
-
export const parseJATSBody = (
|
|
114
|
-
const createElement = createElementFn(
|
|
115
|
-
const orderedFootnotesIDs = createOrderedFootnotesIDs(document);
|
|
116
|
-
jatsBodyTransformations.moveFloatsGroupToBody(document, body, createElement);
|
|
60
|
+
export const parseJATSBody = (doc, body, references) => {
|
|
61
|
+
const createElement = createElementFn(doc);
|
|
117
62
|
jatsBodyTransformations.ensureSection(body, createElement);
|
|
118
|
-
jatsBodyTransformations.moveSectionsToBody(document, body, bibliographyItems, createElement);
|
|
119
63
|
jatsBodyTransformations.moveCaptionsToEnd(body);
|
|
64
|
+
jatsBodyTransformations.fixTables(body, createElement);
|
|
120
65
|
jatsBodyTransformations.moveTableFooterToEnd(body);
|
|
121
|
-
jatsBodyTransformations.
|
|
122
|
-
jatsBodyTransformations.
|
|
123
|
-
jatsBodyTransformations.
|
|
124
|
-
jatsBodyTransformations.
|
|
125
|
-
const node = jatsBodyDOMParser.parse(body);
|
|
126
|
-
if (!node
|
|
66
|
+
jatsBodyTransformations.createBody(doc, body, createElement);
|
|
67
|
+
jatsBodyTransformations.createAbstracts(doc, body, createElement);
|
|
68
|
+
jatsBodyTransformations.createBackmatter(doc, body, createElement);
|
|
69
|
+
jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
70
|
+
const node = jatsBodyDOMParser.parse(body).firstChild;
|
|
71
|
+
if (!node) {
|
|
127
72
|
throw new Error('No content was parsed from the JATS article body');
|
|
128
73
|
}
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
return node.firstChild;
|
|
74
|
+
const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
|
|
75
|
+
updateDocumentIDs(node, replacements);
|
|
76
|
+
return encode(node).values();
|
|
134
77
|
};
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const tbody = table.querySelector('tbody');
|
|
147
|
-
if (tbody) {
|
|
148
|
-
const headerRow = table.querySelector('thead > tr');
|
|
149
|
-
if (!headerRow) {
|
|
150
|
-
const tr = createElement('tr');
|
|
151
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
152
|
-
}
|
|
153
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
154
|
-
if (!footerRow) {
|
|
155
|
-
const tr = createElement('tr');
|
|
156
|
-
tbody.appendChild(tr);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
});
|
|
78
|
+
const createBibliographyModels = (references) => {
|
|
79
|
+
const models = [];
|
|
80
|
+
const bibliographyItems = references.getBibliographyItems();
|
|
81
|
+
const bibliographyElement = buildBibliographyElement(bibliographyItems);
|
|
82
|
+
const bibliographySection = Object.assign(Object.assign({}, buildSection(99)), { category: 'MPSectionCategory:bibliography', elementIDs: [bibliographyElement._id], title: 'References' });
|
|
83
|
+
const comments = createReferenceComments(references);
|
|
84
|
+
models.push(bibliographySection);
|
|
85
|
+
models.push(bibliographyElement);
|
|
86
|
+
models.push(...bibliographyItems);
|
|
87
|
+
models.push(...comments);
|
|
88
|
+
return models;
|
|
160
89
|
};
|
|
161
90
|
const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
|
|
162
|
-
const
|
|
163
|
-
export const parseJATSArticle =
|
|
164
|
-
const
|
|
91
|
+
const generateIDs = (models) => models.map((m) => m._id ? m : Object.assign(Object.assign({}, m), { _id: generateID(m.objectType) }));
|
|
92
|
+
export const parseJATSArticle = (doc) => {
|
|
93
|
+
const article = doc.querySelector('article');
|
|
165
94
|
const front = doc.querySelector('front');
|
|
166
95
|
const body = doc.querySelector('body');
|
|
167
96
|
const back = doc.querySelector('back');
|
|
168
97
|
if (!front) {
|
|
169
98
|
throw new InvalidInput('Invalid JATS format! Missing front element');
|
|
170
99
|
}
|
|
171
|
-
if (!
|
|
100
|
+
if (!article) {
|
|
172
101
|
throw new InvalidInput('Invalid JATS format! Missing article element');
|
|
173
102
|
}
|
|
174
|
-
const
|
|
175
|
-
const createElement = createElementFn(
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
103
|
+
const marks = markComments(doc);
|
|
104
|
+
const createElement = createElementFn(doc);
|
|
105
|
+
const models = [];
|
|
106
|
+
let references;
|
|
107
|
+
if (back) {
|
|
108
|
+
references = jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
|
|
109
|
+
}
|
|
110
|
+
models.push(...parseJATSFront(doc, front));
|
|
182
111
|
if (body) {
|
|
183
|
-
|
|
184
|
-
bodyModels.push(...encode(bodyDoc).values());
|
|
185
|
-
elementsOrder = getElementsOrder(bodyDoc);
|
|
112
|
+
models.push(...parseJATSBody(doc, body, references));
|
|
186
113
|
}
|
|
187
|
-
const
|
|
188
|
-
const manuscript = findManuscript(
|
|
114
|
+
const modelMap = new Map(models.map((model) => [model._id, model]));
|
|
115
|
+
const manuscript = findManuscript(modelMap);
|
|
189
116
|
if (manuscript) {
|
|
190
|
-
const
|
|
191
|
-
manuscript.articleType =
|
|
117
|
+
const type = article.getAttribute('article-type');
|
|
118
|
+
manuscript.articleType = type || 'other';
|
|
192
119
|
}
|
|
193
|
-
|
|
194
|
-
...
|
|
195
|
-
...bodyModels,
|
|
196
|
-
...crossReferences,
|
|
197
|
-
...elementsOrder,
|
|
198
|
-
];
|
|
199
|
-
if (footnotesOrder.footnotesList.length > 0) {
|
|
200
|
-
models.push(footnotesOrder);
|
|
120
|
+
if (references) {
|
|
121
|
+
models.push(...createBibliographyModels(references));
|
|
201
122
|
}
|
|
202
|
-
if (
|
|
203
|
-
const
|
|
204
|
-
models.push(...
|
|
123
|
+
if (marks.length) {
|
|
124
|
+
const comments = createComments(models, marks);
|
|
125
|
+
models.push(...comments);
|
|
205
126
|
}
|
|
206
|
-
if (referenceQueriesMap && referenceQueriesMap.size) {
|
|
207
|
-
const commentAnnotations = createReferenceComments(referenceQueriesMap, references);
|
|
208
|
-
models.push(...commentAnnotations);
|
|
209
|
-
}
|
|
210
|
-
return models;
|
|
211
|
-
};
|
|
212
|
-
export const getElementsOrder = (node) => {
|
|
213
|
-
const elementsOrderIndex = new Map();
|
|
214
|
-
const models = [];
|
|
215
|
-
node.descendants((child) => {
|
|
216
|
-
const type = child.type;
|
|
217
|
-
if (auxiliaryObjectTypes.has(type)) {
|
|
218
|
-
const index = elementsOrderIndex.get(type);
|
|
219
|
-
if (index !== undefined) {
|
|
220
|
-
const elementsOrder = models[index];
|
|
221
|
-
elementsOrder.elements.push(child.attrs['id']);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
const elementsOrder = buildElementsOrder(nodeTypesMap.get(type));
|
|
225
|
-
elementsOrder.elements.push(child.attrs['id']);
|
|
226
|
-
models.push(elementsOrder);
|
|
227
|
-
elementsOrderIndex.set(type, elementsOrderIndex.size);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
127
|
return models;
|
|
232
128
|
};
|
package/dist/es/jats/index.js
CHANGED
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export { parseJATSFront,
|
|
16
|
+
export { parseJATSFront, parseJATSBody, parseJATSArticle } from './importer';
|
|
17
17
|
export * from './jats-exporter';
|
|
18
18
|
export * from './jats-versions';
|