@manuscripts/transform 2.6.0 → 2.6.1-LEAN-3966.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +6 -6
- package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +305 -416
- package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
- package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
- package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
- package/dist/cjs/jats/importer/jats-comments.js +32 -111
- package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +350 -10
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +11 -1
- package/dist/cjs/jats/importer/jats-parser-utils.js +76 -9
- package/dist/cjs/jats/importer/jats-transformations.js +397 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +44 -101
- package/dist/cjs/jats/index.js +7 -7
- package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
- package/dist/cjs/lib/utils.js +3 -1
- package/dist/cjs/schema/nodes/highlight_marker.js +0 -4
- package/dist/cjs/transformer/id.js +1 -5
- package/dist/cjs/transformer/index.js +0 -18
- package/dist/cjs/version.js +1 -1
- package/dist/es/index.js +5 -5
- package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +300 -411
- package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
- package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
- package/dist/{cjs/transformer/model-map.js → es/jats/importer/create-article-node.js} +8 -10
- package/dist/es/jats/importer/jats-comments.js +32 -107
- package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +350 -10
- package/dist/es/jats/importer/jats-journal-meta-parser.js +9 -0
- package/dist/es/jats/importer/jats-parser-utils.js +78 -11
- package/dist/es/jats/importer/jats-transformations.js +377 -0
- package/dist/es/jats/importer/parse-jats-article.js +44 -99
- package/dist/es/jats/index.js +5 -3
- package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
- package/dist/es/lib/utils.js +1 -0
- package/dist/es/schema/nodes/highlight_marker.js +0 -4
- package/dist/es/transformer/id.js +0 -3
- package/dist/es/transformer/index.js +0 -16
- package/dist/es/version.js +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +16 -29
- package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
- package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
- package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
- package/dist/types/jats/importer/jats-comments.d.ts +2 -15
- package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +9 -0
- package/dist/types/jats/importer/jats-parser-utils.d.ts +2 -2
- package/dist/types/jats/importer/jats-transformations.d.ts +33 -0
- package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
- package/dist/types/jats/index.d.ts +5 -3
- package/dist/types/jats/types.d.ts +1 -0
- package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
- package/dist/types/lib/utils.d.ts +1 -0
- package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
- package/dist/types/schema/nodes/contributor.d.ts +10 -0
- package/dist/types/schema/nodes/highlight_marker.d.ts +0 -2
- package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
- package/dist/types/schema/nodes/manuscript.d.ts +8 -7
- package/dist/types/schema/nodes/title.d.ts +0 -3
- package/dist/types/transformer/id.d.ts +0 -3
- package/dist/types/transformer/index.d.ts +0 -16
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -1
- package/dist/cjs/__tests__/data/project-dump.json +0 -825
- package/dist/cjs/jats/importer/index.js +0 -22
- package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
- package/dist/cjs/jats/importer/jats-reference-parser.js +0 -130
- package/dist/cjs/jats/importer/jats-references.js +0 -34
- package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
- package/dist/cjs/transformer/builders.js +0 -219
- package/dist/cjs/transformer/decode.js +0 -898
- package/dist/cjs/transformer/document-object-types.js +0 -31
- package/dist/cjs/transformer/encode.js +0 -674
- package/dist/cjs/transformer/footnote-category.js +0 -20
- package/dist/cjs/transformer/footnotes-order.js +0 -60
- package/dist/cjs/transformer/highlight-markers.js +0 -138
- package/dist/cjs/transformer/html.js +0 -400
- package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
- package/dist/cjs/transformer/object-types.js +0 -57
- package/dist/cjs/transformer/project-bundle.js +0 -94
- package/dist/cjs/transformer/serializer.js +0 -23
- package/dist/cjs/transformer/timestamp.js +0 -20
- package/dist/cjs/transformer/update-identifiers.js +0 -93
- package/dist/es/__tests__/data/project-dump.json +0 -825
- package/dist/es/jats/importer/index.js +0 -16
- package/dist/es/jats/importer/jats-front-parser.js +0 -315
- package/dist/es/jats/importer/jats-reference-parser.js +0 -127
- package/dist/es/jats/importer/jats-references.js +0 -30
- package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
- package/dist/es/transformer/builders.js +0 -186
- package/dist/es/transformer/decode.js +0 -888
- package/dist/es/transformer/document-object-types.js +0 -28
- package/dist/es/transformer/encode.js +0 -664
- package/dist/es/transformer/filename.js +0 -23
- package/dist/es/transformer/footnotes-order.js +0 -55
- package/dist/es/transformer/highlight-markers.js +0 -132
- package/dist/es/transformer/html.js +0 -393
- package/dist/es/transformer/manuscript-dependencies.js +0 -17
- package/dist/es/transformer/model-map.js +0 -22
- package/dist/es/transformer/object-types.js +0 -52
- package/dist/es/transformer/project-bundle.js +0 -85
- package/dist/es/transformer/serializer.js +0 -17
- package/dist/es/transformer/timestamp.js +0 -16
- package/dist/es/transformer/update-identifiers.js +0 -87
- package/dist/types/jats/importer/index.d.ts +0 -16
- package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
- package/dist/types/jats/importer/jats-reference-parser.d.ts +0 -19
- package/dist/types/jats/importer/jats-references.d.ts +0 -12
- package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
- package/dist/types/transformer/builders.d.ts +0 -61
- package/dist/types/transformer/decode.d.ts +0 -52
- package/dist/types/transformer/document-object-types.d.ts +0 -17
- package/dist/types/transformer/encode.d.ts +0 -29
- package/dist/types/transformer/filename.d.ts +0 -16
- package/dist/types/transformer/footnote-category.d.ts +0 -17
- package/dist/types/transformer/footnotes-order.d.ts +0 -22
- package/dist/types/transformer/highlight-markers.d.ts +0 -31
- package/dist/types/transformer/html.d.ts +0 -36
- package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
- package/dist/types/transformer/model-map.d.ts +0 -19
- package/dist/types/transformer/models.d.ts +0 -48
- package/dist/types/transformer/object-types.d.ts +0 -30
- package/dist/types/transformer/project-bundle.d.ts +0 -30
- package/dist/types/transformer/serializer.d.ts +0 -19
- package/dist/types/transformer/update-identifiers.d.ts +0 -23
- package/dist/types/types.d.ts +0 -2
- /package/dist/cjs/{types.js → jats/types.js} +0 -0
- /package/dist/es/{types.js → jats/types.js} +0 -0
|
@@ -27,7 +27,6 @@ const versions = {
|
|
|
27
27
|
systemId: 'http://jats.nlm.nih.gov/archiving/1.2/JATS-archive-oasis-article1-mathml3.dtd',
|
|
28
28
|
},
|
|
29
29
|
};
|
|
30
|
-
export const supportedVersions = () => Object.keys(versions);
|
|
31
30
|
export const selectVersionIds = (version) => {
|
|
32
31
|
if (!(version in versions)) {
|
|
33
32
|
throw new Error(`Unknown version ${version}`);
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { schema } from '
|
|
17
|
-
import { nodeNames } from '
|
|
16
|
+
import { schema, } from '../../schema';
|
|
17
|
+
import { nodeNames } from '../../transformer/node-names';
|
|
18
18
|
const labelledNodeTypes = [
|
|
19
19
|
schema.nodes.figure_element,
|
|
20
20
|
schema.nodes.table_element,
|
|
@@ -26,7 +26,7 @@ const excludedTypes = [schema.nodes.graphical_abstract_section];
|
|
|
26
26
|
const chooseLabel = (nodeType) => {
|
|
27
27
|
return nodeNames.get(nodeType);
|
|
28
28
|
};
|
|
29
|
-
export const buildTargets = (
|
|
29
|
+
export const buildTargets = (node) => {
|
|
30
30
|
const counters = {};
|
|
31
31
|
for (const nodeType of labelledNodeTypes) {
|
|
32
32
|
counters[nodeType.name] = {
|
|
@@ -40,7 +40,7 @@ export const buildTargets = (fragment) => {
|
|
|
40
40
|
return `${counter.label} ${counter.index}`;
|
|
41
41
|
};
|
|
42
42
|
const targets = new Map();
|
|
43
|
-
|
|
43
|
+
node.descendants((node, pos, parent) => {
|
|
44
44
|
var _a;
|
|
45
45
|
if (node.type.name in counters) {
|
|
46
46
|
if (parent && excludedTypes.includes(parent.type)) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*!
|
|
3
|
-
* ©
|
|
2
|
+
* © 2024 Atypon Systems LLC
|
|
4
3
|
*
|
|
5
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,13 +13,12 @@
|
|
|
14
13
|
* See the License for the specific language governing permissions and
|
|
15
14
|
* limitations under the License.
|
|
16
15
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
22
|
-
|
|
16
|
+
import { defaultTitle } from '../../lib/deafults';
|
|
17
|
+
import { schema } from '../../schema';
|
|
18
|
+
export const createArticleNode = (attrs) => {
|
|
19
|
+
const title = schema.nodes.title.createChecked({}, schema.text(defaultTitle));
|
|
20
|
+
if (!attrs.id) {
|
|
21
|
+
throw new Error('Manuscript ID is missing');
|
|
23
22
|
}
|
|
24
|
-
|
|
23
|
+
return schema.nodes.manuscript.createAndFill(attrs, title);
|
|
25
24
|
};
|
|
26
|
-
exports.addModelToMap = addModelToMap;
|
|
@@ -13,43 +13,39 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
19
|
-
|
|
16
|
+
import { schema } from '../../schema';
|
|
17
|
+
import { generateNodeID } from '../../transformer';
|
|
18
|
+
export const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
|
|
19
|
+
const isJATSComment = (node) => {
|
|
20
20
|
return (node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
|
|
21
21
|
node.nodeName === 'AuthorQuery');
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
const parseJATSComment = (node) => {
|
|
24
24
|
const text = node.textContent;
|
|
25
25
|
if (text) {
|
|
26
|
-
const id = /id="(.+)"/.exec(text);
|
|
27
26
|
const queryText = /queryText="(.+)"/.exec(text);
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
id: id[1],
|
|
31
|
-
text: queryText[1],
|
|
32
|
-
};
|
|
33
|
-
}
|
|
27
|
+
return (queryText && queryText[1]) || undefined;
|
|
34
28
|
}
|
|
35
29
|
};
|
|
36
30
|
export const markComments = (doc) => {
|
|
37
|
-
|
|
31
|
+
var _a;
|
|
38
32
|
const root = doc.getRootNode();
|
|
39
33
|
const queue = [root];
|
|
34
|
+
const commentsElement = doc.createElement('comments');
|
|
40
35
|
while (queue.length !== 0) {
|
|
41
36
|
const node = queue.shift();
|
|
42
37
|
if (node) {
|
|
43
38
|
if (isJATSComment(node)) {
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
const text = parseJATSComment(node);
|
|
40
|
+
if (text) {
|
|
41
|
+
const id = generateNodeID(schema.nodes.comment);
|
|
42
|
+
const parent = node.parentNode;
|
|
43
|
+
if (parent) {
|
|
44
|
+
const marker = createHighlightMarkerElement(doc, id);
|
|
45
|
+
parent.insertBefore(marker, node);
|
|
46
|
+
const targetID = (_a = parent.closest('[id]')) === null || _a === void 0 ? void 0 : _a.id;
|
|
47
|
+
const commentElement = createCommentElement(doc, id, targetID, text);
|
|
48
|
+
commentsElement.appendChild(commentElement);
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
51
|
}
|
|
@@ -58,93 +54,22 @@ export const markComments = (doc) => {
|
|
|
58
54
|
});
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const addMark = (doc, node) => {
|
|
64
|
-
const parent = node.parentElement;
|
|
65
|
-
if (parent) {
|
|
66
|
-
const token = uuidv4();
|
|
67
|
-
const tokenNode = doc.createTextNode(token);
|
|
68
|
-
parent.insertBefore(tokenNode, node);
|
|
69
|
-
return token;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
export const createComments = (models, marks) => {
|
|
73
|
-
const comments = [];
|
|
74
|
-
for (const model of models) {
|
|
75
|
-
if (isHighlightableModel(model)) {
|
|
76
|
-
comments.push(...processModel(model, marks));
|
|
77
|
-
}
|
|
78
|
-
else if (isKeyword(model)) {
|
|
79
|
-
comments.push(...processKeyword(model, marks));
|
|
80
|
-
}
|
|
57
|
+
if (commentsElement.hasChildNodes()) {
|
|
58
|
+
doc.documentElement.appendChild(commentsElement);
|
|
81
59
|
}
|
|
82
|
-
return comments;
|
|
83
60
|
};
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
61
|
+
const createHighlightMarkerElement = (doc, id) => {
|
|
62
|
+
const highlightMarker = doc.createElement('highlight-marker');
|
|
63
|
+
highlightMarker.setAttribute('id', id);
|
|
64
|
+
highlightMarker.setAttribute('position', 'point');
|
|
65
|
+
return highlightMarker;
|
|
88
66
|
};
|
|
89
|
-
const
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
const results = processContent(model, content, getFieldMarks(content, marks));
|
|
97
|
-
model[field] = results.content;
|
|
98
|
-
comments.push(...results.comments);
|
|
99
|
-
}
|
|
100
|
-
return comments;
|
|
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;
|
|
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
|
-
}
|
|
67
|
+
const createCommentElement = (doc, id, targetID, text) => {
|
|
68
|
+
const commentElement = doc.createElement('comment');
|
|
69
|
+
commentElement.setAttribute('id', id);
|
|
70
|
+
if (targetID) {
|
|
71
|
+
commentElement.setAttribute('target-id', targetID);
|
|
148
72
|
}
|
|
149
|
-
|
|
73
|
+
commentElement.textContent = text;
|
|
74
|
+
return commentElement;
|
|
150
75
|
};
|
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { buildBibliographicDate, buildBibliographicName, buildContribution, ObjectTypes, } from '@manuscripts/json-schema';
|
|
16
17
|
import mime from 'mime';
|
|
17
18
|
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
18
|
-
import {
|
|
19
|
+
import { getTrimmedTextContent } from '../../lib/utils';
|
|
20
|
+
import { schema, } from '../../schema';
|
|
19
21
|
import { chooseSectionCategory } from '../../transformer';
|
|
22
|
+
import { DEFAULT_PROFILE_ID } from './jats-comments';
|
|
23
|
+
import { htmlFromJatsNode } from './jats-parser-utils';
|
|
20
24
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
21
25
|
const chooseContentType = (graphicNode) => {
|
|
22
26
|
if (graphicNode) {
|
|
@@ -31,6 +35,12 @@ const chooseContentType = (graphicNode) => {
|
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
};
|
|
38
|
+
const parsePriority = (priority) => {
|
|
39
|
+
if (!priority) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return parseInt(priority);
|
|
43
|
+
};
|
|
34
44
|
const getEquationContent = (p) => {
|
|
35
45
|
var _a;
|
|
36
46
|
const element = p;
|
|
@@ -53,6 +63,129 @@ const getEquationContent = (p) => {
|
|
|
53
63
|
}
|
|
54
64
|
return { id, format, contents };
|
|
55
65
|
};
|
|
66
|
+
const getEmail = (element) => {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
const email = element.querySelector('email');
|
|
69
|
+
if (email) {
|
|
70
|
+
return {
|
|
71
|
+
href: (_a = email.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _a !== void 0 ? _a : '',
|
|
72
|
+
text: (_c = (_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const getInstitutionDetails = (element) => {
|
|
77
|
+
var _a;
|
|
78
|
+
let department = '';
|
|
79
|
+
let institution = '';
|
|
80
|
+
for (const node of element.querySelectorAll('institution')) {
|
|
81
|
+
const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
82
|
+
if (!content) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const type = node.getAttribute('content-type');
|
|
86
|
+
if (type === 'dept') {
|
|
87
|
+
department = content;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
institution = content;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { department, institution };
|
|
94
|
+
};
|
|
95
|
+
const getAddressLine = (element, index) => {
|
|
96
|
+
return getTrimmedTextContent(element, `addr-line:nth-of-type(${index})`) || '';
|
|
97
|
+
};
|
|
98
|
+
const getHTMLContent = (node, querySelector) => {
|
|
99
|
+
return htmlFromJatsNode(node.querySelector(querySelector));
|
|
100
|
+
};
|
|
101
|
+
const chooseBibliographyItemType = (publicationType) => {
|
|
102
|
+
switch (publicationType) {
|
|
103
|
+
case 'book':
|
|
104
|
+
case 'thesis':
|
|
105
|
+
return publicationType;
|
|
106
|
+
case 'journal':
|
|
107
|
+
default:
|
|
108
|
+
return 'article-journal';
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const parseRef = (element) => {
|
|
112
|
+
const publicationType = element.getAttribute('publication-type');
|
|
113
|
+
const authorNodes = [
|
|
114
|
+
...element.querySelectorAll('person-group[person-group-type="author"] > *'),
|
|
115
|
+
];
|
|
116
|
+
const id = element.id;
|
|
117
|
+
const attrs = {
|
|
118
|
+
id,
|
|
119
|
+
type: chooseBibliographyItemType(publicationType),
|
|
120
|
+
};
|
|
121
|
+
const title = getHTMLContent(element, 'article-title');
|
|
122
|
+
if (title) {
|
|
123
|
+
attrs.title = title;
|
|
124
|
+
}
|
|
125
|
+
const mixedCitation = element.querySelector('mixed-citation');
|
|
126
|
+
if (authorNodes.length <= 0) {
|
|
127
|
+
mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
|
|
128
|
+
var _a, _b, _c;
|
|
129
|
+
if (item.nodeType === Node.TEXT_NODE &&
|
|
130
|
+
((_a = item.textContent) === null || _a === void 0 ? void 0 : _a.match(/[A-Za-z]+/g))) {
|
|
131
|
+
attrs.literal = (_c = (_b = mixedCitation.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
132
|
+
return attrs;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const source = getHTMLContent(element, 'source');
|
|
137
|
+
if (source) {
|
|
138
|
+
attrs.containerTitle = source;
|
|
139
|
+
}
|
|
140
|
+
const volume = getTrimmedTextContent(element, 'volume');
|
|
141
|
+
if (volume) {
|
|
142
|
+
attrs.volume = volume;
|
|
143
|
+
}
|
|
144
|
+
const issue = getTrimmedTextContent(element, 'issue');
|
|
145
|
+
if (issue) {
|
|
146
|
+
attrs.issue = issue;
|
|
147
|
+
}
|
|
148
|
+
const supplement = getTrimmedTextContent(element, 'supplement');
|
|
149
|
+
if (supplement) {
|
|
150
|
+
attrs.supplement = supplement;
|
|
151
|
+
}
|
|
152
|
+
const fpage = getTrimmedTextContent(element, 'fpage');
|
|
153
|
+
const lpage = getTrimmedTextContent(element, 'lpage');
|
|
154
|
+
if (fpage) {
|
|
155
|
+
attrs.page = lpage ? `${fpage}-${lpage}` : fpage;
|
|
156
|
+
}
|
|
157
|
+
const year = getTrimmedTextContent(element, 'year');
|
|
158
|
+
if (year) {
|
|
159
|
+
attrs.issued = buildBibliographicDate({
|
|
160
|
+
'date-parts': [[year]],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
const doi = getTrimmedTextContent(element, 'pub-id[pub-id-type="doi"]');
|
|
164
|
+
if (doi) {
|
|
165
|
+
attrs.doi = doi;
|
|
166
|
+
}
|
|
167
|
+
const authors = [];
|
|
168
|
+
authorNodes.forEach((authorNode) => {
|
|
169
|
+
var _a;
|
|
170
|
+
const name = buildBibliographicName({});
|
|
171
|
+
const given = getTrimmedTextContent(authorNode, 'given-names');
|
|
172
|
+
if (given) {
|
|
173
|
+
name.given = given;
|
|
174
|
+
}
|
|
175
|
+
const family = getTrimmedTextContent(authorNode, 'surname');
|
|
176
|
+
if (family) {
|
|
177
|
+
name.family = family;
|
|
178
|
+
}
|
|
179
|
+
if (authorNode.nodeName === 'collab') {
|
|
180
|
+
name.literal = (_a = authorNode.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
181
|
+
}
|
|
182
|
+
authors.push(name);
|
|
183
|
+
});
|
|
184
|
+
if (authors.length) {
|
|
185
|
+
attrs.author = authors;
|
|
186
|
+
}
|
|
187
|
+
return attrs;
|
|
188
|
+
};
|
|
56
189
|
const marks = [
|
|
57
190
|
{
|
|
58
191
|
tag: 'bold',
|
|
@@ -95,6 +228,202 @@ const marks = [
|
|
|
95
228
|
},
|
|
96
229
|
];
|
|
97
230
|
const nodes = [
|
|
231
|
+
{
|
|
232
|
+
tag: 'article',
|
|
233
|
+
node: 'manuscript',
|
|
234
|
+
getAttrs: (node) => {
|
|
235
|
+
var _a, _b;
|
|
236
|
+
const element = node;
|
|
237
|
+
const doi = element.querySelector('front > article-meta > article-id[pub-id-type="doi"]');
|
|
238
|
+
return {
|
|
239
|
+
doi: doi === null || doi === void 0 ? void 0 : doi.textContent,
|
|
240
|
+
articleType: (_a = element.getAttribute('article-type')) !== null && _a !== void 0 ? _a : '',
|
|
241
|
+
primaryLanguageCode: (_b = element.getAttribute('lang')) !== null && _b !== void 0 ? _b : '',
|
|
242
|
+
};
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
tag: 'article-title',
|
|
247
|
+
node: 'title',
|
|
248
|
+
getAttrs: (node) => {
|
|
249
|
+
const element = node;
|
|
250
|
+
return {
|
|
251
|
+
id: element.getAttribute('id'),
|
|
252
|
+
};
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
tag: 'highlight-marker',
|
|
257
|
+
node: 'highlight_marker',
|
|
258
|
+
getAttrs: (node) => {
|
|
259
|
+
const element = node;
|
|
260
|
+
return {
|
|
261
|
+
id: element.id,
|
|
262
|
+
position: element.getAttribute('position'),
|
|
263
|
+
};
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
tag: 'comment',
|
|
268
|
+
node: 'comment',
|
|
269
|
+
getAttrs: (node) => {
|
|
270
|
+
const element = node;
|
|
271
|
+
return {
|
|
272
|
+
id: element.getAttribute('id'),
|
|
273
|
+
target: element.getAttribute('target-id'),
|
|
274
|
+
contents: element.textContent,
|
|
275
|
+
contributions: [buildContribution(DEFAULT_PROFILE_ID)],
|
|
276
|
+
};
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
tag: 'author-notes',
|
|
281
|
+
node: 'author_notes',
|
|
282
|
+
getAttrs: (node) => {
|
|
283
|
+
const element = node;
|
|
284
|
+
return {
|
|
285
|
+
id: element.getAttribute('id'),
|
|
286
|
+
};
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
tag: 'funding-group',
|
|
291
|
+
node: 'awards',
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
tag: 'award-group',
|
|
295
|
+
node: 'award',
|
|
296
|
+
getAttrs: (node) => {
|
|
297
|
+
var _a, _b;
|
|
298
|
+
const element = node;
|
|
299
|
+
return {
|
|
300
|
+
id: element.getAttribute('id'),
|
|
301
|
+
recipient: (_a = element.querySelector('principal-award-recipient')) === null || _a === void 0 ? void 0 : _a.textContent,
|
|
302
|
+
code: Array.from(element.querySelectorAll('award-id'))
|
|
303
|
+
.map((awardID) => awardID.textContent)
|
|
304
|
+
.reduce((acc, text) => (acc ? `${acc};${text}` : text), ''),
|
|
305
|
+
source: (_b = element.querySelector('funding-source')) === null || _b === void 0 ? void 0 : _b.textContent,
|
|
306
|
+
};
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
tag: 'fn:not([fn-type])',
|
|
311
|
+
node: 'footnote',
|
|
312
|
+
context: 'author_notes/',
|
|
313
|
+
getAttrs: (node) => {
|
|
314
|
+
const element = node;
|
|
315
|
+
return {
|
|
316
|
+
id: element.getAttribute('id'),
|
|
317
|
+
kind: 'footnote',
|
|
318
|
+
};
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
tag: 'corresp',
|
|
323
|
+
node: 'corresp',
|
|
324
|
+
getAttrs: (node) => {
|
|
325
|
+
var _a;
|
|
326
|
+
const element = node;
|
|
327
|
+
const label = element.querySelector('label');
|
|
328
|
+
if (label) {
|
|
329
|
+
label.remove();
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
id: element.getAttribute('id'),
|
|
333
|
+
label: (_a = label === null || label === void 0 ? void 0 : label.textContent) === null || _a === void 0 ? void 0 : _a.trim(),
|
|
334
|
+
};
|
|
335
|
+
},
|
|
336
|
+
getContent: (node) => {
|
|
337
|
+
var _a;
|
|
338
|
+
const element = node;
|
|
339
|
+
return Fragment.from(schema.text(((_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || ''));
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
tag: 'contrib[contrib-type="author"]',
|
|
344
|
+
node: 'contributor',
|
|
345
|
+
getAttrs: (node) => {
|
|
346
|
+
var _a, _b;
|
|
347
|
+
const element = node;
|
|
348
|
+
const footnote = [];
|
|
349
|
+
const affiliations = [];
|
|
350
|
+
const corresp = [];
|
|
351
|
+
const xrefs = element.querySelectorAll('xref');
|
|
352
|
+
for (const xref of xrefs) {
|
|
353
|
+
const rid = xref.getAttribute('rid');
|
|
354
|
+
const type = xref.getAttribute('ref-type');
|
|
355
|
+
if (!rid) {
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
switch (type) {
|
|
359
|
+
case 'fn':
|
|
360
|
+
footnote.push({
|
|
361
|
+
noteID: rid,
|
|
362
|
+
noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
|
|
363
|
+
});
|
|
364
|
+
break;
|
|
365
|
+
case 'corresp':
|
|
366
|
+
corresp.push({
|
|
367
|
+
correspID: rid,
|
|
368
|
+
correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
|
|
369
|
+
});
|
|
370
|
+
break;
|
|
371
|
+
case 'aff':
|
|
372
|
+
affiliations.push(rid);
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
id: element.getAttribute('id'),
|
|
378
|
+
role: 'author',
|
|
379
|
+
affiliations,
|
|
380
|
+
corresp,
|
|
381
|
+
footnote,
|
|
382
|
+
isCorresponding: element.getAttribute('corresp')
|
|
383
|
+
? element.getAttribute('corresp') === 'yes'
|
|
384
|
+
: undefined,
|
|
385
|
+
bibliographicName: {
|
|
386
|
+
given: getTrimmedTextContent(element, 'name > given-names'),
|
|
387
|
+
family: getTrimmedTextContent(element, 'name > surname'),
|
|
388
|
+
ObjectType: ObjectTypes.BibliographicName,
|
|
389
|
+
},
|
|
390
|
+
ORCIDIdentifier: getTrimmedTextContent(element, 'contrib-id[contrib-id-type="orcid"]'),
|
|
391
|
+
priority: parsePriority(element.getAttribute('priority')),
|
|
392
|
+
};
|
|
393
|
+
},
|
|
394
|
+
getContent: () => {
|
|
395
|
+
return Fragment.from(schema.text('_'));
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
tag: 'affiliations',
|
|
400
|
+
node: 'affiliations',
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
tag: 'aff',
|
|
404
|
+
node: 'affiliation',
|
|
405
|
+
context: 'affiliations/',
|
|
406
|
+
getAttrs: (node) => {
|
|
407
|
+
var _a, _b;
|
|
408
|
+
const element = node;
|
|
409
|
+
const { department, institution } = getInstitutionDetails(element);
|
|
410
|
+
return {
|
|
411
|
+
id: element.getAttribute('id'),
|
|
412
|
+
institution: institution !== null && institution !== void 0 ? institution : '',
|
|
413
|
+
department: department !== null && department !== void 0 ? department : '',
|
|
414
|
+
addressLine1: getAddressLine(element, 1),
|
|
415
|
+
addressLine2: getAddressLine(element, 2),
|
|
416
|
+
addressLine3: getAddressLine(element, 3),
|
|
417
|
+
postCode: (_a = getTrimmedTextContent(element, 'postal-code')) !== null && _a !== void 0 ? _a : '',
|
|
418
|
+
country: (_b = getTrimmedTextContent(element, 'country')) !== null && _b !== void 0 ? _b : '',
|
|
419
|
+
email: getEmail(element),
|
|
420
|
+
priority: parsePriority(element.getAttribute('priority')),
|
|
421
|
+
};
|
|
422
|
+
},
|
|
423
|
+
getContent: () => {
|
|
424
|
+
return Fragment.from(schema.text('_'));
|
|
425
|
+
},
|
|
426
|
+
},
|
|
98
427
|
{
|
|
99
428
|
tag: 'attrib',
|
|
100
429
|
node: 'attribution',
|
|
@@ -103,10 +432,6 @@ const nodes = [
|
|
|
103
432
|
tag: 'back',
|
|
104
433
|
ignore: true,
|
|
105
434
|
},
|
|
106
|
-
{
|
|
107
|
-
tag: 'body',
|
|
108
|
-
node: 'manuscript',
|
|
109
|
-
},
|
|
110
435
|
{
|
|
111
436
|
tag: 'break',
|
|
112
437
|
node: 'hard_break',
|
|
@@ -126,13 +451,13 @@ const nodes = [
|
|
|
126
451
|
const title = element.querySelector('title');
|
|
127
452
|
if (title) {
|
|
128
453
|
const captionTitle = schema.nodes.caption_title.create();
|
|
129
|
-
content.push(
|
|
454
|
+
content.push(jatsDOMParser.parse(title, { topNode: captionTitle }));
|
|
130
455
|
}
|
|
131
456
|
const paragraphs = element.querySelectorAll('p');
|
|
132
457
|
if (paragraphs.length) {
|
|
133
458
|
const figcaption = schema.nodes.caption.create();
|
|
134
459
|
for (const paragraph of paragraphs) {
|
|
135
|
-
content.push(
|
|
460
|
+
content.push(jatsDOMParser.parse(paragraph, { topNode: figcaption }));
|
|
136
461
|
}
|
|
137
462
|
}
|
|
138
463
|
return Fragment.from(content);
|
|
@@ -334,7 +659,7 @@ const nodes = [
|
|
|
334
659
|
const paragraphs = [];
|
|
335
660
|
node.childNodes.forEach((p) => {
|
|
336
661
|
const paragraph = schema.nodes.paragraph.create();
|
|
337
|
-
const content =
|
|
662
|
+
const content = jatsDOMParser.parse(p, {
|
|
338
663
|
topNode: paragraph,
|
|
339
664
|
});
|
|
340
665
|
paragraphs.push(content);
|
|
@@ -445,6 +770,21 @@ const nodes = [
|
|
|
445
770
|
};
|
|
446
771
|
},
|
|
447
772
|
},
|
|
773
|
+
{
|
|
774
|
+
tag: 'sec[sec-type="bibliography"]',
|
|
775
|
+
node: 'bibliography_section',
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
tag: 'ref-list',
|
|
779
|
+
context: 'bibliography_section/',
|
|
780
|
+
node: 'bibliography_element',
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
tag: 'ref',
|
|
784
|
+
context: 'bibliography_element/',
|
|
785
|
+
node: 'bibliography_item',
|
|
786
|
+
getAttrs: (node) => parseRef(node),
|
|
787
|
+
},
|
|
448
788
|
{
|
|
449
789
|
tag: 'sec',
|
|
450
790
|
node: 'section',
|
|
@@ -524,7 +864,7 @@ const nodes = [
|
|
|
524
864
|
{
|
|
525
865
|
tag: 'title',
|
|
526
866
|
node: 'section_title',
|
|
527
|
-
context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/',
|
|
867
|
+
context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/|author_notes/',
|
|
528
868
|
},
|
|
529
869
|
{
|
|
530
870
|
tag: 'title',
|
|
@@ -606,4 +946,4 @@ const nodes = [
|
|
|
606
946
|
},
|
|
607
947
|
},
|
|
608
948
|
];
|
|
609
|
-
export const
|
|
949
|
+
export const jatsDOMParser = new DOMParser(schema, [...marks, ...nodes]);
|
|
@@ -13,6 +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';
|
|
16
17
|
import { getTrimmedTextContent } from '../../lib/utils';
|
|
17
18
|
export const parseJournalIdentifiers = (element) => {
|
|
18
19
|
var _a;
|
|
@@ -84,3 +85,11 @@ export const parseJournalMeta = (element) => {
|
|
|
84
85
|
title: (_b = getTrimmedTextContent(element, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
|
|
85
86
|
};
|
|
86
87
|
};
|
|
88
|
+
export const parseJournal = (doc) => {
|
|
89
|
+
const journalMeta = doc.querySelector('journal-meta');
|
|
90
|
+
if (!journalMeta) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const meta = parseJournalMeta(journalMeta);
|
|
94
|
+
return Object.assign(Object.assign({}, meta), { objectType: ObjectTypes.Journal });
|
|
95
|
+
};
|