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