@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
|
@@ -14,135 +14,136 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
-
import { buildComment, buildContribution,
|
|
18
|
-
const DEFAULT_ANNOTATION_COLOR = 'rgb(250, 224, 150)';
|
|
17
|
+
import { buildComment, buildContribution, highlightableFields, isHighlightableModel, isKeyword, } from '../../transformer';
|
|
19
18
|
const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
20
|
-
export const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
export const isJATSComment = (node) => {
|
|
20
|
+
return (node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
|
|
21
|
+
node.nodeName === 'AuthorQuery');
|
|
22
|
+
};
|
|
23
|
+
export const parseJATSComment = (node) => {
|
|
24
|
+
const text = node.textContent;
|
|
25
|
+
if (text) {
|
|
26
|
+
const id = /id="(.+)"/.exec(text);
|
|
27
|
+
const queryText = /queryText="(.+)"/.exec(text);
|
|
28
|
+
if (id && queryText) {
|
|
29
|
+
return {
|
|
30
|
+
id: id[1],
|
|
31
|
+
text: queryText[1],
|
|
32
|
+
};
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
};
|
|
32
|
-
export const
|
|
33
|
-
const
|
|
36
|
+
export const markComments = (doc) => {
|
|
37
|
+
const marks = [];
|
|
34
38
|
const root = doc.getRootNode();
|
|
35
39
|
const queue = [root];
|
|
36
40
|
while (queue.length !== 0) {
|
|
37
41
|
const node = queue.shift();
|
|
38
42
|
if (node) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
if (isJATSComment(node)) {
|
|
44
|
+
const comment = parseJATSComment(node);
|
|
45
|
+
if (comment) {
|
|
46
|
+
const token = addMark(doc, node);
|
|
47
|
+
if (token) {
|
|
48
|
+
const mark = {
|
|
49
|
+
token,
|
|
50
|
+
comment,
|
|
51
|
+
};
|
|
52
|
+
marks.push(mark);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
43
55
|
}
|
|
44
56
|
node.childNodes.forEach((child) => {
|
|
45
57
|
queue.push(child);
|
|
46
58
|
});
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
|
-
return
|
|
61
|
+
return marks;
|
|
50
62
|
};
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
if (parentElement && instruction) {
|
|
55
|
-
const { queryText } = instruction;
|
|
63
|
+
const addMark = (doc, node) => {
|
|
64
|
+
const parent = node.parentElement;
|
|
65
|
+
if (parent) {
|
|
56
66
|
const token = uuidv4();
|
|
57
67
|
const tokenNode = doc.createTextNode(token);
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const extractCommentsFromKeywords = (tokens, model, authorQueriesMap) => {
|
|
63
|
-
var _a;
|
|
64
|
-
const commentAnnotations = [];
|
|
65
|
-
const name = model.name;
|
|
66
|
-
const filteredTokens = filterAndSortTokens(tokens, name);
|
|
67
|
-
let content = name;
|
|
68
|
-
for (const token of filteredTokens) {
|
|
69
|
-
content = name.replace(token, '');
|
|
70
|
-
const query = authorQueriesMap.get(token);
|
|
71
|
-
const commentAnnotation = buildComment((_a = model.containedGroup) !== null && _a !== void 0 ? _a : uuidv4(), `${query}`, undefined, [buildContribution(DEFAULT_PROFILE_ID)], DEFAULT_ANNOTATION_COLOR);
|
|
72
|
-
model['name'] = content;
|
|
73
|
-
commentAnnotations.push(commentAnnotation);
|
|
68
|
+
parent.insertBefore(tokenNode, node);
|
|
69
|
+
return token;
|
|
74
70
|
}
|
|
75
|
-
return commentAnnotations;
|
|
76
71
|
};
|
|
77
|
-
export const createComments = (
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
for (const model of manuscriptModels) {
|
|
72
|
+
export const createComments = (models, marks) => {
|
|
73
|
+
const comments = [];
|
|
74
|
+
for (const model of models) {
|
|
81
75
|
if (isHighlightableModel(model)) {
|
|
82
|
-
|
|
83
|
-
commentAnnotations.push(...comments);
|
|
76
|
+
comments.push(...processModel(model, marks));
|
|
84
77
|
}
|
|
85
78
|
else if (isKeyword(model)) {
|
|
86
|
-
|
|
87
|
-
commentAnnotations.push(...comments);
|
|
79
|
+
comments.push(...processKeyword(model, marks));
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
|
-
return
|
|
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));
|
|
91
88
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
const addCommentsFromMarkedProcessingInstructions = (tokens, model, authorQueriesMap) => {
|
|
98
|
-
const commentAnnotations = [];
|
|
99
|
-
for (const field of ['contents', 'caption', 'title']) {
|
|
100
|
-
const highlightableField = field;
|
|
101
|
-
const content = model[highlightableField];
|
|
89
|
+
const processModel = (model, marks) => {
|
|
90
|
+
const comments = [];
|
|
91
|
+
for (const field of highlightableFields) {
|
|
92
|
+
const content = model[field];
|
|
102
93
|
if (!content) {
|
|
103
94
|
continue;
|
|
104
95
|
}
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const target = model._id && !isCommentAnnotation(model) ? model._id : uuidv4();
|
|
121
|
-
const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
|
|
122
|
-
const selector = startTokenIndex
|
|
123
|
-
? { from: startTokenIndex, to: startTokenIndex }
|
|
124
|
-
: undefined;
|
|
125
|
-
const commentAnnotation = buildComment(target, comment, selector, contributions, DEFAULT_ANNOTATION_COLOR);
|
|
126
|
-
commentAnnotations.push(commentAnnotation);
|
|
127
|
-
}
|
|
96
|
+
const results = processContent(model, content, getFieldMarks(content, marks));
|
|
97
|
+
model[field] = results.content;
|
|
98
|
+
comments.push(...results.comments);
|
|
99
|
+
}
|
|
100
|
+
return comments;
|
|
101
|
+
};
|
|
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;
|
|
128
111
|
}
|
|
129
|
-
|
|
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);
|
|
130
116
|
}
|
|
131
|
-
return
|
|
117
|
+
return comments;
|
|
132
118
|
};
|
|
133
|
-
|
|
119
|
+
const processContent = (model, content, marks) => {
|
|
134
120
|
const comments = [];
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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);
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
return comments;
|
|
@@ -15,11 +15,30 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import debug from 'debug';
|
|
17
17
|
import { getTrimmedTextContent } from '../../lib/utils';
|
|
18
|
-
import { buildAffiliation, buildBibliographicName, buildContributor, buildCorresp, buildFootnote, buildSupplementaryMaterial, } from '../../transformer';
|
|
18
|
+
import { buildAffiliation, buildBibliographicName, buildContributor, buildCorresp, buildFootnote, buildJournal, buildSupplementaryMaterial, buildTitles, } from '../../transformer';
|
|
19
19
|
import { parseJournalMeta } from './jats-journal-meta-parser';
|
|
20
|
+
import { htmlFromJatsNode } from './jats-parser-utils';
|
|
20
21
|
const warn = debug('manuscripts-transform');
|
|
21
22
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
23
|
+
const defaultTitle = 'Untitled Manuscript';
|
|
22
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
|
+
},
|
|
23
42
|
parseCounts(counts) {
|
|
24
43
|
var _a, _b, _c, _d, _e;
|
|
25
44
|
if (counts) {
|
|
@@ -36,7 +55,7 @@ export const jatsFrontParser = {
|
|
|
36
55
|
for (const element of countElements.values()) {
|
|
37
56
|
const countType = element.getAttribute('count-type');
|
|
38
57
|
const count = parseCount(element.getAttribute('count'));
|
|
39
|
-
if (countType
|
|
58
|
+
if (countType) {
|
|
40
59
|
const genericCount = { count, countType };
|
|
41
60
|
genericCounts.push(genericCount);
|
|
42
61
|
}
|
|
@@ -51,17 +70,9 @@ export const jatsFrontParser = {
|
|
|
51
70
|
};
|
|
52
71
|
}
|
|
53
72
|
},
|
|
54
|
-
parseJournal(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
journalIdentifiers: [],
|
|
58
|
-
abbreviatedTitles: [],
|
|
59
|
-
ISSNs: [],
|
|
60
|
-
publisherName: undefined,
|
|
61
|
-
title: undefined,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return parseJournalMeta(journalMeta);
|
|
73
|
+
parseJournal(element) {
|
|
74
|
+
const meta = parseJournalMeta(element);
|
|
75
|
+
return Object.assign(Object.assign({}, meta), buildJournal());
|
|
65
76
|
},
|
|
66
77
|
parseDates(historyNode) {
|
|
67
78
|
if (!historyNode) {
|
|
@@ -111,66 +122,61 @@ export const jatsFrontParser = {
|
|
|
111
122
|
}
|
|
112
123
|
return history;
|
|
113
124
|
},
|
|
114
|
-
parseSupplements(
|
|
125
|
+
parseSupplements(elements) {
|
|
115
126
|
var _a, _b, _c, _d;
|
|
116
|
-
if (!
|
|
127
|
+
if (!(elements === null || elements === void 0 ? void 0 : elements.length)) {
|
|
117
128
|
return [];
|
|
118
129
|
}
|
|
119
130
|
const supplements = [];
|
|
120
|
-
for (const
|
|
121
|
-
const
|
|
122
|
-
const href = (_b =
|
|
123
|
-
const
|
|
124
|
-
const mimeType = (_c =
|
|
125
|
-
const mimeSubtype = (_d =
|
|
131
|
+
for (const element of elements) {
|
|
132
|
+
const title = (_a = getTrimmedTextContent(element, 'caption > title')) !== null && _a !== void 0 ? _a : '';
|
|
133
|
+
const href = (_b = element.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _b !== void 0 ? _b : '';
|
|
134
|
+
const supplement = buildSupplementaryMaterial(title, href);
|
|
135
|
+
const mimeType = (_c = element.getAttribute('mimetype')) !== null && _c !== void 0 ? _c : '';
|
|
136
|
+
const mimeSubtype = (_d = element.getAttribute('mime-subtype')) !== null && _d !== void 0 ? _d : '';
|
|
126
137
|
if (mimeType && mimeSubtype) {
|
|
127
|
-
|
|
138
|
+
supplement.MIME = [mimeType, mimeSubtype].join('/');
|
|
128
139
|
}
|
|
129
|
-
supplements.push(
|
|
140
|
+
supplements.push(supplement);
|
|
130
141
|
}
|
|
131
142
|
return supplements;
|
|
132
143
|
},
|
|
133
|
-
|
|
144
|
+
parseAffiliations(elements) {
|
|
134
145
|
const affiliationIDs = new Map();
|
|
135
|
-
const affiliations =
|
|
146
|
+
const affiliations = elements.map((element, priority) => {
|
|
136
147
|
var _a, _b;
|
|
137
148
|
const affiliation = buildAffiliation('', priority);
|
|
138
|
-
for (const node of
|
|
149
|
+
for (const node of element.querySelectorAll('institution')) {
|
|
139
150
|
const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
140
151
|
if (!content) {
|
|
141
152
|
continue;
|
|
142
153
|
}
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
affiliation.department = content;
|
|
150
|
-
break;
|
|
154
|
+
const type = node.getAttribute('content-type');
|
|
155
|
+
if (type === 'dept') {
|
|
156
|
+
affiliation.department = content;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
affiliation.institution = content;
|
|
151
160
|
}
|
|
152
161
|
}
|
|
153
162
|
affiliation.addressLine1 =
|
|
154
|
-
getTrimmedTextContent(
|
|
155
|
-
undefined;
|
|
163
|
+
getTrimmedTextContent(element, 'addr-line:nth-of-type(1)') || undefined;
|
|
156
164
|
affiliation.addressLine2 =
|
|
157
|
-
getTrimmedTextContent(
|
|
158
|
-
undefined;
|
|
165
|
+
getTrimmedTextContent(element, 'addr-line:nth-of-type(2)') || undefined;
|
|
159
166
|
affiliation.addressLine3 =
|
|
160
|
-
getTrimmedTextContent(
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
getTrimmedTextContent(element, 'addr-line:nth-of-type(3)') || undefined;
|
|
168
|
+
affiliation.postCode =
|
|
169
|
+
getTrimmedTextContent(element, 'postal-code') || undefined;
|
|
170
|
+
affiliation.country =
|
|
171
|
+
getTrimmedTextContent(element, 'country') || undefined;
|
|
172
|
+
const email = element.querySelector('email');
|
|
173
|
+
if (email) {
|
|
164
174
|
affiliation.email = {
|
|
165
|
-
href:
|
|
166
|
-
text: ((_b =
|
|
175
|
+
href: email.getAttributeNS(XLINK_NAMESPACE, 'href') || undefined,
|
|
176
|
+
text: ((_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
167
177
|
};
|
|
168
178
|
}
|
|
169
|
-
|
|
170
|
-
getTrimmedTextContent(affiliationNode, 'postal-code') || undefined;
|
|
171
|
-
affiliation.country =
|
|
172
|
-
getTrimmedTextContent(affiliationNode, 'country') || undefined;
|
|
173
|
-
const id = affiliationNode.getAttribute('id');
|
|
179
|
+
const id = element.getAttribute('id');
|
|
174
180
|
if (id) {
|
|
175
181
|
affiliationIDs.set(id, affiliation._id);
|
|
176
182
|
}
|
|
@@ -181,11 +187,11 @@ export const jatsFrontParser = {
|
|
|
181
187
|
affiliationIDs,
|
|
182
188
|
};
|
|
183
189
|
},
|
|
184
|
-
|
|
190
|
+
parseAuthorNotes(elements) {
|
|
185
191
|
const footnoteIDs = new Map();
|
|
186
|
-
const footnotes =
|
|
187
|
-
const fn = buildFootnote('',
|
|
188
|
-
const id =
|
|
192
|
+
const footnotes = elements.map((element) => {
|
|
193
|
+
const fn = buildFootnote('', element.innerHTML);
|
|
194
|
+
const id = element.getAttribute('id');
|
|
189
195
|
if (id) {
|
|
190
196
|
footnoteIDs.set(id, fn._id);
|
|
191
197
|
}
|
|
@@ -196,17 +202,17 @@ export const jatsFrontParser = {
|
|
|
196
202
|
footnoteIDs,
|
|
197
203
|
};
|
|
198
204
|
},
|
|
199
|
-
|
|
205
|
+
parseCorresp(elements) {
|
|
200
206
|
const correspondingIDs = new Map();
|
|
201
|
-
const correspondingList =
|
|
207
|
+
const correspondingList = elements.map((element) => {
|
|
202
208
|
var _a, _b, _c;
|
|
203
|
-
const label =
|
|
209
|
+
const label = element.querySelector('label');
|
|
204
210
|
if (label) {
|
|
205
211
|
label.remove();
|
|
206
212
|
}
|
|
207
|
-
const corresponding = buildCorresp((_b = (_a =
|
|
213
|
+
const corresponding = buildCorresp((_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
|
|
208
214
|
corresponding.label = ((_c = label === null || label === void 0 ? void 0 : label.textContent) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
|
|
209
|
-
const id =
|
|
215
|
+
const id = element.getAttribute('id');
|
|
210
216
|
if (id) {
|
|
211
217
|
correspondingIDs.set(id, corresponding._id);
|
|
212
218
|
}
|
|
@@ -217,60 +223,60 @@ export const jatsFrontParser = {
|
|
|
217
223
|
correspondingIDs,
|
|
218
224
|
};
|
|
219
225
|
},
|
|
220
|
-
|
|
221
|
-
return
|
|
226
|
+
parseContributors(elements, affiliationIDs, footnoteIDs, correspondingIDs) {
|
|
227
|
+
return elements.map((element, priority) => {
|
|
222
228
|
var _a, _b;
|
|
223
229
|
const name = buildBibliographicName({});
|
|
224
|
-
const given = getTrimmedTextContent(
|
|
230
|
+
const given = getTrimmedTextContent(element, 'name > given-names');
|
|
225
231
|
if (given) {
|
|
226
232
|
name.given = given;
|
|
227
233
|
}
|
|
228
|
-
const surname = getTrimmedTextContent(
|
|
234
|
+
const surname = getTrimmedTextContent(element, 'name > surname');
|
|
229
235
|
if (surname) {
|
|
230
236
|
name.family = surname;
|
|
231
237
|
}
|
|
232
238
|
const contributor = buildContributor(name, 'author', priority);
|
|
233
|
-
const corresponding =
|
|
239
|
+
const corresponding = element.getAttribute('corresp') === 'yes';
|
|
234
240
|
if (corresponding) {
|
|
235
241
|
contributor.isCorresponding = corresponding;
|
|
236
242
|
}
|
|
237
|
-
const orcid = getTrimmedTextContent(
|
|
243
|
+
const orcid = getTrimmedTextContent(element, 'contrib-id[contrib-id-type="orcid"]');
|
|
238
244
|
if (orcid) {
|
|
239
245
|
contributor.ORCIDIdentifier = orcid;
|
|
240
246
|
}
|
|
241
|
-
const
|
|
242
|
-
for (const
|
|
243
|
-
if (
|
|
244
|
-
const rid =
|
|
245
|
-
const
|
|
247
|
+
const xrefs = element.querySelectorAll('xref');
|
|
248
|
+
for (const xref of xrefs) {
|
|
249
|
+
if (xref) {
|
|
250
|
+
const rid = xref.getAttribute('rid');
|
|
251
|
+
const type = xref.getAttribute('ref-type');
|
|
246
252
|
if (rid) {
|
|
247
|
-
if (
|
|
253
|
+
if (type === 'fn') {
|
|
248
254
|
contributor.footnote = [];
|
|
249
|
-
const
|
|
250
|
-
if (
|
|
255
|
+
const footnoteID = footnoteIDs.get(rid);
|
|
256
|
+
if (footnoteID) {
|
|
251
257
|
const authorFootNoteRef = {
|
|
252
|
-
noteID:
|
|
253
|
-
noteLabel: ((_a =
|
|
258
|
+
noteID: footnoteID,
|
|
259
|
+
noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
|
|
254
260
|
};
|
|
255
261
|
contributor.footnote.push(authorFootNoteRef);
|
|
256
262
|
}
|
|
257
263
|
}
|
|
258
|
-
else if (
|
|
264
|
+
else if (type === 'corresp') {
|
|
259
265
|
contributor.corresp = [];
|
|
260
|
-
const
|
|
261
|
-
if (
|
|
266
|
+
const correspID = correspondingIDs.get(rid);
|
|
267
|
+
if (correspID) {
|
|
262
268
|
const authorCorrespRef = {
|
|
263
|
-
correspID:
|
|
264
|
-
correspLabel: ((_b =
|
|
269
|
+
correspID: correspID,
|
|
270
|
+
correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
|
|
265
271
|
};
|
|
266
272
|
contributor.corresp.push(authorCorrespRef);
|
|
267
273
|
}
|
|
268
274
|
}
|
|
269
|
-
else if (
|
|
275
|
+
else if (type === 'aff') {
|
|
270
276
|
const rids = rid
|
|
271
277
|
.split(/\s+/)
|
|
272
|
-
.
|
|
273
|
-
.
|
|
278
|
+
.map((id) => affiliationIDs.get(id))
|
|
279
|
+
.filter(Boolean);
|
|
274
280
|
if (rids.length) {
|
|
275
281
|
contributor.affiliations = rids;
|
|
276
282
|
}
|
|
@@ -14,61 +14,73 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { getTrimmedTextContent } from '../../lib/utils';
|
|
17
|
-
export const parseJournalIdentifiers = (
|
|
18
|
-
var _a
|
|
17
|
+
export const parseJournalIdentifiers = (element) => {
|
|
18
|
+
var _a;
|
|
19
|
+
if (!element) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
19
22
|
const output = [];
|
|
20
|
-
const
|
|
21
|
-
for (const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
else if (journalID !== null) {
|
|
28
|
-
output.push({ journalID });
|
|
23
|
+
const ids = element.querySelectorAll('journal-id');
|
|
24
|
+
for (const id of ids) {
|
|
25
|
+
const type = id.getAttribute('journal-id-type');
|
|
26
|
+
const value = (_a = id.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
27
|
+
if (!value) {
|
|
28
|
+
continue;
|
|
29
29
|
}
|
|
30
|
+
output.push({
|
|
31
|
+
journalID: value,
|
|
32
|
+
journalIDType: type !== null && type !== void 0 ? type : undefined,
|
|
33
|
+
});
|
|
30
34
|
}
|
|
31
35
|
return output;
|
|
32
36
|
};
|
|
33
|
-
export const parseJournalAbbreviatedTitles = (
|
|
34
|
-
var _a
|
|
37
|
+
export const parseJournalAbbreviatedTitles = (element) => {
|
|
38
|
+
var _a;
|
|
39
|
+
if (!element) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
35
42
|
const output = [];
|
|
36
|
-
const
|
|
37
|
-
for (const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
else if (abbreviatedTitle !== null) {
|
|
44
|
-
output.push({ abbreviatedTitle });
|
|
43
|
+
const titles = element.querySelectorAll('journal-title-group > abbrev-journal-title');
|
|
44
|
+
for (const title of titles) {
|
|
45
|
+
const type = title.getAttribute('abbrev-type');
|
|
46
|
+
const value = (_a = title.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
47
|
+
if (!value) {
|
|
48
|
+
continue;
|
|
45
49
|
}
|
|
50
|
+
output.push({
|
|
51
|
+
abbreviatedTitle: value,
|
|
52
|
+
abbrevType: type !== null && type !== void 0 ? type : undefined,
|
|
53
|
+
});
|
|
46
54
|
}
|
|
47
55
|
return output;
|
|
48
56
|
};
|
|
49
|
-
export const parseJournalISSNs = (
|
|
50
|
-
var _a
|
|
57
|
+
export const parseJournalISSNs = (element) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!element) {
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
51
62
|
const output = [];
|
|
52
|
-
const
|
|
53
|
-
for (const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
else if (ISSN !== null) {
|
|
60
|
-
output.push({ ISSN });
|
|
63
|
+
const issns = element.querySelectorAll('issn');
|
|
64
|
+
for (const issn of issns) {
|
|
65
|
+
const type = issn.getAttribute('pub-type');
|
|
66
|
+
const value = (_a = issn.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
67
|
+
if (!value) {
|
|
68
|
+
continue;
|
|
61
69
|
}
|
|
70
|
+
output.push({
|
|
71
|
+
ISSN: value,
|
|
72
|
+
publicationType: type !== null && type !== void 0 ? type : undefined,
|
|
73
|
+
});
|
|
62
74
|
}
|
|
63
75
|
return output;
|
|
64
76
|
};
|
|
65
|
-
export const parseJournalMeta = (
|
|
77
|
+
export const parseJournalMeta = (element) => {
|
|
66
78
|
var _a, _b;
|
|
67
79
|
return {
|
|
68
|
-
abbreviatedTitles: parseJournalAbbreviatedTitles(
|
|
69
|
-
journalIdentifiers: parseJournalIdentifiers(
|
|
70
|
-
ISSNs: parseJournalISSNs(
|
|
71
|
-
publisherName: (_a = getTrimmedTextContent(
|
|
72
|
-
title: (_b = getTrimmedTextContent(
|
|
80
|
+
abbreviatedTitles: parseJournalAbbreviatedTitles(element),
|
|
81
|
+
journalIdentifiers: parseJournalIdentifiers(element),
|
|
82
|
+
ISSNs: parseJournalISSNs(element),
|
|
83
|
+
publisherName: (_a = getTrimmedTextContent(element, 'publisher > publisher-name')) !== null && _a !== void 0 ? _a : undefined,
|
|
84
|
+
title: (_b = getTrimmedTextContent(element, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
|
|
73
85
|
};
|
|
74
86
|
};
|