@manuscripts/transform 2.3.38-LEAN-3911.0 → 2.4.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/__tests__/data/project-dump.json +825 -0
- package/dist/cjs/index.js +6 -6
- package/dist/cjs/jats/importer/index.js +22 -0
- package/dist/cjs/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +34 -273
- package/dist/cjs/jats/importer/jats-body-transformations.js +22 -74
- package/dist/cjs/jats/importer/jats-comments.js +104 -27
- package/dist/cjs/jats/importer/jats-front-parser.js +321 -0
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +1 -8
- package/dist/cjs/jats/importer/jats-parser-utils.js +5 -43
- package/dist/cjs/jats/importer/jats-reference-parser.js +23 -16
- package/dist/cjs/jats/importer/jats-references.js +18 -18
- package/dist/cjs/jats/importer/parse-jats-article.js +79 -40
- package/dist/cjs/jats/index.js +7 -7
- package/dist/cjs/jats/{exporter/jats-exporter.js → jats-exporter.js} +398 -264
- package/dist/cjs/jats/{exporter/jats-versions.js → jats-versions.js} +3 -1
- package/dist/cjs/lib/utils.js +1 -12
- package/dist/cjs/transformer/__tests__/__helpers__/doc.js +37 -0
- package/dist/cjs/transformer/builders.js +219 -0
- package/dist/cjs/transformer/decode.js +898 -0
- package/dist/cjs/transformer/document-object-types.js +31 -0
- package/dist/cjs/transformer/encode.js +674 -0
- package/dist/cjs/{jats/importer/create-article-node.js → transformer/filename.js} +9 -10
- package/dist/cjs/transformer/footnote-category.js +20 -0
- package/dist/cjs/transformer/footnotes-order.js +60 -0
- package/dist/cjs/transformer/highlight-markers.js +138 -0
- package/dist/cjs/transformer/html.js +400 -0
- package/dist/cjs/transformer/id.js +5 -10
- package/dist/cjs/transformer/index.js +18 -0
- package/dist/cjs/{jats/exporter → transformer}/labels.js +5 -4
- package/dist/cjs/transformer/manuscript-dependencies.js +21 -0
- package/dist/cjs/transformer/model-map.js +26 -0
- package/dist/cjs/{lib/deafults.js → transformer/models.js} +1 -3
- package/dist/cjs/transformer/node-names.js +1 -0
- package/dist/cjs/transformer/object-types.js +57 -0
- package/dist/cjs/transformer/project-bundle.js +94 -0
- package/dist/cjs/transformer/serializer.js +23 -0
- package/dist/cjs/transformer/timestamp.js +20 -0
- package/dist/cjs/transformer/update-identifiers.js +93 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/__tests__/data/project-dump.json +825 -0
- package/dist/es/index.js +5 -5
- package/dist/{types/jats/importer/create-article-node.d.ts → es/jats/importer/index.js} +2 -3
- package/dist/es/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +35 -274
- package/dist/es/jats/importer/jats-body-transformations.js +22 -74
- package/dist/es/jats/importer/jats-comments.js +101 -26
- package/dist/es/jats/importer/jats-front-parser.js +315 -0
- package/dist/es/jats/importer/jats-journal-meta-parser.js +0 -6
- package/dist/es/jats/importer/jats-parser-utils.js +6 -44
- package/dist/es/jats/importer/jats-reference-parser.js +23 -16
- package/dist/es/jats/importer/jats-references.js +18 -18
- package/dist/es/jats/importer/parse-jats-article.js +78 -41
- package/dist/es/jats/index.js +3 -5
- package/dist/es/jats/{exporter/jats-exporter.js → jats-exporter.js} +392 -258
- package/dist/es/jats/{exporter/jats-versions.js → jats-versions.js} +1 -0
- package/dist/es/lib/utils.js +0 -9
- package/dist/es/transformer/__tests__/__helpers__/doc.js +29 -0
- package/dist/es/transformer/builders.js +186 -0
- package/dist/es/transformer/decode.js +888 -0
- package/dist/es/transformer/document-object-types.js +28 -0
- package/dist/es/transformer/encode.js +664 -0
- package/dist/es/transformer/filename.js +23 -0
- package/dist/es/transformer/footnote-category.js +16 -0
- package/dist/es/transformer/footnotes-order.js +55 -0
- package/dist/es/transformer/highlight-markers.js +132 -0
- package/dist/es/transformer/html.js +393 -0
- package/dist/es/transformer/id.js +3 -8
- package/dist/es/transformer/index.js +16 -0
- package/dist/es/{jats/exporter → transformer}/labels.js +5 -4
- package/dist/es/transformer/manuscript-dependencies.js +17 -0
- package/dist/es/transformer/model-map.js +22 -0
- package/dist/es/{lib/deafults.js → transformer/models.js} +2 -2
- package/dist/es/transformer/node-names.js +1 -0
- package/dist/es/transformer/object-types.js +52 -0
- package/dist/es/transformer/project-bundle.js +85 -0
- package/dist/es/transformer/serializer.js +17 -0
- package/dist/es/transformer/timestamp.js +16 -0
- package/dist/es/transformer/update-identifiers.js +87 -0
- package/dist/es/version.js +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types/jats/importer/index.d.ts +16 -0
- package/dist/types/jats/importer/{jats-dom-parser.d.ts → jats-body-dom-parser.d.ts} +1 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -5
- package/dist/types/jats/importer/jats-comments.d.ts +10 -4
- package/dist/types/jats/importer/jats-front-parser.d.ts +84 -0
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +0 -10
- package/dist/types/jats/importer/jats-references.d.ts +8 -19
- package/dist/types/jats/importer/parse-jats-article.d.ts +5 -12
- package/dist/types/jats/index.d.ts +3 -5
- package/dist/types/jats/{exporter/jats-exporter.d.ts → jats-exporter.d.ts} +29 -15
- package/dist/types/jats/{exporter/jats-versions.d.ts → jats-versions.d.ts} +1 -0
- package/dist/types/lib/utils.d.ts +0 -2
- package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
- package/dist/types/schema/nodes/contributor.d.ts +0 -10
- package/dist/types/schema/nodes/keyword_group.d.ts +0 -1
- package/dist/types/schema/nodes/manuscript.d.ts +7 -8
- package/dist/types/schema/nodes/title.d.ts +3 -0
- package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +18 -0
- package/dist/types/transformer/builders.d.ts +61 -0
- package/dist/types/transformer/decode.d.ts +52 -0
- package/dist/types/transformer/document-object-types.d.ts +17 -0
- package/dist/types/transformer/encode.d.ts +29 -0
- package/dist/types/transformer/filename.d.ts +16 -0
- package/dist/types/transformer/footnote-category.d.ts +17 -0
- package/dist/{es/jats/importer/create-article-node.js → types/transformer/footnotes-order.d.ts} +8 -10
- package/dist/types/transformer/highlight-markers.d.ts +31 -0
- package/dist/types/transformer/html.d.ts +36 -0
- package/dist/types/transformer/id.d.ts +2 -5
- package/dist/types/transformer/index.d.ts +16 -0
- package/dist/types/{jats/exporter → transformer}/labels.d.ts +2 -2
- package/dist/types/transformer/manuscript-dependencies.d.ts +4 -0
- package/dist/types/transformer/model-map.d.ts +19 -0
- package/dist/types/transformer/models.d.ts +48 -0
- package/dist/types/transformer/object-types.d.ts +30 -0
- package/dist/types/transformer/project-bundle.d.ts +30 -0
- package/dist/types/transformer/serializer.d.ts +19 -0
- package/dist/types/{lib/deafults.d.ts → transformer/timestamp.d.ts} +2 -2
- package/dist/types/transformer/update-identifiers.d.ts +23 -0
- package/dist/types/types.d.ts +2 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -2
- package/dist/cjs/jats/importer/jats-front-transformations.js +0 -79
- package/dist/es/jats/importer/jats-front-transformations.js +0 -76
- package/dist/types/jats/importer/jats-front-transformations.d.ts +0 -22
- package/dist/types/jats/types.d.ts +0 -1
- /package/dist/cjs/{jats/types.js → types.js} +0 -0
- /package/dist/es/{jats/types.js → types.js} +0 -0
|
@@ -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
|
-
|
|
16
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
+
import { buildComment, buildContribution, highlightableFields, isHighlightableModel, isKeyword, } from '../../transformer';
|
|
18
|
+
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,33 +23,34 @@ 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);
|
|
26
27
|
const queryText = /queryText="(.+)"/.exec(text);
|
|
27
|
-
if (queryText) {
|
|
28
|
-
const parentNode = node.parentNode;
|
|
29
|
-
const index = parentNode.outerHTML.indexOf(queryText[1]);
|
|
28
|
+
if (id && queryText) {
|
|
30
29
|
return {
|
|
31
|
-
id:
|
|
30
|
+
id: id[1],
|
|
32
31
|
text: queryText[1],
|
|
33
|
-
index,
|
|
34
32
|
};
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
};
|
|
38
36
|
export const markComments = (doc) => {
|
|
39
|
-
|
|
37
|
+
const marks = [];
|
|
40
38
|
const root = doc.getRootNode();
|
|
41
39
|
const queue = [root];
|
|
42
|
-
const commentsElement = doc.createElement('comments-annotations');
|
|
43
40
|
while (queue.length !== 0) {
|
|
44
41
|
const node = queue.shift();
|
|
45
42
|
if (node) {
|
|
46
43
|
if (isJATSComment(node)) {
|
|
47
44
|
const comment = parseJATSComment(node);
|
|
48
45
|
if (comment) {
|
|
49
|
-
const
|
|
50
|
-
(
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
const token = addMark(doc, node);
|
|
47
|
+
if (token) {
|
|
48
|
+
const mark = {
|
|
49
|
+
token,
|
|
50
|
+
comment,
|
|
51
|
+
};
|
|
52
|
+
marks.push(mark);
|
|
53
|
+
}
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
node.childNodes.forEach((child) => {
|
|
@@ -57,19 +58,93 @@ export const markComments = (doc) => {
|
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
return marks;
|
|
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
|
+
}
|
|
62
81
|
}
|
|
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));
|
|
63
88
|
};
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
const processModel = (model, marks) => {
|
|
90
|
+
const comments = [];
|
|
91
|
+
for (const field of highlightableFields) {
|
|
92
|
+
const content = model[field];
|
|
93
|
+
if (!content) {
|
|
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;
|
|
69
101
|
};
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
const processKeyword = (model, marks) => {
|
|
103
|
+
const comments = [];
|
|
104
|
+
const name = model.name;
|
|
105
|
+
let content = name;
|
|
106
|
+
for (const mark of getFieldMarks(name, marks)) {
|
|
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;
|
|
75
150
|
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2020 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import debug from 'debug';
|
|
17
|
+
import { getTrimmedTextContent } from '../../lib/utils';
|
|
18
|
+
import { buildAffiliation, buildAuthorNotes, buildBibliographicName, buildContributor, buildCorresp, buildFootnote, buildJournal, buildParagraph, buildTitles, } from '../../transformer';
|
|
19
|
+
import { parseJournalMeta } from './jats-journal-meta-parser';
|
|
20
|
+
import { htmlFromJatsNode } from './jats-parser-utils';
|
|
21
|
+
const warn = debug('manuscripts-transform');
|
|
22
|
+
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
23
|
+
const defaultTitle = 'Untitled Manuscript';
|
|
24
|
+
export const jatsFrontParser = {
|
|
25
|
+
parseTitles(element, createElement) {
|
|
26
|
+
var _a;
|
|
27
|
+
if (!element) {
|
|
28
|
+
return buildTitles(defaultTitle);
|
|
29
|
+
}
|
|
30
|
+
const title = element.querySelector('article-title');
|
|
31
|
+
const subtitle = element.querySelector('subtitle');
|
|
32
|
+
const runningTitle = element.querySelector('alt-title[alt-title-type="right-running"]');
|
|
33
|
+
const titles = buildTitles((_a = htmlFromJatsNode(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle);
|
|
34
|
+
if (subtitle) {
|
|
35
|
+
titles.subtitle = htmlFromJatsNode(subtitle, createElement);
|
|
36
|
+
}
|
|
37
|
+
if (runningTitle) {
|
|
38
|
+
titles.runningTitle = htmlFromJatsNode(runningTitle, createElement);
|
|
39
|
+
}
|
|
40
|
+
return titles;
|
|
41
|
+
},
|
|
42
|
+
parseDOI(front) {
|
|
43
|
+
var _a;
|
|
44
|
+
const doi = front === null || front === void 0 ? void 0 : front.querySelector('article-meta > article-id[pub-id-type="doi"]');
|
|
45
|
+
return (_a = doi === null || doi === void 0 ? void 0 : doi.textContent) !== null && _a !== void 0 ? _a : undefined;
|
|
46
|
+
},
|
|
47
|
+
parseCounts(counts) {
|
|
48
|
+
var _a, _b, _c, _d, _e;
|
|
49
|
+
if (counts) {
|
|
50
|
+
const parseCount = (count) => {
|
|
51
|
+
if (count && /^-?\d+$/.test(count)) {
|
|
52
|
+
return parseInt(count);
|
|
53
|
+
}
|
|
54
|
+
else if (count) {
|
|
55
|
+
warn(`Invalid count number for ${count}`);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const genericCounts = [];
|
|
59
|
+
const countElements = counts.querySelectorAll('count');
|
|
60
|
+
for (const element of countElements.values()) {
|
|
61
|
+
const countType = element.getAttribute('count-type');
|
|
62
|
+
const count = parseCount(element.getAttribute('count'));
|
|
63
|
+
if (countType) {
|
|
64
|
+
const genericCount = { count, countType };
|
|
65
|
+
genericCounts.push(genericCount);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
wordCount: parseCount((_a = counts.querySelector('word-count')) === null || _a === void 0 ? void 0 : _a.getAttribute('count')),
|
|
70
|
+
figureCount: parseCount((_b = counts.querySelector('fig-count')) === null || _b === void 0 ? void 0 : _b.getAttribute('count')),
|
|
71
|
+
tableCount: parseCount((_c = counts.querySelector('table-count')) === null || _c === void 0 ? void 0 : _c.getAttribute('count')),
|
|
72
|
+
equationCount: parseCount((_d = counts.querySelector('equation-count')) === null || _d === void 0 ? void 0 : _d.getAttribute('count')),
|
|
73
|
+
referencesCount: parseCount((_e = counts.querySelector('ref-count')) === null || _e === void 0 ? void 0 : _e.getAttribute('count')),
|
|
74
|
+
genericCounts: genericCounts.length > 0 ? genericCounts : undefined,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
parseJournal(element) {
|
|
79
|
+
const meta = parseJournalMeta(element);
|
|
80
|
+
return Object.assign(Object.assign({}, meta), buildJournal());
|
|
81
|
+
},
|
|
82
|
+
parseDates(historyNode) {
|
|
83
|
+
if (!historyNode) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const history = {};
|
|
87
|
+
const dateToTimestamp = (dateElement) => {
|
|
88
|
+
const selectors = ['year', 'month', 'day'];
|
|
89
|
+
const values = [];
|
|
90
|
+
for (const selector of selectors) {
|
|
91
|
+
const value = getTrimmedTextContent(dateElement, selector);
|
|
92
|
+
if (!value || isNaN(+value)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
values.push(+value);
|
|
96
|
+
}
|
|
97
|
+
return Date.UTC(values[0], values[1], values[2]) / 1000;
|
|
98
|
+
};
|
|
99
|
+
for (const date of historyNode.children) {
|
|
100
|
+
const dateType = date.getAttribute('date-type');
|
|
101
|
+
switch (dateType) {
|
|
102
|
+
case 'received': {
|
|
103
|
+
history.receiveDate = dateToTimestamp(date);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'rev-recd': {
|
|
107
|
+
history.revisionReceiveDate = dateToTimestamp(date);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case 'accepted': {
|
|
111
|
+
history.acceptanceDate = dateToTimestamp(date);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case 'rev-request': {
|
|
115
|
+
history.revisionRequestDate = dateToTimestamp(date);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'retracted': {
|
|
119
|
+
history.retractionDate = dateToTimestamp(date);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case 'corrected': {
|
|
123
|
+
history.correctionDate = dateToTimestamp(date);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return history;
|
|
129
|
+
},
|
|
130
|
+
parseAffiliations(elements) {
|
|
131
|
+
const affiliationIDs = new Map();
|
|
132
|
+
const affiliations = elements.map((element, priority) => {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
const affiliation = buildAffiliation('', priority);
|
|
135
|
+
for (const node of element.querySelectorAll('institution')) {
|
|
136
|
+
const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
137
|
+
if (!content) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const type = node.getAttribute('content-type');
|
|
141
|
+
if (type === 'dept') {
|
|
142
|
+
affiliation.department = content;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
affiliation.institution = content;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
affiliation.addressLine1 =
|
|
149
|
+
getTrimmedTextContent(element, 'addr-line:nth-of-type(1)') || undefined;
|
|
150
|
+
affiliation.addressLine2 =
|
|
151
|
+
getTrimmedTextContent(element, 'addr-line:nth-of-type(2)') || undefined;
|
|
152
|
+
affiliation.addressLine3 =
|
|
153
|
+
getTrimmedTextContent(element, 'addr-line:nth-of-type(3)') || undefined;
|
|
154
|
+
affiliation.postCode =
|
|
155
|
+
getTrimmedTextContent(element, 'postal-code') || undefined;
|
|
156
|
+
affiliation.country =
|
|
157
|
+
getTrimmedTextContent(element, 'country') || undefined;
|
|
158
|
+
const email = element.querySelector('email');
|
|
159
|
+
if (email) {
|
|
160
|
+
affiliation.email = {
|
|
161
|
+
href: email.getAttributeNS(XLINK_NAMESPACE, 'href') || undefined,
|
|
162
|
+
text: ((_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const id = element.getAttribute('id');
|
|
166
|
+
if (id) {
|
|
167
|
+
affiliationIDs.set(id, affiliation._id);
|
|
168
|
+
}
|
|
169
|
+
return affiliation;
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
affiliations,
|
|
173
|
+
affiliationIDs,
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
parseAuthorNotes(element) {
|
|
177
|
+
if (!element) {
|
|
178
|
+
return {
|
|
179
|
+
footnotes: [],
|
|
180
|
+
footnoteIDs: new Map(),
|
|
181
|
+
authorNotes: [],
|
|
182
|
+
authorNotesParagraphs: [],
|
|
183
|
+
correspondingIDs: new Map(),
|
|
184
|
+
correspondingList: [],
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const { footnotes, footnoteIDs } = this.parseFootnotes([
|
|
188
|
+
...element.querySelectorAll('fn:not([fn-type])'),
|
|
189
|
+
]);
|
|
190
|
+
const authorNotesParagraphs = this.parseParagraphs([
|
|
191
|
+
...element.querySelectorAll(':scope > p'),
|
|
192
|
+
]);
|
|
193
|
+
const { correspondingList, correspondingIDs } = this.parseCorresp([
|
|
194
|
+
...element.querySelectorAll('corresp'),
|
|
195
|
+
]);
|
|
196
|
+
const authorNotes = [
|
|
197
|
+
buildAuthorNotes([
|
|
198
|
+
...correspondingIDs.values(),
|
|
199
|
+
...footnoteIDs.values(),
|
|
200
|
+
...authorNotesParagraphs.map((p) => p._id),
|
|
201
|
+
]),
|
|
202
|
+
];
|
|
203
|
+
return {
|
|
204
|
+
footnotes,
|
|
205
|
+
footnoteIDs,
|
|
206
|
+
authorNotesParagraphs,
|
|
207
|
+
authorNotes,
|
|
208
|
+
correspondingIDs,
|
|
209
|
+
correspondingList,
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
parseParagraphs(elements) {
|
|
213
|
+
return elements.map((p) => buildParagraph(p.innerHTML));
|
|
214
|
+
},
|
|
215
|
+
parseFootnotes(elements) {
|
|
216
|
+
const footnoteIDs = new Map();
|
|
217
|
+
const footnotes = elements.map((element) => {
|
|
218
|
+
const fn = buildFootnote('', element.innerHTML);
|
|
219
|
+
const id = element.getAttribute('id');
|
|
220
|
+
if (id) {
|
|
221
|
+
footnoteIDs.set(id, fn._id);
|
|
222
|
+
}
|
|
223
|
+
return fn;
|
|
224
|
+
});
|
|
225
|
+
return {
|
|
226
|
+
footnotes,
|
|
227
|
+
footnoteIDs,
|
|
228
|
+
};
|
|
229
|
+
},
|
|
230
|
+
parseCorresp(elements) {
|
|
231
|
+
const correspondingIDs = new Map();
|
|
232
|
+
const correspondingList = elements.map((element) => {
|
|
233
|
+
var _a, _b, _c;
|
|
234
|
+
const label = element.querySelector('label');
|
|
235
|
+
if (label) {
|
|
236
|
+
label.remove();
|
|
237
|
+
}
|
|
238
|
+
const corresponding = buildCorresp((_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
|
|
239
|
+
corresponding.label = ((_c = label === null || label === void 0 ? void 0 : label.textContent) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
|
|
240
|
+
const id = element.getAttribute('id');
|
|
241
|
+
if (id) {
|
|
242
|
+
correspondingIDs.set(id, corresponding._id);
|
|
243
|
+
}
|
|
244
|
+
return corresponding;
|
|
245
|
+
});
|
|
246
|
+
return {
|
|
247
|
+
correspondingList,
|
|
248
|
+
correspondingIDs,
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
parseContributors(elements, affiliationIDs, footnoteIDs, correspondingIDs) {
|
|
252
|
+
return elements.map((element, priority) => {
|
|
253
|
+
var _a, _b;
|
|
254
|
+
const name = buildBibliographicName({});
|
|
255
|
+
const given = getTrimmedTextContent(element, 'name > given-names');
|
|
256
|
+
if (given) {
|
|
257
|
+
name.given = given;
|
|
258
|
+
}
|
|
259
|
+
const surname = getTrimmedTextContent(element, 'name > surname');
|
|
260
|
+
if (surname) {
|
|
261
|
+
name.family = surname;
|
|
262
|
+
}
|
|
263
|
+
const contributor = buildContributor(name, 'author', priority);
|
|
264
|
+
const corresponding = element.getAttribute('corresp') === 'yes';
|
|
265
|
+
if (corresponding) {
|
|
266
|
+
contributor.isCorresponding = corresponding;
|
|
267
|
+
}
|
|
268
|
+
const orcid = getTrimmedTextContent(element, 'contrib-id[contrib-id-type="orcid"]');
|
|
269
|
+
if (orcid) {
|
|
270
|
+
contributor.ORCIDIdentifier = orcid;
|
|
271
|
+
}
|
|
272
|
+
const xrefs = element.querySelectorAll('xref');
|
|
273
|
+
for (const xref of xrefs) {
|
|
274
|
+
if (xref) {
|
|
275
|
+
const rid = xref.getAttribute('rid');
|
|
276
|
+
const type = xref.getAttribute('ref-type');
|
|
277
|
+
if (rid) {
|
|
278
|
+
if (type === 'fn') {
|
|
279
|
+
contributor.footnote = [];
|
|
280
|
+
const footnoteID = footnoteIDs.get(rid);
|
|
281
|
+
if (footnoteID) {
|
|
282
|
+
const authorFootNoteRef = {
|
|
283
|
+
noteID: footnoteID,
|
|
284
|
+
noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
|
|
285
|
+
};
|
|
286
|
+
contributor.footnote.push(authorFootNoteRef);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else if (type === 'corresp') {
|
|
290
|
+
contributor.corresp = [];
|
|
291
|
+
const correspID = correspondingIDs.get(rid);
|
|
292
|
+
if (correspID) {
|
|
293
|
+
const authorCorrespRef = {
|
|
294
|
+
correspID: correspID,
|
|
295
|
+
correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
|
|
296
|
+
};
|
|
297
|
+
contributor.corresp.push(authorCorrespRef);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
else if (type === 'aff') {
|
|
301
|
+
const rids = rid
|
|
302
|
+
.split(/\s+/)
|
|
303
|
+
.map((id) => affiliationIDs.get(id))
|
|
304
|
+
.filter(Boolean);
|
|
305
|
+
if (rids.length) {
|
|
306
|
+
contributor.affiliations = rids;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return contributor;
|
|
313
|
+
});
|
|
314
|
+
},
|
|
315
|
+
};
|
|
@@ -13,9 +13,7 @@
|
|
|
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
16
|
import { getTrimmedTextContent } from '../../lib/utils';
|
|
18
|
-
import { generateID } from '../../transformer';
|
|
19
17
|
export const parseJournalIdentifiers = (element) => {
|
|
20
18
|
var _a;
|
|
21
19
|
if (!element) {
|
|
@@ -86,7 +84,3 @@ export const parseJournalMeta = (element) => {
|
|
|
86
84
|
title: (_b = getTrimmedTextContent(element, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
|
|
87
85
|
};
|
|
88
86
|
};
|
|
89
|
-
export const parseJournal = (element) => {
|
|
90
|
-
const meta = parseJournalMeta(element);
|
|
91
|
-
return Object.assign(Object.assign({}, meta), { _id: generateID(ObjectTypes.Journal), objectType: ObjectTypes.Journal });
|
|
92
|
-
};
|
|
@@ -14,38 +14,24 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
-
import { schema
|
|
17
|
+
import { schema } from '../../schema';
|
|
18
18
|
import { generateID, nodeTypesMap } from '../../transformer';
|
|
19
19
|
export const updateDocumentIDs = (node, replacements) => {
|
|
20
20
|
const warnings = [];
|
|
21
|
-
|
|
22
|
-
recurseDoc(node, (n, parent) => updateNodeID(n, parent, replacements, warnings, highlightNodes));
|
|
21
|
+
recurseDoc(node, (n) => updateNodeID(n, replacements, warnings));
|
|
23
22
|
recurseDoc(node, (n) => updateNodeRID(n, replacements, warnings));
|
|
24
23
|
recurseDoc(node, (n) => updateNodeRIDS(n, replacements, warnings));
|
|
25
|
-
recurseDoc(node, (n) => updateContributorNodesIDS(n, replacements, warnings));
|
|
26
24
|
return warnings;
|
|
27
25
|
};
|
|
28
|
-
function recurseDoc(node, fn
|
|
29
|
-
fn(node
|
|
30
|
-
node.descendants((n
|
|
26
|
+
function recurseDoc(node, fn) {
|
|
27
|
+
fn(node);
|
|
28
|
+
node.descendants((n) => fn(n));
|
|
31
29
|
}
|
|
32
|
-
const updateNodeID = (node,
|
|
30
|
+
const updateNodeID = (node, replacements, warnings) => {
|
|
33
31
|
if (node.type === schema.nodes.inline_equation) {
|
|
34
32
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${uuidv4()}` });
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
37
|
-
if (node.type === schema.nodes.highlight_marker) {
|
|
38
|
-
node.attrs = Object.assign(Object.assign({}, node.attrs), { tid: parent === null || parent === void 0 ? void 0 : parent.attrs.id });
|
|
39
|
-
highlightNodes.push(node);
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (node.type === schema.nodes.comment) {
|
|
43
|
-
const highlightNode = highlightNodes.find((n) => n.attrs.id === node.attrs.id);
|
|
44
|
-
if (highlightNode) {
|
|
45
|
-
node.attrs = Object.assign(Object.assign({}, node.attrs), { target: highlightNode.attrs.tid });
|
|
46
|
-
}
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
35
|
if (node.type === schema.nodes.general_table_footnote) {
|
|
50
36
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `GeneralTableFootnote:${uuidv4()}` });
|
|
51
37
|
return;
|
|
@@ -88,30 +74,6 @@ const updateNodeRIDS = (node, replacements, warnings) => {
|
|
|
88
74
|
}
|
|
89
75
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { rids: previousRIDs.map((r) => replacements.get(r) || r) });
|
|
90
76
|
};
|
|
91
|
-
const updateContributorNodesIDS = (node, replacements, warnings) => {
|
|
92
|
-
var _a, _b;
|
|
93
|
-
if (node.type === schema.nodes.contributor) {
|
|
94
|
-
const footnote = (_a = node.attrs.footnote) === null || _a === void 0 ? void 0 : _a.map((fn) => {
|
|
95
|
-
return replacements.get(fn.noteID)
|
|
96
|
-
? Object.assign(Object.assign({}, fn), { noteID: replacements.get(fn.noteID) }) : undefined;
|
|
97
|
-
}).filter(Boolean);
|
|
98
|
-
const corresp = (_b = node.attrs.corresp) === null || _b === void 0 ? void 0 : _b.map((corresp) => {
|
|
99
|
-
return replacements.get(corresp.correspID)
|
|
100
|
-
? Object.assign(Object.assign({}, corresp), { correspID: replacements.get(corresp.correspID) }) : undefined;
|
|
101
|
-
}).filter(Boolean);
|
|
102
|
-
const affiliations = node.attrs.affiliations
|
|
103
|
-
.map((affiliation) => {
|
|
104
|
-
return replacements.get(affiliation);
|
|
105
|
-
})
|
|
106
|
-
.filter(Boolean);
|
|
107
|
-
node.attrs = Object.assign(Object.assign({}, node.attrs), { footnote,
|
|
108
|
-
corresp,
|
|
109
|
-
affiliations });
|
|
110
|
-
}
|
|
111
|
-
if (node.type !== schema.nodes.contributors) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
77
|
const JATS_TO_HTML_MAPPING = new Map([
|
|
116
78
|
['bold', 'b'],
|
|
117
79
|
['italic', 'i'],
|
|
@@ -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 { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
16
|
import { getTrimmedTextContent } from '../../lib/utils';
|
|
18
|
-
import {
|
|
17
|
+
import { buildBibliographicDate, buildBibliographicName, buildBibliographyItem, } from '../../transformer/builders';
|
|
18
|
+
import { isJATSComment, parseJATSComment } from './jats-comments';
|
|
19
19
|
import { htmlFromJatsNode } from './jats-parser-utils';
|
|
20
20
|
import { References } from './jats-references';
|
|
21
21
|
const chooseBibliographyItemType = (publicationType) => {
|
|
@@ -37,15 +37,23 @@ export const jatsReferenceParser = {
|
|
|
37
37
|
const authorNodes = [
|
|
38
38
|
...element.querySelectorAll('person-group[person-group-type="author"] > *'),
|
|
39
39
|
];
|
|
40
|
-
const bibliographyItem = {
|
|
41
|
-
id: generateID(ObjectTypes.BibliographyItem),
|
|
40
|
+
const bibliographyItem = buildBibliographyItem({
|
|
42
41
|
type: chooseBibliographyItemType(publicationType),
|
|
43
|
-
};
|
|
42
|
+
});
|
|
44
43
|
const titleNode = element.querySelector('article-title');
|
|
45
44
|
if (titleNode) {
|
|
46
45
|
bibliographyItem.title = (_a = htmlFromJatsNode(titleNode, createElement)) === null || _a === void 0 ? void 0 : _a.trim();
|
|
47
46
|
}
|
|
47
|
+
const comments = [];
|
|
48
48
|
const mixedCitation = element.querySelector('mixed-citation');
|
|
49
|
+
mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
|
|
50
|
+
if (isJATSComment(item)) {
|
|
51
|
+
const comment = parseJATSComment(item);
|
|
52
|
+
if (comment) {
|
|
53
|
+
comments.push(comment);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
49
57
|
if (authorNodes.length <= 0) {
|
|
50
58
|
mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
|
|
51
59
|
var _a, _b, _c;
|
|
@@ -58,7 +66,7 @@ export const jatsReferenceParser = {
|
|
|
58
66
|
}
|
|
59
67
|
const source = getTrimmedTextContent(element, 'source');
|
|
60
68
|
if (source) {
|
|
61
|
-
bibliographyItem
|
|
69
|
+
bibliographyItem['container-title'] = source;
|
|
62
70
|
}
|
|
63
71
|
const volume = getTrimmedTextContent(element, 'volume');
|
|
64
72
|
if (volume) {
|
|
@@ -79,23 +87,18 @@ export const jatsReferenceParser = {
|
|
|
79
87
|
}
|
|
80
88
|
const year = getTrimmedTextContent(element, 'year');
|
|
81
89
|
if (year) {
|
|
82
|
-
bibliographyItem.issued = {
|
|
90
|
+
bibliographyItem.issued = buildBibliographicDate({
|
|
83
91
|
'date-parts': [[year]],
|
|
84
|
-
|
|
85
|
-
objectType: ObjectTypes.BibliographicDate,
|
|
86
|
-
};
|
|
92
|
+
});
|
|
87
93
|
}
|
|
88
94
|
const doi = getTrimmedTextContent(element, 'pub-id[pub-id-type="doi"]');
|
|
89
95
|
if (doi) {
|
|
90
|
-
bibliographyItem.
|
|
96
|
+
bibliographyItem.DOI = doi;
|
|
91
97
|
}
|
|
92
98
|
const authors = [];
|
|
93
99
|
authorNodes.forEach((authorNode) => {
|
|
94
100
|
var _a;
|
|
95
|
-
const name = {
|
|
96
|
-
_id: generateID(ObjectTypes.BibliographicName),
|
|
97
|
-
objectType: ObjectTypes.BibliographicName,
|
|
98
|
-
};
|
|
101
|
+
const name = buildBibliographicName({});
|
|
99
102
|
const given = getTrimmedTextContent(authorNode, 'given-names');
|
|
100
103
|
if (given) {
|
|
101
104
|
name.given = given;
|
|
@@ -104,6 +107,10 @@ export const jatsReferenceParser = {
|
|
|
104
107
|
if (family) {
|
|
105
108
|
name.family = family;
|
|
106
109
|
}
|
|
110
|
+
const suffix = getTrimmedTextContent(authorNode, 'suffix');
|
|
111
|
+
if (suffix) {
|
|
112
|
+
name.suffix = suffix;
|
|
113
|
+
}
|
|
107
114
|
if (authorNode.nodeName === 'collab') {
|
|
108
115
|
name.literal = (_a = authorNode.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
109
116
|
}
|
|
@@ -113,7 +120,7 @@ export const jatsReferenceParser = {
|
|
|
113
120
|
bibliographyItem.author = authors;
|
|
114
121
|
}
|
|
115
122
|
const id = element.getAttribute('id');
|
|
116
|
-
references.add(bibliographyItem, id);
|
|
123
|
+
references.add(bibliographyItem, id, comments);
|
|
117
124
|
});
|
|
118
125
|
return references;
|
|
119
126
|
},
|