@manuscripts/transform 2.3.37 → 2.3.38-LEAN-3911.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 +6 -6
- package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +263 -390
- package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
- package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
- package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
- package/dist/cjs/jats/importer/jats-body-transformations.js +73 -0
- package/dist/cjs/jats/importer/jats-comments.js +27 -104
- package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +281 -10
- package/dist/cjs/jats/importer/jats-front-transformations.js +79 -0
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
- package/dist/cjs/jats/importer/jats-parser-utils.js +43 -5
- package/dist/cjs/jats/importer/jats-reference-parser.js +16 -23
- package/dist/cjs/jats/importer/jats-references.js +18 -18
- package/dist/cjs/jats/importer/parse-jats-article.js +40 -78
- package/dist/cjs/jats/index.js +7 -7
- package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
- package/dist/cjs/lib/utils.js +12 -1
- package/dist/cjs/transformer/id.js +10 -5
- package/dist/cjs/transformer/index.js +0 -18
- package/dist/cjs/version.js +1 -1
- package/dist/es/index.js +5 -5
- package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +257 -384
- package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
- package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
- package/dist/es/{transformer/filename.js → jats/importer/create-article-node.js} +8 -7
- package/dist/es/jats/importer/jats-body-transformations.js +73 -0
- package/dist/es/jats/importer/jats-comments.js +26 -101
- package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +282 -11
- package/dist/es/jats/importer/jats-front-transformations.js +76 -0
- package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
- package/dist/es/jats/importer/jats-parser-utils.js +44 -6
- package/dist/es/jats/importer/jats-reference-parser.js +16 -23
- package/dist/es/jats/importer/jats-references.js +18 -18
- package/dist/es/jats/importer/parse-jats-article.js +41 -77
- package/dist/es/jats/index.js +5 -3
- package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
- package/dist/es/lib/utils.js +9 -0
- package/dist/es/transformer/id.js +8 -3
- package/dist/es/transformer/index.js +0 -16
- package/dist/es/version.js +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
- package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
- package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
- package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
- package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
- package/dist/types/jats/importer/jats-comments.d.ts +4 -10
- package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
- package/dist/{cjs/transformer/serializer.js → types/jats/importer/jats-front-transformations.d.ts} +7 -8
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
- package/dist/types/jats/importer/jats-references.d.ts +19 -8
- package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
- package/dist/types/jats/index.d.ts +5 -3
- package/dist/types/jats/types.d.ts +1 -0
- package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
- package/dist/types/lib/utils.d.ts +2 -0
- package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
- package/dist/types/schema/nodes/contributor.d.ts +10 -0
- package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
- package/dist/types/schema/nodes/manuscript.d.ts +8 -7
- package/dist/types/schema/nodes/title.d.ts +0 -3
- package/dist/types/transformer/id.d.ts +5 -2
- package/dist/types/transformer/index.d.ts +0 -16
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -1
- package/dist/cjs/__tests__/data/project-dump.json +0 -825
- package/dist/cjs/jats/importer/index.js +0 -22
- package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
- package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
- package/dist/cjs/transformer/builders.js +0 -219
- package/dist/cjs/transformer/decode.js +0 -874
- package/dist/cjs/transformer/document-object-types.js +0 -31
- package/dist/cjs/transformer/encode.js +0 -664
- package/dist/cjs/transformer/footnote-category.js +0 -20
- package/dist/cjs/transformer/footnotes-order.js +0 -60
- package/dist/cjs/transformer/highlight-markers.js +0 -138
- package/dist/cjs/transformer/html.js +0 -400
- package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
- package/dist/cjs/transformer/model-map.js +0 -26
- package/dist/cjs/transformer/object-types.js +0 -57
- package/dist/cjs/transformer/project-bundle.js +0 -94
- package/dist/cjs/transformer/timestamp.js +0 -20
- package/dist/cjs/transformer/update-identifiers.js +0 -93
- package/dist/es/__tests__/data/project-dump.json +0 -825
- package/dist/es/jats/importer/index.js +0 -16
- package/dist/es/jats/importer/jats-front-parser.js +0 -315
- package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
- package/dist/es/transformer/builders.js +0 -186
- package/dist/es/transformer/decode.js +0 -864
- package/dist/es/transformer/document-object-types.js +0 -28
- package/dist/es/transformer/encode.js +0 -654
- package/dist/es/transformer/footnotes-order.js +0 -55
- package/dist/es/transformer/highlight-markers.js +0 -132
- package/dist/es/transformer/html.js +0 -393
- package/dist/es/transformer/manuscript-dependencies.js +0 -17
- package/dist/es/transformer/model-map.js +0 -22
- package/dist/es/transformer/object-types.js +0 -52
- package/dist/es/transformer/project-bundle.js +0 -85
- package/dist/es/transformer/serializer.js +0 -17
- package/dist/es/transformer/timestamp.js +0 -16
- package/dist/es/transformer/update-identifiers.js +0 -87
- package/dist/types/jats/importer/index.d.ts +0 -16
- package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
- package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
- package/dist/types/transformer/builders.d.ts +0 -61
- package/dist/types/transformer/decode.d.ts +0 -51
- package/dist/types/transformer/document-object-types.d.ts +0 -17
- package/dist/types/transformer/encode.d.ts +0 -29
- package/dist/types/transformer/filename.d.ts +0 -16
- package/dist/types/transformer/footnote-category.d.ts +0 -17
- package/dist/types/transformer/footnotes-order.d.ts +0 -22
- package/dist/types/transformer/highlight-markers.d.ts +0 -31
- package/dist/types/transformer/html.d.ts +0 -36
- package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
- package/dist/types/transformer/model-map.d.ts +0 -19
- package/dist/types/transformer/models.d.ts +0 -48
- package/dist/types/transformer/object-types.d.ts +0 -30
- package/dist/types/transformer/project-bundle.d.ts +0 -30
- package/dist/types/transformer/serializer.d.ts +0 -19
- package/dist/types/transformer/update-identifiers.d.ts +0 -23
- package/dist/types/types.d.ts +0 -2
- /package/dist/cjs/{types.js → jats/types.js} +0 -0
- /package/dist/es/{types.js → jats/types.js} +0 -0
|
@@ -27,7 +27,6 @@ const versions = {
|
|
|
27
27
|
systemId: 'http://jats.nlm.nih.gov/archiving/1.2/JATS-archive-oasis-article1-mathml3.dtd',
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
|
-
export const supportedVersions = () => Object.keys(versions);
|
|
31
30
|
export const selectVersionIds = (version) => {
|
|
32
31
|
if (!(version in versions)) {
|
|
33
32
|
throw new Error(`Unknown version ${version}`);
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { schema } from '
|
|
17
|
-
import { nodeNames } from '
|
|
16
|
+
import { schema, } from '../../schema';
|
|
17
|
+
import { nodeNames } from '../../transformer/node-names';
|
|
18
18
|
const labelledNodeTypes = [
|
|
19
19
|
schema.nodes.figure_element,
|
|
20
20
|
schema.nodes.table_element,
|
|
@@ -25,7 +25,7 @@ const excludedTypes = [schema.nodes.graphical_abstract_section];
|
|
|
25
25
|
const chooseLabel = (nodeType) => {
|
|
26
26
|
return nodeNames.get(nodeType);
|
|
27
27
|
};
|
|
28
|
-
export const buildTargets = (
|
|
28
|
+
export const buildTargets = (node) => {
|
|
29
29
|
const counters = {};
|
|
30
30
|
for (const nodeType of labelledNodeTypes) {
|
|
31
31
|
counters[nodeType.name] = {
|
|
@@ -39,7 +39,7 @@ export const buildTargets = (fragment) => {
|
|
|
39
39
|
return `${counter.label} ${counter.index}`;
|
|
40
40
|
};
|
|
41
41
|
const targets = new Map();
|
|
42
|
-
|
|
42
|
+
node.descendants((node, pos, parent) => {
|
|
43
43
|
var _a;
|
|
44
44
|
if (node.type.name in counters) {
|
|
45
45
|
if (parent && excludedTypes.includes(parent.type)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ©
|
|
2
|
+
* © 2024 Atypon Systems LLC
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
import { defaultTitle } from '../../lib/deafults';
|
|
17
|
+
import { schema } from '../../schema';
|
|
18
|
+
export const createArticleNode = (attrs) => {
|
|
19
|
+
const title = schema.nodes.title.createChecked({}, schema.text(defaultTitle));
|
|
20
|
+
if (!attrs.id) {
|
|
21
|
+
throw new Error('Manuscript ID is missing');
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
return `${basename}.${mimeSubType}`;
|
|
23
|
+
return schema.nodes.manuscript.createAndFill(attrs, title);
|
|
23
24
|
};
|
|
@@ -299,4 +299,77 @@ export const jatsBodyTransformations = {
|
|
|
299
299
|
body.prepend(section);
|
|
300
300
|
}
|
|
301
301
|
},
|
|
302
|
+
moveReferencesToBackmatter(body, references, createElement) {
|
|
303
|
+
const backmatter = body.querySelector('sec[sec-type="backmatter"]');
|
|
304
|
+
if (!references || !references.items.size || !backmatter) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const bibliographySection = this.createBibliographySection(createElement);
|
|
308
|
+
const bibliographyElement = createElement('bibliography-element');
|
|
309
|
+
references.getBibliographyItems().forEach((item) => {
|
|
310
|
+
const bibliographyItem = this.createBibliographyItem(item, createElement);
|
|
311
|
+
bibliographyElement.appendChild(bibliographyItem);
|
|
312
|
+
});
|
|
313
|
+
bibliographySection.appendChild(bibliographyElement);
|
|
314
|
+
backmatter.appendChild(bibliographySection);
|
|
315
|
+
},
|
|
316
|
+
createBibliographySection(createElement) {
|
|
317
|
+
const section = createElement('sec');
|
|
318
|
+
section.setAttribute('sec-type', 'bibliography_section');
|
|
319
|
+
const title = createElement('title');
|
|
320
|
+
title.textContent = 'References';
|
|
321
|
+
section.appendChild(title);
|
|
322
|
+
return section;
|
|
323
|
+
},
|
|
324
|
+
createBibliographyItem(item, createElement) {
|
|
325
|
+
var _a, _b, _c;
|
|
326
|
+
const bibliographyItem = createElement('bibliography-item');
|
|
327
|
+
bibliographyItem.setAttribute('id', item.id);
|
|
328
|
+
bibliographyItem.setAttribute('type', item.type);
|
|
329
|
+
(_a = item.author) === null || _a === void 0 ? void 0 : _a.forEach((author) => {
|
|
330
|
+
const authorElement = createElement('author');
|
|
331
|
+
authorElement.setAttribute('id', author._id);
|
|
332
|
+
authorElement.setAttribute('family', author.family || '');
|
|
333
|
+
authorElement.setAttribute('given', author.given || '');
|
|
334
|
+
bibliographyItem.appendChild(authorElement);
|
|
335
|
+
});
|
|
336
|
+
if (item.issued) {
|
|
337
|
+
const issuedEl = createElement('issued');
|
|
338
|
+
issuedEl.setAttribute('id', ((_b = item.issued) === null || _b === void 0 ? void 0 : _b._id) || '');
|
|
339
|
+
const dateParts = item.issued['date-parts'];
|
|
340
|
+
const year = (_c = dateParts === null || dateParts === void 0 ? void 0 : dateParts[0]) === null || _c === void 0 ? void 0 : _c[0];
|
|
341
|
+
if (year) {
|
|
342
|
+
issuedEl.setAttribute('year', year.toString());
|
|
343
|
+
}
|
|
344
|
+
bibliographyItem.appendChild(issuedEl);
|
|
345
|
+
}
|
|
346
|
+
if (item.containerTitle) {
|
|
347
|
+
bibliographyItem.setAttribute('containerTitle', item.containerTitle);
|
|
348
|
+
}
|
|
349
|
+
if (item.volume) {
|
|
350
|
+
bibliographyItem.setAttribute('volume', item.volume.toString());
|
|
351
|
+
}
|
|
352
|
+
if (item.issue) {
|
|
353
|
+
bibliographyItem.setAttribute('issue', item.issue.toString());
|
|
354
|
+
}
|
|
355
|
+
if (item.supplement) {
|
|
356
|
+
bibliographyItem.setAttribute('supplement', item.supplement);
|
|
357
|
+
}
|
|
358
|
+
if (item.page) {
|
|
359
|
+
bibliographyItem.setAttribute('page', item.page.toString());
|
|
360
|
+
}
|
|
361
|
+
if (item.title) {
|
|
362
|
+
bibliographyItem.setAttribute('title', item.title);
|
|
363
|
+
}
|
|
364
|
+
if (item.literal) {
|
|
365
|
+
bibliographyItem.setAttribute('literal', item.literal);
|
|
366
|
+
}
|
|
367
|
+
if (item.doi) {
|
|
368
|
+
bibliographyItem.setAttribute('DOI', item.doi);
|
|
369
|
+
}
|
|
370
|
+
if (item.literal) {
|
|
371
|
+
bibliographyItem.setAttribute('literal', item.literal);
|
|
372
|
+
}
|
|
373
|
+
return bibliographyItem;
|
|
374
|
+
},
|
|
302
375
|
};
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
16
|
+
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
|
+
import { generateID } from '../../transformer';
|
|
18
|
+
export const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
19
19
|
export const isJATSComment = (node) => {
|
|
20
20
|
return (node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
|
|
21
21
|
node.nodeName === 'AuthorQuery');
|
|
@@ -23,34 +23,33 @@ export const isJATSComment = (node) => {
|
|
|
23
23
|
export const parseJATSComment = (node) => {
|
|
24
24
|
const text = node.textContent;
|
|
25
25
|
if (text) {
|
|
26
|
-
const id = /id="(.+)"/.exec(text);
|
|
27
26
|
const queryText = /queryText="(.+)"/.exec(text);
|
|
28
|
-
if (
|
|
27
|
+
if (queryText) {
|
|
28
|
+
const parentNode = node.parentNode;
|
|
29
|
+
const index = parentNode.outerHTML.indexOf(queryText[1]);
|
|
29
30
|
return {
|
|
30
|
-
id:
|
|
31
|
+
id: generateID(ObjectTypes.CommentAnnotation),
|
|
31
32
|
text: queryText[1],
|
|
33
|
+
index,
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
};
|
|
36
38
|
export const markComments = (doc) => {
|
|
37
|
-
|
|
39
|
+
var _a;
|
|
38
40
|
const root = doc.getRootNode();
|
|
39
41
|
const queue = [root];
|
|
42
|
+
const commentsElement = doc.createElement('comments-annotations');
|
|
40
43
|
while (queue.length !== 0) {
|
|
41
44
|
const node = queue.shift();
|
|
42
45
|
if (node) {
|
|
43
46
|
if (isJATSComment(node)) {
|
|
44
47
|
const comment = parseJATSComment(node);
|
|
45
48
|
if (comment) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
comment,
|
|
51
|
-
};
|
|
52
|
-
marks.push(mark);
|
|
53
|
-
}
|
|
49
|
+
const highlightMarker = createHighlightMarkerElement(doc, comment.id);
|
|
50
|
+
(_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(highlightMarker, node);
|
|
51
|
+
const commentElement = createCommentElement(doc, comment);
|
|
52
|
+
commentsElement.appendChild(commentElement);
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
node.childNodes.forEach((child) => {
|
|
@@ -58,93 +57,19 @@ export const markComments = (doc) => {
|
|
|
58
57
|
});
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const addMark = (doc, node) => {
|
|
64
|
-
const parent = node.parentElement;
|
|
65
|
-
if (parent) {
|
|
66
|
-
const token = uuidv4();
|
|
67
|
-
const tokenNode = doc.createTextNode(token);
|
|
68
|
-
parent.insertBefore(tokenNode, node);
|
|
69
|
-
return token;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
export const createComments = (models, marks) => {
|
|
73
|
-
const comments = [];
|
|
74
|
-
for (const model of models) {
|
|
75
|
-
if (isHighlightableModel(model)) {
|
|
76
|
-
comments.push(...processModel(model, marks));
|
|
77
|
-
}
|
|
78
|
-
else if (isKeyword(model)) {
|
|
79
|
-
comments.push(...processKeyword(model, marks));
|
|
80
|
-
}
|
|
60
|
+
if (commentsElement.hasChildNodes()) {
|
|
61
|
+
doc.documentElement.appendChild(commentsElement);
|
|
81
62
|
}
|
|
82
|
-
return comments;
|
|
83
|
-
};
|
|
84
|
-
const getFieldMarks = (content, marks) => {
|
|
85
|
-
return marks
|
|
86
|
-
.filter((m) => content.indexOf(m.token) >= 0)
|
|
87
|
-
.sort((a, b) => content.indexOf(a.token) - content.indexOf(b.token));
|
|
88
63
|
};
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const results = processContent(model, content, getFieldMarks(content, marks));
|
|
97
|
-
model[field] = results.content;
|
|
98
|
-
comments.push(...results.comments);
|
|
99
|
-
}
|
|
100
|
-
return comments;
|
|
64
|
+
const createHighlightMarkerElement = (doc, id) => {
|
|
65
|
+
const highlightMarker = doc.createElement('highlight-marker');
|
|
66
|
+
highlightMarker.setAttribute('id', id);
|
|
67
|
+
highlightMarker.setAttribute('position', 'point');
|
|
68
|
+
return highlightMarker;
|
|
101
69
|
};
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
content = name.replace(mark.token, '');
|
|
108
|
-
const target = model.containedGroup;
|
|
109
|
-
if (!target) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
|
|
113
|
-
const comment = buildComment(target, mark.comment.text, undefined, contributions);
|
|
114
|
-
model.name = content;
|
|
115
|
-
comments.push(comment);
|
|
116
|
-
}
|
|
117
|
-
return comments;
|
|
118
|
-
};
|
|
119
|
-
const processContent = (model, content, marks) => {
|
|
120
|
-
const comments = [];
|
|
121
|
-
let result = content;
|
|
122
|
-
for (const mark of marks) {
|
|
123
|
-
const token = mark.token;
|
|
124
|
-
const index = result.indexOf(token);
|
|
125
|
-
result = result.replace(token, '');
|
|
126
|
-
const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
|
|
127
|
-
const selector = {
|
|
128
|
-
from: index,
|
|
129
|
-
to: index,
|
|
130
|
-
};
|
|
131
|
-
const comment = buildComment(model._id, mark.comment.text, selector, contributions);
|
|
132
|
-
comments.push(comment);
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
content: result,
|
|
136
|
-
comments,
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
export const createReferenceComments = (references) => {
|
|
140
|
-
const comments = [];
|
|
141
|
-
for (const item of references.getBibliographyItems()) {
|
|
142
|
-
const id = item._id;
|
|
143
|
-
for (const comment of references.getComments(id)) {
|
|
144
|
-
const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
|
|
145
|
-
const c = buildComment(id, comment.text, undefined, contributions);
|
|
146
|
-
comments.push(c);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return comments;
|
|
70
|
+
const createCommentElement = (doc, comment) => {
|
|
71
|
+
const commentElement = doc.createElement('comment-annotation');
|
|
72
|
+
commentElement.setAttribute('id', comment.id);
|
|
73
|
+
commentElement.textContent = comment.text;
|
|
74
|
+
return commentElement;
|
|
150
75
|
};
|
|
@@ -13,10 +13,13 @@
|
|
|
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';
|
|
16
17
|
import mime from 'mime';
|
|
17
18
|
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
19
|
+
import { getTrimmedTextContent, timestamp } from '../../lib/utils';
|
|
20
|
+
import { schema, } from '../../schema';
|
|
21
|
+
import { chooseSectionCategory, generateID } from '../../transformer';
|
|
22
|
+
import { DEFAULT_PROFILE_ID } from './jats-comments';
|
|
20
23
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
21
24
|
const chooseContentType = (graphicNode) => {
|
|
22
25
|
if (graphicNode) {
|
|
@@ -31,6 +34,12 @@ const chooseContentType = (graphicNode) => {
|
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
};
|
|
37
|
+
const parsePriority = (priority) => {
|
|
38
|
+
if (!priority) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return parseInt(priority);
|
|
42
|
+
};
|
|
34
43
|
const getEquationContent = (p) => {
|
|
35
44
|
var _a;
|
|
36
45
|
const element = p;
|
|
@@ -95,6 +104,224 @@ const marks = [
|
|
|
95
104
|
},
|
|
96
105
|
];
|
|
97
106
|
const nodes = [
|
|
107
|
+
{
|
|
108
|
+
tag: 'article',
|
|
109
|
+
node: 'manuscript',
|
|
110
|
+
getAttrs: (node) => {
|
|
111
|
+
var _a, _b, _c, _d;
|
|
112
|
+
const element = node;
|
|
113
|
+
return {
|
|
114
|
+
doi: (_a = element.getAttribute('DOI')) !== null && _a !== void 0 ? _a : '',
|
|
115
|
+
articleType: (_b = element.getAttribute('article-type')) !== null && _b !== void 0 ? _b : '',
|
|
116
|
+
prototype: (_c = element.getAttribute('prototype')) !== null && _c !== void 0 ? _c : '',
|
|
117
|
+
primaryLanguageCode: (_d = element.getAttribute('primary-language-code')) !== null && _d !== void 0 ? _d : '',
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
tag: 'article-title',
|
|
123
|
+
node: 'title',
|
|
124
|
+
getAttrs: (node) => {
|
|
125
|
+
const element = node;
|
|
126
|
+
return {
|
|
127
|
+
id: element.getAttribute('id'),
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
tag: 'highlight-marker',
|
|
133
|
+
node: 'highlight_marker',
|
|
134
|
+
getAttrs: (node) => {
|
|
135
|
+
var _a;
|
|
136
|
+
const element = node;
|
|
137
|
+
const id = element.getAttribute('id');
|
|
138
|
+
return {
|
|
139
|
+
id: id,
|
|
140
|
+
position: (_a = element.getAttribute('position')) !== null && _a !== void 0 ? _a : '',
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
tag: 'comment-annotation',
|
|
146
|
+
node: 'comment',
|
|
147
|
+
getAttrs: (node) => {
|
|
148
|
+
const element = node;
|
|
149
|
+
return {
|
|
150
|
+
id: element.getAttribute('id'),
|
|
151
|
+
contents: element.textContent,
|
|
152
|
+
contributions: [
|
|
153
|
+
{
|
|
154
|
+
_id: generateID(ObjectTypes.Contribution),
|
|
155
|
+
objecType: ObjectTypes.Contribution,
|
|
156
|
+
profileID: DEFAULT_PROFILE_ID,
|
|
157
|
+
timestamp: timestamp(),
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
tag: 'author-notes',
|
|
165
|
+
node: 'author_notes',
|
|
166
|
+
getAttrs: (node) => {
|
|
167
|
+
const element = node;
|
|
168
|
+
return {
|
|
169
|
+
id: element.getAttribute('id'),
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
tag: 'fn:not([fn-type])',
|
|
175
|
+
node: 'footnote',
|
|
176
|
+
context: 'author_notes/',
|
|
177
|
+
getAttrs: (node) => {
|
|
178
|
+
const element = node;
|
|
179
|
+
return {
|
|
180
|
+
id: element.getAttribute('id'),
|
|
181
|
+
kind: 'footnote',
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
tag: 'corresp',
|
|
187
|
+
node: 'corresp',
|
|
188
|
+
getAttrs: (node) => {
|
|
189
|
+
var _a;
|
|
190
|
+
const element = node;
|
|
191
|
+
const label = element.querySelector('label');
|
|
192
|
+
if (label) {
|
|
193
|
+
label.remove();
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
id: element.getAttribute('id'),
|
|
197
|
+
label: (_a = label === null || label === void 0 ? void 0 : label.textContent) === null || _a === void 0 ? void 0 : _a.trim(),
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
getContent: (node) => {
|
|
201
|
+
var _a;
|
|
202
|
+
const element = node;
|
|
203
|
+
return Fragment.from(schema.text(((_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || ''));
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
tag: 'contrib[contrib-type="author"]',
|
|
208
|
+
node: 'contributor',
|
|
209
|
+
getAttrs: (node) => {
|
|
210
|
+
var _a, _b;
|
|
211
|
+
const element = node;
|
|
212
|
+
const footnote = [];
|
|
213
|
+
const affiliations = [];
|
|
214
|
+
const corresp = [];
|
|
215
|
+
const xrefs = element.querySelectorAll('xref');
|
|
216
|
+
for (const xref of xrefs) {
|
|
217
|
+
const rid = xref.getAttribute('rid');
|
|
218
|
+
const type = xref.getAttribute('ref-type');
|
|
219
|
+
if (!rid) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
switch (type) {
|
|
223
|
+
case 'fn':
|
|
224
|
+
footnote.push({
|
|
225
|
+
noteID: rid,
|
|
226
|
+
noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
|
|
227
|
+
});
|
|
228
|
+
break;
|
|
229
|
+
case 'corresp':
|
|
230
|
+
corresp.push({
|
|
231
|
+
correspID: rid,
|
|
232
|
+
correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
|
|
233
|
+
});
|
|
234
|
+
break;
|
|
235
|
+
case 'aff':
|
|
236
|
+
affiliations.push(rid);
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
id: element.getAttribute('id'),
|
|
242
|
+
role: 'author',
|
|
243
|
+
affiliations,
|
|
244
|
+
corresp,
|
|
245
|
+
footnote,
|
|
246
|
+
isCorresponding: element.getAttribute('corresp')
|
|
247
|
+
? element.getAttribute('corresp') === 'yes'
|
|
248
|
+
: undefined,
|
|
249
|
+
bibliographicName: {
|
|
250
|
+
given: getTrimmedTextContent(element, 'name > given-names'),
|
|
251
|
+
family: getTrimmedTextContent(element, 'name > surname'),
|
|
252
|
+
ObjectType: ObjectTypes.BibliographicName,
|
|
253
|
+
_id: generateID(ObjectTypes.BibliographicName),
|
|
254
|
+
},
|
|
255
|
+
ORCIDIdentifier: getTrimmedTextContent(element, 'contrib-id[contrib-id-type="orcid"]'),
|
|
256
|
+
priority: parsePriority(element.getAttribute('priority')),
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
getContent: () => {
|
|
260
|
+
return Fragment.from(schema.text('_'));
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
tag: 'affiliations',
|
|
265
|
+
node: 'affiliations',
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
tag: 'aff',
|
|
269
|
+
node: 'affiliation',
|
|
270
|
+
context: 'affiliations/',
|
|
271
|
+
getAttrs: (node) => {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
const element = node;
|
|
274
|
+
const getEmail = (element) => {
|
|
275
|
+
var _a, _b, _c;
|
|
276
|
+
const email = element.querySelector('email');
|
|
277
|
+
if (email) {
|
|
278
|
+
return {
|
|
279
|
+
href: (_a = email.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _a !== void 0 ? _a : '',
|
|
280
|
+
text: (_c = (_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '',
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const getInstitutionDetails = (element) => {
|
|
285
|
+
var _a;
|
|
286
|
+
let department = '';
|
|
287
|
+
let institution = '';
|
|
288
|
+
for (const node of element.querySelectorAll('institution')) {
|
|
289
|
+
const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
290
|
+
if (!content) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const type = node.getAttribute('content-type');
|
|
294
|
+
if (type === 'dept') {
|
|
295
|
+
department = content;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
institution = content;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return { department, institution };
|
|
302
|
+
};
|
|
303
|
+
const getAddressLine = (element, index) => {
|
|
304
|
+
return (getTrimmedTextContent(element, `addr-line:nth-of-type(${index})`) ||
|
|
305
|
+
'');
|
|
306
|
+
};
|
|
307
|
+
const { department, institution } = getInstitutionDetails(element);
|
|
308
|
+
return {
|
|
309
|
+
id: element.getAttribute('id'),
|
|
310
|
+
institution: institution !== null && institution !== void 0 ? institution : '',
|
|
311
|
+
department: department !== null && department !== void 0 ? department : '',
|
|
312
|
+
addressLine1: getAddressLine(element, 1),
|
|
313
|
+
addressLine2: getAddressLine(element, 2),
|
|
314
|
+
addressLine3: getAddressLine(element, 3),
|
|
315
|
+
postCode: (_a = getTrimmedTextContent(element, 'postal-code')) !== null && _a !== void 0 ? _a : '',
|
|
316
|
+
country: (_b = getTrimmedTextContent(element, 'country')) !== null && _b !== void 0 ? _b : '',
|
|
317
|
+
email: getEmail(element),
|
|
318
|
+
priority: parsePriority(element.getAttribute('priority')),
|
|
319
|
+
};
|
|
320
|
+
},
|
|
321
|
+
getContent: () => {
|
|
322
|
+
return Fragment.from(schema.text('_'));
|
|
323
|
+
},
|
|
324
|
+
},
|
|
98
325
|
{
|
|
99
326
|
tag: 'attrib',
|
|
100
327
|
node: 'attribution',
|
|
@@ -103,10 +330,6 @@ const nodes = [
|
|
|
103
330
|
tag: 'back',
|
|
104
331
|
ignore: true,
|
|
105
332
|
},
|
|
106
|
-
{
|
|
107
|
-
tag: 'body',
|
|
108
|
-
node: 'manuscript',
|
|
109
|
-
},
|
|
110
333
|
{
|
|
111
334
|
tag: 'break',
|
|
112
335
|
node: 'hard_break',
|
|
@@ -126,13 +349,13 @@ const nodes = [
|
|
|
126
349
|
const title = element.querySelector('title');
|
|
127
350
|
if (title) {
|
|
128
351
|
const captionTitle = schema.nodes.caption_title.create();
|
|
129
|
-
content.push(
|
|
352
|
+
content.push(jatsDOMParser.parse(title, { topNode: captionTitle }));
|
|
130
353
|
}
|
|
131
354
|
const paragraphs = element.querySelectorAll('p');
|
|
132
355
|
if (paragraphs.length) {
|
|
133
356
|
const figcaption = schema.nodes.caption.create();
|
|
134
357
|
for (const paragraph of paragraphs) {
|
|
135
|
-
content.push(
|
|
358
|
+
content.push(jatsDOMParser.parse(paragraph, { topNode: figcaption }));
|
|
136
359
|
}
|
|
137
360
|
}
|
|
138
361
|
return Fragment.from(content);
|
|
@@ -323,7 +546,7 @@ const nodes = [
|
|
|
323
546
|
const paragraphs = [];
|
|
324
547
|
node.childNodes.forEach((p) => {
|
|
325
548
|
const paragraph = schema.nodes.paragraph.create();
|
|
326
|
-
const content =
|
|
549
|
+
const content = jatsDOMParser.parse(p, {
|
|
327
550
|
topNode: paragraph,
|
|
328
551
|
});
|
|
329
552
|
paragraphs.push(content);
|
|
@@ -422,6 +645,54 @@ const nodes = [
|
|
|
422
645
|
tag: 'sec[sec-type="backmatter"]',
|
|
423
646
|
node: 'backmatter',
|
|
424
647
|
},
|
|
648
|
+
{
|
|
649
|
+
tag: 'bibliography-element',
|
|
650
|
+
node: 'bibliography_element',
|
|
651
|
+
getAttrs: (node) => {
|
|
652
|
+
const element = node;
|
|
653
|
+
return {
|
|
654
|
+
id: element.getAttribute('id'),
|
|
655
|
+
};
|
|
656
|
+
},
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
tag: 'bibliography-item',
|
|
660
|
+
node: 'bibliography_item',
|
|
661
|
+
getAttrs: (node) => {
|
|
662
|
+
const element = node;
|
|
663
|
+
const authors = [];
|
|
664
|
+
element.querySelectorAll('author').forEach((author) => {
|
|
665
|
+
authors.push({
|
|
666
|
+
_id: author.getAttribute('id') || '',
|
|
667
|
+
given: author.getAttribute('given') || '',
|
|
668
|
+
family: author.getAttribute('family') || '',
|
|
669
|
+
objectType: 'MPBibliographicName',
|
|
670
|
+
});
|
|
671
|
+
});
|
|
672
|
+
const issuedEl = element.querySelector('issued');
|
|
673
|
+
const issued = issuedEl
|
|
674
|
+
? {
|
|
675
|
+
objectType: 'MPBibliographicDate',
|
|
676
|
+
_id: issuedEl.getAttribute('id'),
|
|
677
|
+
'date-parts': [[issuedEl.getAttribute('year')]],
|
|
678
|
+
}
|
|
679
|
+
: undefined;
|
|
680
|
+
return {
|
|
681
|
+
id: element.getAttribute('id'),
|
|
682
|
+
type: element.getAttribute('type'),
|
|
683
|
+
containerTitle: element.getAttribute('container-title'),
|
|
684
|
+
volume: element.getAttribute('volume'),
|
|
685
|
+
issue: element.getAttribute('issue'),
|
|
686
|
+
supplement: element.getAttribute('supplement'),
|
|
687
|
+
page: element.getAttribute('page'),
|
|
688
|
+
title: element.getAttribute('title'),
|
|
689
|
+
literal: element.getAttribute('literal'),
|
|
690
|
+
author: authors,
|
|
691
|
+
issued,
|
|
692
|
+
DOI: element.getAttribute('DOI'),
|
|
693
|
+
};
|
|
694
|
+
},
|
|
695
|
+
},
|
|
425
696
|
{
|
|
426
697
|
tag: 'sec',
|
|
427
698
|
node: 'section',
|
|
@@ -492,7 +763,7 @@ const nodes = [
|
|
|
492
763
|
{
|
|
493
764
|
tag: 'title',
|
|
494
765
|
node: 'section_title',
|
|
495
|
-
context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/',
|
|
766
|
+
context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/|author_notes/',
|
|
496
767
|
},
|
|
497
768
|
{
|
|
498
769
|
tag: 'title',
|
|
@@ -574,4 +845,4 @@ const nodes = [
|
|
|
574
845
|
},
|
|
575
846
|
},
|
|
576
847
|
];
|
|
577
|
-
export const
|
|
848
|
+
export const jatsDOMParser = new DOMParser(schema, [...marks, ...nodes]);
|