@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
|
@@ -14,26 +14,38 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
-
import { schema } from '../../schema';
|
|
18
|
-
import {
|
|
19
|
-
|
|
17
|
+
import { schema, } from '../../schema';
|
|
18
|
+
import { generateNodeID, nodeTypesMap } from '../../transformer';
|
|
19
|
+
const nonJSONSchemaTypes = new Set([
|
|
20
|
+
'inline_equation',
|
|
21
|
+
'general_table_footnote',
|
|
22
|
+
'award',
|
|
23
|
+
]);
|
|
24
|
+
export const updateDocumentIDs = (node) => {
|
|
25
|
+
const replacements = new Map();
|
|
20
26
|
const warnings = [];
|
|
21
27
|
recurseDoc(node, (n) => updateNodeID(n, replacements, warnings));
|
|
28
|
+
updateHighlightCommentTargets(node);
|
|
22
29
|
recurseDoc(node, (n) => updateNodeRID(n, replacements, warnings));
|
|
23
30
|
recurseDoc(node, (n) => updateNodeRIDS(n, replacements, warnings));
|
|
31
|
+
recurseDoc(node, (n) => updateContributorNodesIDS(n, replacements, warnings));
|
|
32
|
+
recurseDoc(node, (n) => updateCommentTarget(n, replacements, warnings));
|
|
24
33
|
return warnings;
|
|
25
34
|
};
|
|
26
|
-
|
|
35
|
+
const recurseDoc = (node, fn) => {
|
|
27
36
|
fn(node);
|
|
28
37
|
node.descendants((n) => fn(n));
|
|
29
|
-
}
|
|
38
|
+
};
|
|
30
39
|
const updateNodeID = (node, replacements, warnings) => {
|
|
31
|
-
if (node.type
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
if (nonJSONSchemaTypes.has(node.type.name)) {
|
|
41
|
+
const id = `${node.type.name
|
|
42
|
+
.split('_')
|
|
43
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
44
|
+
.join('')}:${uuidv4()}`;
|
|
45
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { id });
|
|
34
46
|
}
|
|
35
|
-
if (node.type === schema.nodes.
|
|
36
|
-
node.
|
|
47
|
+
if (node.type === schema.nodes.comment ||
|
|
48
|
+
node.type === schema.nodes.highlight_marker) {
|
|
37
49
|
return;
|
|
38
50
|
}
|
|
39
51
|
if (!('id' in node.attrs)) {
|
|
@@ -45,7 +57,7 @@ const updateNodeID = (node, replacements, warnings) => {
|
|
|
45
57
|
return;
|
|
46
58
|
}
|
|
47
59
|
const previousID = node.attrs.id;
|
|
48
|
-
const nextID =
|
|
60
|
+
const nextID = generateNodeID(node.type);
|
|
49
61
|
if (previousID) {
|
|
50
62
|
if (replacements.has(previousID) ||
|
|
51
63
|
Array.from(replacements.values()).includes(previousID)) {
|
|
@@ -74,6 +86,58 @@ const updateNodeRIDS = (node, replacements, warnings) => {
|
|
|
74
86
|
}
|
|
75
87
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { rids: previousRIDs.map((r) => replacements.get(r) || r) });
|
|
76
88
|
};
|
|
89
|
+
const updateContributorNodesIDS = (node, replacements, warnings) => {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
if (node.type === schema.nodes.contributor) {
|
|
92
|
+
const footnote = (_a = node.attrs.footnote) === null || _a === void 0 ? void 0 : _a.map((fn) => {
|
|
93
|
+
return replacements.get(fn.noteID)
|
|
94
|
+
? Object.assign(Object.assign({}, fn), { noteID: replacements.get(fn.noteID) }) : undefined;
|
|
95
|
+
}).filter(Boolean);
|
|
96
|
+
const corresp = (_b = node.attrs.corresp) === null || _b === void 0 ? void 0 : _b.map((corresp) => {
|
|
97
|
+
return replacements.get(corresp.correspID)
|
|
98
|
+
? Object.assign(Object.assign({}, corresp), { correspID: replacements.get(corresp.correspID) }) : undefined;
|
|
99
|
+
}).filter(Boolean);
|
|
100
|
+
const affiliations = node.attrs.affiliations
|
|
101
|
+
.map((affiliation) => {
|
|
102
|
+
return replacements.get(affiliation);
|
|
103
|
+
})
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { footnote,
|
|
106
|
+
corresp,
|
|
107
|
+
affiliations });
|
|
108
|
+
}
|
|
109
|
+
if (node.type !== schema.nodes.contributors) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const updateCommentTarget = (node, replacements, warnings) => {
|
|
114
|
+
if (node.type !== schema.nodes.comment) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const target = node.attrs.target;
|
|
118
|
+
if (!target) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (!replacements.has(target)) {
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { target: replacements.get(target) });
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const updateHighlightCommentTargets = (doc) => {
|
|
128
|
+
const targetIDs = new Map();
|
|
129
|
+
doc.descendants((node, pos, parent) => {
|
|
130
|
+
if (node.type === schema.nodes.highlight_marker) {
|
|
131
|
+
targetIDs.set(node.attrs.id, parent.attrs.id);
|
|
132
|
+
}
|
|
133
|
+
if (node.type === schema.nodes.comment) {
|
|
134
|
+
const targetID = targetIDs.get(node.attrs.id);
|
|
135
|
+
if (targetID) {
|
|
136
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { target: targetID });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
};
|
|
77
141
|
const JATS_TO_HTML_MAPPING = new Map([
|
|
78
142
|
['bold', 'b'],
|
|
79
143
|
['italic', 'i'],
|
|
@@ -109,6 +173,9 @@ export const htmlFromJatsNode = (element, createElement) => {
|
|
|
109
173
|
if (!element) {
|
|
110
174
|
return undefined;
|
|
111
175
|
}
|
|
176
|
+
if (!createElement) {
|
|
177
|
+
createElement = (tagName) => element.ownerDocument.createElement(tagName);
|
|
178
|
+
}
|
|
112
179
|
const temp = createElement('template');
|
|
113
180
|
renameJatsNodesToHTML(element, temp, createElement);
|
|
114
181
|
return temp.innerHTML;
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2020 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { defaultTitle } from '../../lib/deafults';
|
|
17
|
+
import { abstractsType, backmatterType, bodyType, } from '../../lib/section-group-type';
|
|
18
|
+
import { chooseSectionCategoryByType, chooseSecType } from '../../transformer';
|
|
19
|
+
import { htmlFromJatsNode } from './jats-parser-utils';
|
|
20
|
+
const removeNodeFromParent = (node) => node.parentNode && node.parentNode.removeChild(node);
|
|
21
|
+
const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
22
|
+
const createSectionGroup = (type, createElement) => {
|
|
23
|
+
const sec = createElement('sec');
|
|
24
|
+
sec.setAttribute('sec-type', type._id);
|
|
25
|
+
const title = createElement('title');
|
|
26
|
+
title.textContent = type.title;
|
|
27
|
+
sec.appendChild(title);
|
|
28
|
+
return sec;
|
|
29
|
+
};
|
|
30
|
+
export const ensureSection = (body, createElement) => {
|
|
31
|
+
let section;
|
|
32
|
+
const element = body.firstElementChild;
|
|
33
|
+
if (element && element.tagName === 'sec') {
|
|
34
|
+
section = element;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
section = createElement('sec');
|
|
38
|
+
body.insertBefore(section, body.firstChild);
|
|
39
|
+
}
|
|
40
|
+
body.childNodes.forEach((child) => {
|
|
41
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
42
|
+
const element = child;
|
|
43
|
+
if (element.tagName !== 'sec') {
|
|
44
|
+
section.appendChild(element);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
section = element;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export const moveTitle = (front, createElement) => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
let title = front.querySelector('article-meta > title-group > article-title');
|
|
55
|
+
if (title) {
|
|
56
|
+
title.innerHTML = (_a = htmlFromJatsNode(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
title = createElement('article-title');
|
|
60
|
+
title.innerHTML = defaultTitle;
|
|
61
|
+
}
|
|
62
|
+
(_b = front.parentNode) === null || _b === void 0 ? void 0 : _b.insertBefore(title, front);
|
|
63
|
+
};
|
|
64
|
+
export const moveAuthorNotes = (front, createElement) => {
|
|
65
|
+
var _a;
|
|
66
|
+
const authorNotes = front.querySelector('article-meta > author-notes');
|
|
67
|
+
if (authorNotes) {
|
|
68
|
+
const sectionTitle = createElement('title');
|
|
69
|
+
authorNotes.prepend(sectionTitle);
|
|
70
|
+
(_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(authorNotes, front);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export const moveAwards = (front) => {
|
|
74
|
+
var _a;
|
|
75
|
+
const awards = front.querySelector('article-meta > funding-group');
|
|
76
|
+
if (awards) {
|
|
77
|
+
(_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(awards, front);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export const moveContributors = (front, createElement) => {
|
|
81
|
+
var _a;
|
|
82
|
+
const contribs = front.querySelectorAll('contrib-group > contrib[contrib-type="author"]');
|
|
83
|
+
if (contribs.length) {
|
|
84
|
+
const contributors = createElement('contributors');
|
|
85
|
+
contribs.forEach((c) => contributors.appendChild(c));
|
|
86
|
+
(_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(contributors, front);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export const moveAffiliations = (front, createElement) => {
|
|
90
|
+
var _a;
|
|
91
|
+
const affs = front.querySelectorAll('article-meta > contrib-group > aff');
|
|
92
|
+
if (affs.length) {
|
|
93
|
+
const affiliations = createElement('affiliations');
|
|
94
|
+
affs.forEach((a) => affiliations.appendChild(a));
|
|
95
|
+
(_a = front.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(affiliations, front);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export const moveAbstracts = (doc, group, createElement) => {
|
|
99
|
+
const abstracts = doc.querySelectorAll('front > article-meta > abstract');
|
|
100
|
+
abstracts.forEach((abstract) => {
|
|
101
|
+
const sec = createAbstractSection(abstract, createElement);
|
|
102
|
+
removeNodeFromParent(abstract);
|
|
103
|
+
group.appendChild(sec);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
export const createBoxedElementSection = (body, createElement) => {
|
|
107
|
+
const boxedTexts = body.querySelectorAll('boxed-text');
|
|
108
|
+
for (const boxedText of boxedTexts) {
|
|
109
|
+
const boxElementSec = createElement('sec');
|
|
110
|
+
boxElementSec.setAttribute('sec-type', 'box-element');
|
|
111
|
+
const title = createElement('title');
|
|
112
|
+
title.textContent = 'BoxElement';
|
|
113
|
+
boxElementSec.append(title);
|
|
114
|
+
for (const element of [...boxedText.children]) {
|
|
115
|
+
if ((element === null || element === void 0 ? void 0 : element.tagName) === 'label' || (element === null || element === void 0 ? void 0 : element.tagName) === 'caption') {
|
|
116
|
+
boxElementSec.append(element);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const containerSection = createElement('sec');
|
|
120
|
+
containerSection.append(...boxedText.children);
|
|
121
|
+
boxElementSec.append(containerSection);
|
|
122
|
+
boxedText.replaceWith(boxElementSec);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
export const createBody = (doc, body, createElement) => {
|
|
126
|
+
const group = createSectionGroup(bodyType, createElement);
|
|
127
|
+
const sections = doc.querySelectorAll('body > sec:not([sec-type="backmatter"]), body > sec:not([sec-type])');
|
|
128
|
+
sections.forEach((section) => {
|
|
129
|
+
removeNodeFromParent(section);
|
|
130
|
+
group.appendChild(section);
|
|
131
|
+
});
|
|
132
|
+
moveFloatsGroupToBody(doc, group, createElement);
|
|
133
|
+
body.append(group);
|
|
134
|
+
};
|
|
135
|
+
export const createAbstracts = (doc, body, createElement) => {
|
|
136
|
+
const group = createSectionGroup(abstractsType, createElement);
|
|
137
|
+
moveAbstracts(doc, group, createElement);
|
|
138
|
+
body.insertBefore(group, body.lastElementChild);
|
|
139
|
+
};
|
|
140
|
+
export const createBackmatter = (doc, body, createElement) => {
|
|
141
|
+
const group = createSectionGroup(backmatterType, createElement);
|
|
142
|
+
moveBackSections(doc, group);
|
|
143
|
+
moveAppendices(doc, group, createElement);
|
|
144
|
+
moveSpecialFootnotes(doc, group, createElement);
|
|
145
|
+
moveFootnotes(doc, group, createElement);
|
|
146
|
+
moveAcknowledgments(doc, group, createElement);
|
|
147
|
+
body.append(group);
|
|
148
|
+
};
|
|
149
|
+
const moveFootnotes = (doc, group, createElement) => {
|
|
150
|
+
var _a;
|
|
151
|
+
const fns = [
|
|
152
|
+
...doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'),
|
|
153
|
+
];
|
|
154
|
+
let section = doc.querySelector('sec[sec-type="endnotes"]');
|
|
155
|
+
const fnGroup = (section === null || section === void 0 ? void 0 : section.querySelector('fn-group')) || createElement('fn-group');
|
|
156
|
+
fns.forEach((fn) => {
|
|
157
|
+
if (!fn.getAttribute('fn-type')) {
|
|
158
|
+
fnGroup.appendChild(fn);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
if (!section && fnGroup.innerHTML) {
|
|
162
|
+
section = createFootnotesSection([fnGroup], createElement);
|
|
163
|
+
}
|
|
164
|
+
if (section) {
|
|
165
|
+
group.insertBefore(section, ((_a = group.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling) || group.firstChild);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const moveSpecialFootnotes = (doc, group, createElement) => {
|
|
169
|
+
var _a;
|
|
170
|
+
const fns = [...doc.querySelectorAll('fn[fn-type]')];
|
|
171
|
+
for (const fn of fns) {
|
|
172
|
+
const type = fn.getAttribute('fn-type') || '';
|
|
173
|
+
const category = chooseSectionCategoryByType(type);
|
|
174
|
+
if (category) {
|
|
175
|
+
const section = createElement('sec');
|
|
176
|
+
const fnTitle = fn.querySelector('p[content-type="fn-title"]');
|
|
177
|
+
if (fnTitle) {
|
|
178
|
+
const title = createElement('title');
|
|
179
|
+
const titleText = (_a = fnTitle.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
180
|
+
if (titleText) {
|
|
181
|
+
title.textContent = titleText;
|
|
182
|
+
}
|
|
183
|
+
removeNodeFromParent(fnTitle);
|
|
184
|
+
section.append(title);
|
|
185
|
+
}
|
|
186
|
+
section.append(...fn.children);
|
|
187
|
+
removeNodeFromParent(fn);
|
|
188
|
+
section.setAttribute('sec-type', chooseSecType(category));
|
|
189
|
+
group.append(section);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
export const moveCaptionsToEnd = (body) => {
|
|
194
|
+
const captions = body.querySelectorAll('caption');
|
|
195
|
+
for (const caption of captions) {
|
|
196
|
+
if (caption.parentNode &&
|
|
197
|
+
caption.parentNode.nodeName !== 'table-wrap' &&
|
|
198
|
+
caption.parentNode.nodeName !== 'boxed-text') {
|
|
199
|
+
caption.parentNode.appendChild(caption);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
const createAbstractSection = (abstract, createElement) => {
|
|
204
|
+
const abstractType = abstract.getAttribute('abstract-type');
|
|
205
|
+
const section = createElement('sec');
|
|
206
|
+
const sectionType = abstractType ? `abstract-${abstractType}` : 'abstract';
|
|
207
|
+
section.setAttribute('sec-type', sectionType);
|
|
208
|
+
if (!abstract.querySelector(':scope > title')) {
|
|
209
|
+
const title = createElement('title');
|
|
210
|
+
title.textContent = abstractType
|
|
211
|
+
? `${capitalizeFirstLetter(abstractType)} Abstract`
|
|
212
|
+
: 'Abstract';
|
|
213
|
+
section.appendChild(title);
|
|
214
|
+
}
|
|
215
|
+
while (abstract.firstChild) {
|
|
216
|
+
section.appendChild(abstract.firstChild);
|
|
217
|
+
}
|
|
218
|
+
return section;
|
|
219
|
+
};
|
|
220
|
+
const createAcknowledgmentsSection = (ack, createElement) => {
|
|
221
|
+
const section = createElement('sec');
|
|
222
|
+
section.setAttribute('sec-type', 'acknowledgments');
|
|
223
|
+
if (!ack.querySelector('title')) {
|
|
224
|
+
const title = createElement('title');
|
|
225
|
+
title.textContent = 'Acknowledgements';
|
|
226
|
+
section.appendChild(title);
|
|
227
|
+
}
|
|
228
|
+
while (ack.firstChild) {
|
|
229
|
+
section.appendChild(ack.firstChild);
|
|
230
|
+
}
|
|
231
|
+
return section;
|
|
232
|
+
};
|
|
233
|
+
const createFootnotesSection = (fnGroups, createElement) => {
|
|
234
|
+
const section = createElement('sec');
|
|
235
|
+
section.setAttribute('sec-type', 'endnotes');
|
|
236
|
+
const titleNode = fnGroups
|
|
237
|
+
.map((g) => g.querySelector('title'))
|
|
238
|
+
.filter((t) => t !== null)[0];
|
|
239
|
+
if (titleNode) {
|
|
240
|
+
section.appendChild(titleNode);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
const title = createElement('title');
|
|
244
|
+
title.textContent = 'Footnotes';
|
|
245
|
+
section.appendChild(title);
|
|
246
|
+
}
|
|
247
|
+
for (const fnGroup of fnGroups) {
|
|
248
|
+
section.appendChild(fnGroup);
|
|
249
|
+
}
|
|
250
|
+
return section;
|
|
251
|
+
};
|
|
252
|
+
const createAppendicesSection = (app, createElement) => {
|
|
253
|
+
const section = createElement('sec');
|
|
254
|
+
section.setAttribute('sec-type', 'appendices');
|
|
255
|
+
section.append(...app.children);
|
|
256
|
+
return section;
|
|
257
|
+
};
|
|
258
|
+
const createFloatsGroupSection = (floatsGroup, createElement) => {
|
|
259
|
+
const section = createElement('sec');
|
|
260
|
+
section.setAttribute('sec-type', 'floating-element');
|
|
261
|
+
const title = createElement('title');
|
|
262
|
+
title.textContent = 'Floating Group';
|
|
263
|
+
section.appendChild(title);
|
|
264
|
+
section.append(...floatsGroup.children);
|
|
265
|
+
return section;
|
|
266
|
+
};
|
|
267
|
+
const moveBackSections = (doc, group) => {
|
|
268
|
+
for (const section of doc.querySelectorAll('back > sec')) {
|
|
269
|
+
removeNodeFromParent(section);
|
|
270
|
+
group.appendChild(section);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const moveAcknowledgments = (doc, group, createElement) => {
|
|
274
|
+
const ack = doc.querySelector('back > ack');
|
|
275
|
+
if (ack) {
|
|
276
|
+
const section = createAcknowledgmentsSection(ack, createElement);
|
|
277
|
+
removeNodeFromParent(ack);
|
|
278
|
+
group.appendChild(section);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const moveAppendices = (doc, group, createElement) => {
|
|
282
|
+
const apps = doc.querySelectorAll('back > app-group > app');
|
|
283
|
+
for (const app of apps) {
|
|
284
|
+
const section = createAppendicesSection(app, createElement);
|
|
285
|
+
removeNodeFromParent(app);
|
|
286
|
+
group.appendChild(section);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const moveFloatsGroupToBody = (doc, body, createElement) => {
|
|
290
|
+
const floatsGroup = doc.querySelector('floats-group');
|
|
291
|
+
if (floatsGroup) {
|
|
292
|
+
const sec = createFloatsGroupSection(floatsGroup, createElement);
|
|
293
|
+
removeNodeFromParent(floatsGroup);
|
|
294
|
+
body.appendChild(sec);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
export const createKeywordsSection = (document, body, createElement) => {
|
|
298
|
+
const kwdGroups = [...document.querySelectorAll('kwd-group')];
|
|
299
|
+
if (kwdGroups.length > 0) {
|
|
300
|
+
const section = createElement('sec');
|
|
301
|
+
section.setAttribute('sec-type', 'keywords');
|
|
302
|
+
const title = createElement('title');
|
|
303
|
+
title.textContent = 'Keywords';
|
|
304
|
+
section.append(title);
|
|
305
|
+
const kwdGroupList = createElement('kwd-group-list');
|
|
306
|
+
kwdGroupList.append(kwdGroups[0]);
|
|
307
|
+
section.append(kwdGroupList);
|
|
308
|
+
body.prepend(section);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
export const createSupplementaryMaterialsSection = (document, body, createElement) => {
|
|
312
|
+
const suppls = [
|
|
313
|
+
...document.querySelectorAll('article-meta > supplementary-material'),
|
|
314
|
+
];
|
|
315
|
+
if (suppls.length) {
|
|
316
|
+
const section = createElement('sec');
|
|
317
|
+
section.setAttribute('sec-type', 'supplementary-material');
|
|
318
|
+
const title = createElement('title');
|
|
319
|
+
title.textContent = 'Supplementary Material';
|
|
320
|
+
section.append(title);
|
|
321
|
+
section.append(...suppls);
|
|
322
|
+
body.prepend(section);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
export const moveReferencesToBackmatter = (body, back, createElement) => {
|
|
326
|
+
const backmatter = body.querySelector('sec[sec-type="backmatter"]');
|
|
327
|
+
const refList = back.querySelector('ref-list');
|
|
328
|
+
if (!backmatter || !refList) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
removeNodeFromParent(refList);
|
|
332
|
+
const section = createElement('sec');
|
|
333
|
+
section.setAttribute('sec-type', 'bibliography');
|
|
334
|
+
const title = createElement('title');
|
|
335
|
+
title.textContent = 'References';
|
|
336
|
+
section.appendChild(title);
|
|
337
|
+
section.appendChild(refList);
|
|
338
|
+
backmatter.appendChild(section);
|
|
339
|
+
};
|
|
340
|
+
export const orderTableFootnote = (doc, body) => {
|
|
341
|
+
const rids = new Set([...body.querySelectorAll('tbody > xref[ref-type="fn"]')].map((xref) => xref.getAttribute('rid')));
|
|
342
|
+
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
343
|
+
fnGroups.forEach((fnGroup) => {
|
|
344
|
+
const fns = [...fnGroup.querySelectorAll('fn')].sort((fn) => rids.has(fn.getAttribute('id')) ? -1 : 0);
|
|
345
|
+
fnGroup.replaceChildren(...fns);
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
export const fixTables = (doc, body, createElement) => {
|
|
349
|
+
const tableWraps = body.querySelectorAll('table-wrap');
|
|
350
|
+
tableWraps.forEach((tableWrap) => {
|
|
351
|
+
const table = tableWrap.querySelector('table');
|
|
352
|
+
if (!table) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const colgroup = table.querySelector('colgroup');
|
|
356
|
+
const cols = table.querySelectorAll('col');
|
|
357
|
+
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
358
|
+
const colgroup = createElement('colgroup');
|
|
359
|
+
for (const col of cols) {
|
|
360
|
+
colgroup.appendChild(col);
|
|
361
|
+
}
|
|
362
|
+
tableWrap.insertBefore(colgroup, table.nextSibling);
|
|
363
|
+
}
|
|
364
|
+
const tableFootWrap = tableWrap.querySelector('table-wrap-foot');
|
|
365
|
+
if (tableFootWrap) {
|
|
366
|
+
const paragraphs = tableFootWrap.querySelectorAll(':scope > p');
|
|
367
|
+
if (paragraphs.length) {
|
|
368
|
+
const generalTableFootnote = createElement('general-table-footnote');
|
|
369
|
+
for (const paragraph of paragraphs) {
|
|
370
|
+
removeNodeFromParent(paragraph);
|
|
371
|
+
generalTableFootnote.append(paragraph);
|
|
372
|
+
}
|
|
373
|
+
tableFootWrap.prepend(generalTableFootnote);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
};
|
|
@@ -13,112 +13,57 @@
|
|
|
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
|
-
import {
|
|
19
|
-
import { generateID } from '../../transformer/id';
|
|
20
|
-
import { findManuscript } from '../../transformer/project-bundle';
|
|
21
|
-
import { jatsBodyDOMParser } from './jats-body-dom-parser';
|
|
22
|
-
import { jatsBodyTransformations } from './jats-body-transformations';
|
|
23
|
-
import { createComments, createReferenceComments, markComments, } from './jats-comments';
|
|
24
|
-
import { jatsFrontParser } from './jats-front-parser';
|
|
16
|
+
import { markComments } from './jats-comments';
|
|
17
|
+
import { jatsDOMParser } from './jats-dom-parser';
|
|
18
|
+
import { parseJournal } from './jats-journal-meta-parser';
|
|
25
19
|
import { updateDocumentIDs } from './jats-parser-utils';
|
|
26
|
-
import {
|
|
27
|
-
|
|
20
|
+
import { createAbstracts, createBackmatter, createBody, createBoxedElementSection, createKeywordsSection, createSupplementaryMaterialsSection, ensureSection, fixTables, moveAffiliations, moveAuthorNotes, moveAwards, moveCaptionsToEnd, moveContributors, moveReferencesToBackmatter, moveTitle, orderTableFootnote, } from './jats-transformations';
|
|
21
|
+
const processJATS = (doc) => {
|
|
28
22
|
const createElement = createElementFn(doc);
|
|
29
|
-
|
|
30
|
-
const titles = jatsFrontParser.parseTitles(front.querySelector('article-meta > title-group'), createElement);
|
|
31
|
-
const DOI = jatsFrontParser.parseDOI(front);
|
|
32
|
-
const { affiliations, affiliationIDs } = jatsFrontParser.parseAffiliations([
|
|
33
|
-
...front.querySelectorAll('article-meta > contrib-group > aff'),
|
|
34
|
-
]);
|
|
35
|
-
const { footnotes, footnoteIDs, authorNotes, authorNotesParagraphs, correspondingIDs, correspondingList, } = jatsFrontParser.parseAuthorNotes(front.querySelector('article-meta > author-notes'));
|
|
36
|
-
const authors = jatsFrontParser.parseContributors([
|
|
37
|
-
...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
|
|
38
|
-
], affiliationIDs, footnoteIDs, correspondingIDs);
|
|
39
|
-
const history = jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
|
|
40
|
-
const counts = jatsFrontParser.parseCounts(front.querySelector('article-meta counts'));
|
|
41
|
-
const manuscript = Object.assign(Object.assign(Object.assign(Object.assign({}, buildManuscript()), counts), history), { DOI });
|
|
42
|
-
return generateIDs([
|
|
43
|
-
manuscript,
|
|
44
|
-
titles,
|
|
45
|
-
journal,
|
|
46
|
-
...authorNotesParagraphs,
|
|
47
|
-
...authorNotes,
|
|
48
|
-
...footnotes,
|
|
49
|
-
...authors,
|
|
50
|
-
...affiliations,
|
|
51
|
-
...correspondingList,
|
|
52
|
-
]);
|
|
53
|
-
};
|
|
54
|
-
export const parseJATSBody = (doc, body, references) => {
|
|
55
|
-
const createElement = createElementFn(doc);
|
|
56
|
-
jatsBodyTransformations.ensureSection(body, createElement);
|
|
57
|
-
jatsBodyTransformations.moveCaptionsToEnd(body);
|
|
58
|
-
jatsBodyTransformations.fixTables(body, createElement);
|
|
59
|
-
jatsBodyTransformations.createBoxedElementSection(doc, body, createElement);
|
|
60
|
-
jatsBodyTransformations.createBody(doc, body, createElement);
|
|
61
|
-
jatsBodyTransformations.createAbstracts(doc, body, createElement);
|
|
62
|
-
jatsBodyTransformations.createBackmatter(doc, body, createElement);
|
|
63
|
-
jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
|
|
64
|
-
jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
65
|
-
jatsBodyTransformations.orderTableFootnote(doc, body);
|
|
66
|
-
const node = jatsBodyDOMParser.parse(body).firstChild;
|
|
67
|
-
if (!node) {
|
|
68
|
-
throw new Error('No content was parsed from the JATS article body');
|
|
69
|
-
}
|
|
70
|
-
const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
|
|
71
|
-
updateDocumentIDs(node, replacements);
|
|
72
|
-
return encode(node).values();
|
|
73
|
-
};
|
|
74
|
-
const createBibliographyModels = (references) => {
|
|
75
|
-
const models = [];
|
|
76
|
-
const bibliographyItems = references.getBibliographyItems();
|
|
77
|
-
const bibliographyElement = buildBibliographyElement(bibliographyItems);
|
|
78
|
-
const bibliographySection = Object.assign(Object.assign({}, buildSection(99)), { category: 'MPSectionCategory:bibliography', elementIDs: [bibliographyElement._id], title: 'References' });
|
|
79
|
-
const comments = createReferenceComments(references);
|
|
80
|
-
models.push(bibliographySection);
|
|
81
|
-
models.push(bibliographyElement);
|
|
82
|
-
models.push(...bibliographyItems);
|
|
83
|
-
models.push(...comments);
|
|
84
|
-
return models;
|
|
85
|
-
};
|
|
86
|
-
const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
|
|
87
|
-
const generateIDs = (models) => models.map((m) => m._id ? m : Object.assign(Object.assign({}, m), { _id: generateID(m.objectType) }));
|
|
88
|
-
export const parseJATSArticle = (doc) => {
|
|
89
|
-
const article = doc.querySelector('article');
|
|
23
|
+
markComments(doc);
|
|
90
24
|
const front = doc.querySelector('front');
|
|
91
|
-
const body = doc.querySelector('body');
|
|
92
|
-
const back = doc.querySelector('back');
|
|
93
25
|
if (!front) {
|
|
94
|
-
|
|
26
|
+
return;
|
|
95
27
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
references = jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
|
|
105
|
-
}
|
|
106
|
-
models.push(...parseJATSFront(doc, front));
|
|
107
|
-
if (body) {
|
|
108
|
-
models.push(...parseJATSBody(doc, body, references));
|
|
28
|
+
moveTitle(front, createElement);
|
|
29
|
+
moveContributors(front, createElement);
|
|
30
|
+
moveAffiliations(front, createElement);
|
|
31
|
+
moveAuthorNotes(front, createElement);
|
|
32
|
+
moveAwards(front);
|
|
33
|
+
const body = doc.querySelector('body');
|
|
34
|
+
if (!body) {
|
|
35
|
+
return;
|
|
109
36
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
37
|
+
ensureSection(body, createElement);
|
|
38
|
+
moveCaptionsToEnd(body);
|
|
39
|
+
createBoxedElementSection(body, createElement);
|
|
40
|
+
createBody(doc, body, createElement);
|
|
41
|
+
createAbstracts(doc, body, createElement);
|
|
42
|
+
createBackmatter(doc, body, createElement);
|
|
43
|
+
createSupplementaryMaterialsSection(doc, body, createElement);
|
|
44
|
+
createKeywordsSection(doc, body, createElement);
|
|
45
|
+
fixTables(doc, body, createElement);
|
|
46
|
+
orderTableFootnote(doc, body);
|
|
47
|
+
const back = doc.querySelector('back');
|
|
48
|
+
if (!back) {
|
|
49
|
+
return;
|
|
115
50
|
}
|
|
116
|
-
|
|
117
|
-
|
|
51
|
+
moveReferencesToBackmatter(body, back, createElement);
|
|
52
|
+
};
|
|
53
|
+
const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
|
|
54
|
+
export const parseJATSArticle = (doc, template) => {
|
|
55
|
+
const journal = parseJournal(doc);
|
|
56
|
+
processJATS(doc);
|
|
57
|
+
const node = jatsDOMParser.parse(doc).firstChild;
|
|
58
|
+
if (!node) {
|
|
59
|
+
throw new Error('No content was parsed from the JATS article body');
|
|
118
60
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
61
|
+
updateDocumentIDs(node);
|
|
62
|
+
if (template) {
|
|
63
|
+
node.attrs.prototype = template;
|
|
122
64
|
}
|
|
123
|
-
return
|
|
65
|
+
return {
|
|
66
|
+
node,
|
|
67
|
+
journal,
|
|
68
|
+
};
|
|
124
69
|
};
|
package/dist/es/jats/index.js
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export
|
|
17
|
-
export * from './jats-
|
|
18
|
-
export * from './
|
|
16
|
+
export * from './exporter/jats-exporter';
|
|
17
|
+
export * from './exporter/jats-versions';
|
|
18
|
+
export * from './exporter/labels';
|
|
19
|
+
export * from './importer/create-article-node';
|
|
20
|
+
export { parseJATSArticle } from './importer/parse-jats-article';
|