@manuscripts/transform 2.3.32 → 2.3.34-LEAN-3911.2
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/jats/importer/create-article-node.js +31 -0
- package/dist/cjs/jats/importer/index.js +3 -3
- package/dist/cjs/jats/importer/jats-body-transformations.js +70 -0
- package/dist/cjs/jats/importer/jats-comments.js +27 -104
- package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +229 -9
- package/dist/cjs/jats/importer/jats-front-transformations.js +262 -0
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
- package/dist/cjs/jats/importer/jats-parser-utils.js +39 -5
- package/dist/cjs/jats/importer/jats-reference-parser.js +16 -27
- package/dist/cjs/jats/importer/jats-references.js +18 -18
- package/dist/cjs/jats/importer/parse-jats-article.js +42 -78
- package/dist/cjs/jats/index.js +4 -3
- package/dist/cjs/jats/jats-exporter.js +251 -354
- package/dist/cjs/{transformer → jats}/labels.js +3 -3
- package/dist/cjs/lib/utils.js +9 -1
- package/dist/cjs/schema/nodes/footnotes_section.js +1 -1
- package/dist/cjs/transformer/id.js +6 -6
- package/dist/cjs/transformer/index.js +0 -18
- package/dist/cjs/version.js +1 -1
- package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
- package/dist/es/jats/importer/index.js +2 -1
- package/dist/es/jats/importer/jats-body-transformations.js +70 -0
- package/dist/es/jats/importer/jats-comments.js +26 -101
- package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
- package/dist/es/jats/importer/jats-front-transformations.js +259 -0
- package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
- package/dist/es/jats/importer/jats-parser-utils.js +40 -6
- package/dist/es/jats/importer/jats-reference-parser.js +16 -27
- package/dist/es/jats/importer/jats-references.js +18 -18
- package/dist/es/jats/importer/parse-jats-article.js +43 -77
- package/dist/es/jats/index.js +3 -1
- package/dist/es/jats/jats-exporter.js +253 -356
- package/dist/es/{transformer → jats}/labels.js +3 -3
- package/dist/es/lib/utils.js +7 -0
- package/dist/es/schema/nodes/footnotes_section.js +1 -1
- package/dist/es/transformer/id.js +5 -4
- package/dist/es/transformer/index.js +0 -16
- package/dist/es/version.js +1 -1
- package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
- package/dist/types/jats/importer/index.d.ts +2 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
- package/dist/types/jats/importer/jats-comments.d.ts +4 -10
- package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
- package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
- package/dist/types/jats/importer/jats-references.d.ts +19 -8
- package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
- package/dist/types/jats/index.d.ts +3 -1
- package/dist/types/jats/jats-exporter.d.ts +10 -29
- package/dist/types/{transformer → jats}/labels.d.ts +2 -1
- package/dist/types/lib/utils.d.ts +3 -0
- package/dist/types/schema/nodes/bibliography_item.d.ts +16 -6
- package/dist/types/schema/nodes/contributor.d.ts +10 -0
- package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
- package/dist/types/transformer/id.d.ts +4 -3
- package/dist/types/transformer/index.d.ts +0 -16
- package/dist/types/version.d.ts +1 -1
- package/package.json +3 -2
- package/dist/cjs/__tests__/data/project-dump.json +0 -825
- package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
- 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 -874
- package/dist/cjs/transformer/document-object-types.js +0 -31
- package/dist/cjs/transformer/encode.js +0 -664
- 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/model-map.js +0 -26
- package/dist/cjs/transformer/object-types.js +0 -57
- package/dist/cjs/transformer/project-bundle.js +0 -94
- package/dist/cjs/transformer/update-identifiers.js +0 -93
- package/dist/es/__tests__/data/project-dump.json +0 -825
- package/dist/es/jats/importer/jats-front-parser.js +0 -315
- 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 -864
- package/dist/es/transformer/document-object-types.js +0 -28
- package/dist/es/transformer/encode.js +0 -654
- package/dist/es/transformer/footnote-category.js +0 -16
- 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/models.js +0 -16
- 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/update-identifiers.js +0 -87
- package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
- 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 -51
- package/dist/types/transformer/document-object-types.d.ts +0 -17
- package/dist/types/transformer/encode.d.ts +0 -29
- 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/cjs/{transformer → jats}/filename.js +0 -0
- /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
- /package/dist/es/{transformer → jats}/filename.js +0 -0
- /package/dist/es/{transformer → jats}/timestamp.js +0 -0
- /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
- /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { ObjectTypes, timestamp, } from '@manuscripts/json-schema';
|
|
16
17
|
import mime from 'mime';
|
|
17
18
|
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
18
|
-
import { schema } from '../../schema';
|
|
19
|
-
import { chooseSectionCategory } from '../../transformer';
|
|
19
|
+
import { schema, } from '../../schema';
|
|
20
|
+
import { chooseSectionCategory, generateID } from '../../transformer';
|
|
21
|
+
import { DEFAULT_PROFILE_ID } from './jats-comments';
|
|
20
22
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
21
23
|
const chooseContentType = (graphicNode) => {
|
|
22
24
|
if (graphicNode) {
|
|
@@ -31,6 +33,12 @@ const chooseContentType = (graphicNode) => {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
};
|
|
36
|
+
const parsePriority = (priority) => {
|
|
37
|
+
if (!priority) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return parseInt(priority);
|
|
41
|
+
};
|
|
34
42
|
const getEquationContent = (p) => {
|
|
35
43
|
var _a;
|
|
36
44
|
const element = p;
|
|
@@ -95,6 +103,174 @@ const marks = [
|
|
|
95
103
|
},
|
|
96
104
|
];
|
|
97
105
|
const nodes = [
|
|
106
|
+
{
|
|
107
|
+
tag: 'article',
|
|
108
|
+
node: 'manuscript',
|
|
109
|
+
getAttrs: (node) => {
|
|
110
|
+
const element = node;
|
|
111
|
+
return {
|
|
112
|
+
doi: element.getAttribute('DOI'),
|
|
113
|
+
articleType: element.getAttribute('article-type') || '',
|
|
114
|
+
prototype: element.getAttribute('prototype') || '',
|
|
115
|
+
primaryLanguageCode: element.getAttribute('primary-language-code') || '',
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
tag: 'article-title',
|
|
121
|
+
node: 'title',
|
|
122
|
+
getAttrs: (node) => {
|
|
123
|
+
const element = node;
|
|
124
|
+
return {
|
|
125
|
+
id: element.getAttribute('id'),
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
tag: 'highlight-marker',
|
|
131
|
+
node: 'highlight_marker',
|
|
132
|
+
getAttrs: (node) => {
|
|
133
|
+
var _a;
|
|
134
|
+
const element = node;
|
|
135
|
+
const id = element.getAttribute('id');
|
|
136
|
+
return {
|
|
137
|
+
id: id,
|
|
138
|
+
position: (_a = element.getAttribute('position')) !== null && _a !== void 0 ? _a : '',
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
tag: 'comment-annotation',
|
|
144
|
+
node: 'comment',
|
|
145
|
+
getAttrs: (node) => {
|
|
146
|
+
const element = node;
|
|
147
|
+
return {
|
|
148
|
+
id: element.getAttribute('id'),
|
|
149
|
+
contents: element.textContent,
|
|
150
|
+
contributions: [
|
|
151
|
+
{
|
|
152
|
+
_id: generateID(ObjectTypes.Contribution),
|
|
153
|
+
objecType: ObjectTypes.Contribution,
|
|
154
|
+
profileID: DEFAULT_PROFILE_ID,
|
|
155
|
+
timestamp: timestamp(),
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
tag: 'author-notes',
|
|
163
|
+
node: 'author_notes',
|
|
164
|
+
getAttrs: (node) => {
|
|
165
|
+
const element = node;
|
|
166
|
+
return {
|
|
167
|
+
id: element.getAttribute('id'),
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
tag: 'fn-author',
|
|
173
|
+
node: 'footnote',
|
|
174
|
+
getAttrs: (node) => {
|
|
175
|
+
const element = node;
|
|
176
|
+
return {
|
|
177
|
+
id: element.getAttribute('id'),
|
|
178
|
+
kind: 'footnote',
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
tag: 'corresp',
|
|
184
|
+
node: 'corresp',
|
|
185
|
+
getAttrs: (node) => {
|
|
186
|
+
const element = node;
|
|
187
|
+
return {
|
|
188
|
+
id: element.getAttribute('id'),
|
|
189
|
+
label: element.getAttribute('label'),
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
tag: 'contributor',
|
|
195
|
+
node: 'contributor',
|
|
196
|
+
getAttrs: (node) => {
|
|
197
|
+
const element = node;
|
|
198
|
+
const footnote = [];
|
|
199
|
+
const affiliations = [];
|
|
200
|
+
const corresp = [];
|
|
201
|
+
element.querySelectorAll('fn').forEach((fn) => {
|
|
202
|
+
const noteID = fn.getAttribute('noteID');
|
|
203
|
+
const noteLabel = fn.getAttribute('noteLabel');
|
|
204
|
+
if (noteID && noteLabel) {
|
|
205
|
+
footnote.push({ noteID, noteLabel });
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
element.querySelectorAll('corresp').forEach((correspondence) => {
|
|
209
|
+
const correspLabel = correspondence.getAttribute('correspLabel');
|
|
210
|
+
const correspID = correspondence.getAttribute('correspID');
|
|
211
|
+
if (correspID && correspLabel) {
|
|
212
|
+
corresp.push({ correspID, correspLabel });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
element.querySelectorAll('aff').forEach((aff) => {
|
|
216
|
+
const affID = aff.getAttribute('affiliationID');
|
|
217
|
+
if (affID) {
|
|
218
|
+
affiliations.push(affID);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
const isCorrespondingEl = element.getAttribute('isCorresponding');
|
|
222
|
+
return {
|
|
223
|
+
id: element.getAttribute('id'),
|
|
224
|
+
role: 'author',
|
|
225
|
+
isCorresponding: isCorrespondingEl
|
|
226
|
+
? isCorrespondingEl === 'true'
|
|
227
|
+
: undefined,
|
|
228
|
+
bibliographicName: {
|
|
229
|
+
given: element.getAttribute('given'),
|
|
230
|
+
family: element.getAttribute('family'),
|
|
231
|
+
ObjectType: 'MPBibliographicName',
|
|
232
|
+
_id: generateID(ObjectTypes.BibliographicName),
|
|
233
|
+
},
|
|
234
|
+
affiliations,
|
|
235
|
+
corresp: corresp.length ? corresp : undefined,
|
|
236
|
+
footnote: footnote.length ? footnote : undefined,
|
|
237
|
+
ORCIDIdentifier: element.getAttribute('ORCIDIdentifier'),
|
|
238
|
+
priority: parsePriority(element.getAttribute('priority')),
|
|
239
|
+
};
|
|
240
|
+
},
|
|
241
|
+
getContent: () => {
|
|
242
|
+
return Fragment.from(schema.text('_'));
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
tag: 'affiliation',
|
|
247
|
+
node: 'affiliation',
|
|
248
|
+
getAttrs: (node) => {
|
|
249
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
250
|
+
const element = node;
|
|
251
|
+
const emailEl = element.querySelector('email');
|
|
252
|
+
return {
|
|
253
|
+
id: element.getAttribute('id'),
|
|
254
|
+
institution: (_a = element.getAttribute('institution')) !== null && _a !== void 0 ? _a : '',
|
|
255
|
+
department: (_b = element.getAttribute('department')) !== null && _b !== void 0 ? _b : '',
|
|
256
|
+
addressLine1: (_c = element.getAttribute('addressLine1')) !== null && _c !== void 0 ? _c : '',
|
|
257
|
+
addressLine2: (_d = element.getAttribute('addressLine2')) !== null && _d !== void 0 ? _d : '',
|
|
258
|
+
addressLine3: (_e = element.getAttribute('addressLine3')) !== null && _e !== void 0 ? _e : '',
|
|
259
|
+
postCode: (_f = element.getAttribute('postCode')) !== null && _f !== void 0 ? _f : '',
|
|
260
|
+
country: (_g = element.getAttribute('country')) !== null && _g !== void 0 ? _g : '',
|
|
261
|
+
email: emailEl
|
|
262
|
+
? {
|
|
263
|
+
href: (_h = emailEl.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _h !== void 0 ? _h : '',
|
|
264
|
+
text: (_k = (_j = emailEl.textContent) === null || _j === void 0 ? void 0 : _j.trim()) !== null && _k !== void 0 ? _k : '',
|
|
265
|
+
}
|
|
266
|
+
: undefined,
|
|
267
|
+
priority: parsePriority(element.getAttribute('priority')),
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
getContent: () => {
|
|
271
|
+
return Fragment.from(schema.text('_'));
|
|
272
|
+
},
|
|
273
|
+
},
|
|
98
274
|
{
|
|
99
275
|
tag: 'attrib',
|
|
100
276
|
node: 'attribution',
|
|
@@ -103,10 +279,6 @@ const nodes = [
|
|
|
103
279
|
tag: 'back',
|
|
104
280
|
ignore: true,
|
|
105
281
|
},
|
|
106
|
-
{
|
|
107
|
-
tag: 'body',
|
|
108
|
-
node: 'manuscript',
|
|
109
|
-
},
|
|
110
282
|
{
|
|
111
283
|
tag: 'break',
|
|
112
284
|
node: 'hard_break',
|
|
@@ -126,13 +298,13 @@ const nodes = [
|
|
|
126
298
|
const title = element.querySelector('title');
|
|
127
299
|
if (title) {
|
|
128
300
|
const captionTitle = schema.nodes.caption_title.create();
|
|
129
|
-
content.push(
|
|
301
|
+
content.push(jatsDOMParser.parse(title, { topNode: captionTitle }));
|
|
130
302
|
}
|
|
131
303
|
const paragraphs = element.querySelectorAll('p');
|
|
132
304
|
if (paragraphs.length) {
|
|
133
305
|
const figcaption = schema.nodes.caption.create();
|
|
134
306
|
for (const paragraph of paragraphs) {
|
|
135
|
-
content.push(
|
|
307
|
+
content.push(jatsDOMParser.parse(paragraph, { topNode: figcaption }));
|
|
136
308
|
}
|
|
137
309
|
}
|
|
138
310
|
return Fragment.from(content);
|
|
@@ -323,7 +495,7 @@ const nodes = [
|
|
|
323
495
|
const paragraphs = [];
|
|
324
496
|
node.childNodes.forEach((p) => {
|
|
325
497
|
const paragraph = schema.nodes.paragraph.create();
|
|
326
|
-
const content =
|
|
498
|
+
const content = jatsDOMParser.parse(p, {
|
|
327
499
|
topNode: paragraph,
|
|
328
500
|
});
|
|
329
501
|
paragraphs.push(content);
|
|
@@ -422,6 +594,54 @@ const nodes = [
|
|
|
422
594
|
tag: 'sec[sec-type="backmatter"]',
|
|
423
595
|
node: 'backmatter',
|
|
424
596
|
},
|
|
597
|
+
{
|
|
598
|
+
tag: 'bibliography-element',
|
|
599
|
+
node: 'bibliography_element',
|
|
600
|
+
getAttrs: (node) => {
|
|
601
|
+
const element = node;
|
|
602
|
+
return {
|
|
603
|
+
id: element.getAttribute('id'),
|
|
604
|
+
};
|
|
605
|
+
},
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
tag: 'bibliography-item',
|
|
609
|
+
node: 'bibliography_item',
|
|
610
|
+
getAttrs: (node) => {
|
|
611
|
+
const element = node;
|
|
612
|
+
const authors = [];
|
|
613
|
+
element.querySelectorAll('author').forEach((author) => {
|
|
614
|
+
authors.push({
|
|
615
|
+
_id: author.getAttribute('id') || '',
|
|
616
|
+
given: author.getAttribute('given') || '',
|
|
617
|
+
family: author.getAttribute('family') || '',
|
|
618
|
+
objectType: 'MPBibliographicName',
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
const issuedEl = element.querySelector('issued');
|
|
622
|
+
const issued = issuedEl
|
|
623
|
+
? {
|
|
624
|
+
objectType: 'MPBibliographicDate',
|
|
625
|
+
_id: issuedEl.getAttribute('id'),
|
|
626
|
+
'date-parts': [[issuedEl.getAttribute('year')]],
|
|
627
|
+
}
|
|
628
|
+
: undefined;
|
|
629
|
+
return {
|
|
630
|
+
id: element.getAttribute('id'),
|
|
631
|
+
type: element.getAttribute('type'),
|
|
632
|
+
containerTitle: element.getAttribute('container-title'),
|
|
633
|
+
volume: element.getAttribute('volume'),
|
|
634
|
+
issue: element.getAttribute('issue'),
|
|
635
|
+
supplement: element.getAttribute('supplement'),
|
|
636
|
+
page: element.getAttribute('page'),
|
|
637
|
+
title: element.getAttribute('title'),
|
|
638
|
+
literal: element.getAttribute('literal'),
|
|
639
|
+
author: authors,
|
|
640
|
+
issued,
|
|
641
|
+
DOI: element.getAttribute('DOI'),
|
|
642
|
+
};
|
|
643
|
+
},
|
|
644
|
+
},
|
|
425
645
|
{
|
|
426
646
|
tag: 'sec',
|
|
427
647
|
node: 'section',
|
|
@@ -574,4 +794,4 @@ const nodes = [
|
|
|
574
794
|
},
|
|
575
795
|
},
|
|
576
796
|
];
|
|
577
|
-
export const
|
|
797
|
+
export const jatsDOMParser = new DOMParser(schema, [...marks, ...nodes]);
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2024 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 { ObjectTypes } from '@manuscripts/json-schema';
|
|
17
|
+
import { getTrimmedTextContent } from '../../lib/utils';
|
|
18
|
+
import { generateID } from '../../transformer';
|
|
19
|
+
import { htmlFromJatsNode } from './jats-parser-utils';
|
|
20
|
+
export const defaultTitle = 'Untitled Manuscript';
|
|
21
|
+
export const jatsFrontTransformations = {
|
|
22
|
+
setArticleAttrs(doc, template) {
|
|
23
|
+
var _a;
|
|
24
|
+
const doi = (_a = doc.querySelector('article-meta > article-id[pub-id-type="doi"]')) === null || _a === void 0 ? void 0 : _a.textContent;
|
|
25
|
+
const Attrs = {
|
|
26
|
+
DOI: doi !== null && doi !== void 0 ? doi : '',
|
|
27
|
+
prototype: template !== null && template !== void 0 ? template : '',
|
|
28
|
+
id: generateID(ObjectTypes.Manuscript),
|
|
29
|
+
};
|
|
30
|
+
Object.entries(Attrs).forEach(([key, value]) => {
|
|
31
|
+
var _a;
|
|
32
|
+
if (value) {
|
|
33
|
+
(_a = doc.querySelector('article')) === null || _a === void 0 ? void 0 : _a.setAttribute(key, value);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
createTitle(front, createElement) {
|
|
38
|
+
var _a;
|
|
39
|
+
let title = front.querySelector('article-meta > title-group > article-title');
|
|
40
|
+
if (title) {
|
|
41
|
+
title.innerHTML = (_a = htmlFromJatsNode(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
title = createElement('article-title');
|
|
45
|
+
title.textContent = defaultTitle;
|
|
46
|
+
}
|
|
47
|
+
return title;
|
|
48
|
+
},
|
|
49
|
+
createAuthorNotes(document, createElement) {
|
|
50
|
+
const authornotes = document.querySelector('article-meta > author-notes');
|
|
51
|
+
if (!authornotes) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const authorNotesEl = createElement('author-notes');
|
|
55
|
+
authornotes
|
|
56
|
+
.querySelectorAll('fn:not([fn-type]), :scope > p, corresp')
|
|
57
|
+
.forEach((node) => {
|
|
58
|
+
switch (node.nodeName) {
|
|
59
|
+
case 'fn': {
|
|
60
|
+
this.appendFootnote(node, authorNotesEl, createElement);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'p': {
|
|
64
|
+
this.appendParagraph(document, node, authorNotesEl);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'corresp': {
|
|
68
|
+
this.appendCorresp(node, authorNotesEl, createElement);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return authorNotesEl;
|
|
74
|
+
},
|
|
75
|
+
appendFootnote(node, element, createElement) {
|
|
76
|
+
const fnEl = createElement('fn-author');
|
|
77
|
+
fnEl.innerHTML = node.innerHTML;
|
|
78
|
+
fnEl.setAttribute('kind', 'footnote');
|
|
79
|
+
const id = node.getAttribute('id');
|
|
80
|
+
if (id) {
|
|
81
|
+
fnEl.setAttribute('id', id);
|
|
82
|
+
}
|
|
83
|
+
element.append(fnEl);
|
|
84
|
+
},
|
|
85
|
+
appendParagraph(document, node, element) {
|
|
86
|
+
const pEl = document.createElementNS(null, 'p');
|
|
87
|
+
pEl.innerHTML = node.innerHTML;
|
|
88
|
+
element.append(pEl);
|
|
89
|
+
},
|
|
90
|
+
appendCorresp(node, element, createElement) {
|
|
91
|
+
var _a, _b;
|
|
92
|
+
const correspEl = createElement('corresp');
|
|
93
|
+
const label = node.querySelector('label');
|
|
94
|
+
if (label) {
|
|
95
|
+
label.remove();
|
|
96
|
+
}
|
|
97
|
+
correspEl.textContent = ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
|
|
98
|
+
correspEl.setAttribute('label', ((_b = label === null || label === void 0 ? void 0 : label.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '');
|
|
99
|
+
const id = node.getAttribute('id');
|
|
100
|
+
if (id) {
|
|
101
|
+
correspEl.setAttribute('id', id);
|
|
102
|
+
}
|
|
103
|
+
element.append(correspEl);
|
|
104
|
+
},
|
|
105
|
+
createContributors(front, createElement) {
|
|
106
|
+
const contribs = front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]');
|
|
107
|
+
const contributors = createElement('contributors');
|
|
108
|
+
contribs.forEach((element, priority) => {
|
|
109
|
+
const contributor = this.createContributorElement(priority, createElement);
|
|
110
|
+
this.setNameAttrs(element, contributor);
|
|
111
|
+
this.setOrcidAttribute(element, contributor);
|
|
112
|
+
this.setIsCorrespondingAttribute(element, contributor);
|
|
113
|
+
this.setContributorReferences(element, contributor, createElement);
|
|
114
|
+
contributors.append(contributor);
|
|
115
|
+
});
|
|
116
|
+
return contributors;
|
|
117
|
+
},
|
|
118
|
+
createContributorElement(priority, createElement) {
|
|
119
|
+
const contributor = createElement('contributor');
|
|
120
|
+
contributor.setAttribute('priority', priority.toString());
|
|
121
|
+
contributor.setAttribute('role', 'author');
|
|
122
|
+
return contributor;
|
|
123
|
+
},
|
|
124
|
+
setNameAttrs(node, element) {
|
|
125
|
+
const given = getTrimmedTextContent(node, 'name > given-names');
|
|
126
|
+
if (given) {
|
|
127
|
+
element.setAttribute('given', given);
|
|
128
|
+
}
|
|
129
|
+
const surname = getTrimmedTextContent(node, 'name > surname');
|
|
130
|
+
if (surname) {
|
|
131
|
+
element.setAttribute('family', surname);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
setOrcidAttribute(node, element) {
|
|
135
|
+
const orcid = getTrimmedTextContent(node, 'contrib-id[contrib-id-type="orcid"]');
|
|
136
|
+
if (orcid) {
|
|
137
|
+
element.setAttribute('ORCIDIdentifier', orcid);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
setIsCorrespondingAttribute(node, element) {
|
|
141
|
+
const isCorresponding = node.getAttribute('corresp') === 'yes';
|
|
142
|
+
if (isCorresponding) {
|
|
143
|
+
element.setAttribute('isCorresponding', isCorresponding.toString());
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
setContributorReferences(node, element, createElement) {
|
|
147
|
+
const xrefs = node.querySelectorAll('xref');
|
|
148
|
+
const footnotes = createElement('fns');
|
|
149
|
+
const corresps = createElement('corresps');
|
|
150
|
+
const affs = createElement('affs');
|
|
151
|
+
xrefs.forEach((xref) => {
|
|
152
|
+
const rid = xref.getAttribute('rid');
|
|
153
|
+
const type = xref.getAttribute('ref-type');
|
|
154
|
+
if (rid) {
|
|
155
|
+
switch (type) {
|
|
156
|
+
case 'fn':
|
|
157
|
+
this.appendFootnoteID(xref, footnotes, rid, createElement);
|
|
158
|
+
break;
|
|
159
|
+
case 'corresp':
|
|
160
|
+
this.appendCorrespID(xref, corresps, rid, createElement);
|
|
161
|
+
break;
|
|
162
|
+
case 'aff':
|
|
163
|
+
this.appendAffiliationID(affs, rid, createElement);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
element.append(footnotes, corresps, affs);
|
|
169
|
+
},
|
|
170
|
+
appendFootnoteID(xref, footnotes, rid, createElement) {
|
|
171
|
+
var _a;
|
|
172
|
+
const fn = createElement('fn');
|
|
173
|
+
fn.setAttribute('noteID', rid);
|
|
174
|
+
fn.setAttribute('noteLabel', ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
175
|
+
footnotes.append(fn);
|
|
176
|
+
},
|
|
177
|
+
appendCorrespID(xref, corresps, rid, createElement) {
|
|
178
|
+
var _a;
|
|
179
|
+
const corresp = createElement('corresp');
|
|
180
|
+
corresp.setAttribute('correspID', rid);
|
|
181
|
+
corresp.setAttribute('correspLabel', ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
182
|
+
corresps.append(corresp);
|
|
183
|
+
},
|
|
184
|
+
appendAffiliationID(affs, rid, createElement) {
|
|
185
|
+
const rids = rid.split(/\s+/).filter(Boolean);
|
|
186
|
+
if (rids.length) {
|
|
187
|
+
rids.forEach((affID) => {
|
|
188
|
+
const aff = createElement('aff');
|
|
189
|
+
aff.setAttribute('affiliationID', affID);
|
|
190
|
+
affs.append(aff);
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
createAffiliations(front, createElement) {
|
|
195
|
+
const affiliations = front.querySelectorAll('article-meta > contrib-group > aff');
|
|
196
|
+
const affiliationGroup = createElement('affiliations');
|
|
197
|
+
affiliations.forEach((element, priority) => {
|
|
198
|
+
const affiliation = this.createAffiliationElement(element, priority, createElement);
|
|
199
|
+
this.setInstitutionAttrs(element, affiliation);
|
|
200
|
+
this.setAddressAttrs(element, affiliation);
|
|
201
|
+
this.appendEmail(element, affiliation);
|
|
202
|
+
affiliationGroup.append(affiliation);
|
|
203
|
+
});
|
|
204
|
+
return affiliationGroup;
|
|
205
|
+
},
|
|
206
|
+
createAffiliationElement(element, priority, createElement) {
|
|
207
|
+
const affiliation = createElement('affiliation');
|
|
208
|
+
affiliation.setAttribute('priority', priority.toString());
|
|
209
|
+
const id = element.getAttribute('id');
|
|
210
|
+
if (id) {
|
|
211
|
+
affiliation.setAttribute('id', id);
|
|
212
|
+
}
|
|
213
|
+
return affiliation;
|
|
214
|
+
},
|
|
215
|
+
appendEmail(element, affiliation) {
|
|
216
|
+
const emailEl = element.querySelector('email');
|
|
217
|
+
if (emailEl) {
|
|
218
|
+
affiliation.appendChild(emailEl);
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
setInstitutionAttrs(element, affiliation) {
|
|
222
|
+
var _a;
|
|
223
|
+
for (const node of element.querySelectorAll('institution')) {
|
|
224
|
+
const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
225
|
+
if (!content) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const type = node.getAttribute('content-type');
|
|
229
|
+
if (type === 'dept') {
|
|
230
|
+
affiliation.setAttribute('department', content);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
affiliation.setAttribute('institution', content);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
setAddressAttrs(element, affiliation) {
|
|
238
|
+
const addressLine1 = getTrimmedTextContent(element, 'addr-line:nth-of-type(1)');
|
|
239
|
+
const addressLine2 = getTrimmedTextContent(element, 'addr-line:nth-of-type(2)');
|
|
240
|
+
const addressLine3 = getTrimmedTextContent(element, 'addr-line:nth-of-type(3)');
|
|
241
|
+
const postCode = getTrimmedTextContent(element, 'postal-code');
|
|
242
|
+
const country = getTrimmedTextContent(element, 'country');
|
|
243
|
+
if (addressLine1) {
|
|
244
|
+
affiliation.setAttribute('addressLine1', addressLine1);
|
|
245
|
+
}
|
|
246
|
+
if (addressLine2) {
|
|
247
|
+
affiliation.setAttribute('addressLine2', addressLine2);
|
|
248
|
+
}
|
|
249
|
+
if (addressLine3) {
|
|
250
|
+
affiliation.setAttribute('addressLine3', addressLine3);
|
|
251
|
+
}
|
|
252
|
+
if (postCode) {
|
|
253
|
+
affiliation.setAttribute('postCode', postCode);
|
|
254
|
+
}
|
|
255
|
+
if (country) {
|
|
256
|
+
affiliation.setAttribute('country', country);
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
};
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
16
17
|
import { getTrimmedTextContent } from '../../lib/utils';
|
|
18
|
+
import { generateID } from '../../transformer';
|
|
17
19
|
export const parseJournalIdentifiers = (element) => {
|
|
18
20
|
var _a;
|
|
19
21
|
if (!element) {
|
|
@@ -84,3 +86,7 @@ export const parseJournalMeta = (element) => {
|
|
|
84
86
|
title: (_b = getTrimmedTextContent(element, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
|
|
85
87
|
};
|
|
86
88
|
};
|
|
89
|
+
export const parseJournal = (element) => {
|
|
90
|
+
const meta = parseJournalMeta(element);
|
|
91
|
+
return Object.assign(Object.assign({}, meta), { _id: generateID(ObjectTypes.Journal), objectType: ObjectTypes.Journal });
|
|
92
|
+
};
|
|
@@ -14,24 +14,38 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
-
import { schema } from '../../schema';
|
|
17
|
+
import { schema, } from '../../schema';
|
|
18
18
|
import { generateID, nodeTypesMap } from '../../transformer';
|
|
19
19
|
export const updateDocumentIDs = (node, replacements) => {
|
|
20
20
|
const warnings = [];
|
|
21
|
-
|
|
21
|
+
const highlightNodes = [];
|
|
22
|
+
recurseDoc(node, (n, parent) => updateNodeID(n, parent, replacements, warnings, highlightNodes));
|
|
22
23
|
recurseDoc(node, (n) => updateNodeRID(n, replacements, warnings));
|
|
23
24
|
recurseDoc(node, (n) => updateNodeRIDS(n, replacements, warnings));
|
|
25
|
+
recurseDoc(node, (n) => updateContributorNodesIDS(n, replacements, warnings));
|
|
24
26
|
return warnings;
|
|
25
27
|
};
|
|
26
|
-
function recurseDoc(node, fn) {
|
|
27
|
-
fn(node);
|
|
28
|
-
node.descendants((n) => fn(n));
|
|
28
|
+
function recurseDoc(node, fn, parent = null) {
|
|
29
|
+
fn(node, parent);
|
|
30
|
+
node.descendants((n, pos, parent) => fn(n, parent));
|
|
29
31
|
}
|
|
30
|
-
const updateNodeID = (node, replacements, warnings) => {
|
|
32
|
+
const updateNodeID = (node, parent, replacements, warnings, highlightNodes) => {
|
|
31
33
|
if (node.type === schema.nodes.inline_equation) {
|
|
32
34
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${uuidv4()}` });
|
|
33
35
|
return;
|
|
34
36
|
}
|
|
37
|
+
if (node.type === schema.nodes.highlight_marker) {
|
|
38
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { tid: parent === null || parent === void 0 ? void 0 : parent.attrs.id });
|
|
39
|
+
highlightNodes.push(node);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (node.type === schema.nodes.comment) {
|
|
43
|
+
const highlightNode = highlightNodes.find((n) => n.attrs.id === node.attrs.id);
|
|
44
|
+
if (highlightNode) {
|
|
45
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { target: highlightNode.attrs.tid });
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
35
49
|
if (node.type === schema.nodes.general_table_footnote) {
|
|
36
50
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `GeneralTableFootnote:${uuidv4()}` });
|
|
37
51
|
return;
|
|
@@ -74,6 +88,26 @@ const updateNodeRIDS = (node, replacements, warnings) => {
|
|
|
74
88
|
}
|
|
75
89
|
node.attrs = Object.assign(Object.assign({}, node.attrs), { rids: previousRIDs.map((r) => replacements.get(r) || r) });
|
|
76
90
|
};
|
|
91
|
+
const updateContributorNodesIDS = (node, replacements, warnings) => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
if (node.type === schema.nodes.contributor) {
|
|
94
|
+
const footnote = (_a = node.attrs.footnote) === null || _a === void 0 ? void 0 : _a.map((fn) => {
|
|
95
|
+
return Object.assign(Object.assign({}, fn), { noteID: replacements.get(fn.noteID) });
|
|
96
|
+
});
|
|
97
|
+
const corresp = (_b = node.attrs.corresp) === null || _b === void 0 ? void 0 : _b.map((corresp) => {
|
|
98
|
+
return Object.assign(Object.assign({}, corresp), { correspID: replacements.get(corresp.correspID) });
|
|
99
|
+
});
|
|
100
|
+
const affiliations = node.attrs.affiliations.map((affiliation) => {
|
|
101
|
+
return replacements.get(affiliation);
|
|
102
|
+
});
|
|
103
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { footnote,
|
|
104
|
+
corresp,
|
|
105
|
+
affiliations });
|
|
106
|
+
}
|
|
107
|
+
if (node.type !== schema.nodes.contributors) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
77
111
|
const JATS_TO_HTML_MAPPING = new Map([
|
|
78
112
|
['bold', 'b'],
|
|
79
113
|
['italic', 'i'],
|