@manuscripts/transform 3.0.13 → 3.0.14-LEAN-3961.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/cjs/index.js +1 -2
  2. package/dist/cjs/jats/exporter/jats-exporter.js +7 -7
  3. package/dist/cjs/jats/importer/jats-dom-parser.js +969 -949
  4. package/dist/cjs/jats/importer/jats-transformations.js +9 -14
  5. package/dist/cjs/jats/importer/parse-jats-article.js +7 -5
  6. package/dist/cjs/lib/{section-group-type.js → section-categories.js} +4 -14
  7. package/dist/cjs/schema/migration/migration-scripts/3.0.14.js +25 -0
  8. package/dist/cjs/schema/migration/migration-scripts/index.js +6 -1
  9. package/dist/cjs/transformer/index.js +0 -1
  10. package/dist/cjs/version.js +1 -1
  11. package/dist/es/index.js +1 -2
  12. package/dist/es/jats/exporter/jats-exporter.js +8 -8
  13. package/dist/es/jats/importer/jats-dom-parser.js +967 -948
  14. package/dist/es/jats/importer/jats-transformations.js +9 -14
  15. package/dist/es/jats/importer/parse-jats-article.js +8 -6
  16. package/dist/es/lib/{section-group-type.js → section-categories.js} +2 -13
  17. package/dist/es/schema/migration/migration-scripts/3.0.14.js +23 -0
  18. package/dist/es/schema/migration/migration-scripts/index.js +6 -1
  19. package/dist/es/transformer/index.js +0 -1
  20. package/dist/es/version.js +1 -1
  21. package/dist/types/index.d.ts +1 -2
  22. package/dist/types/jats/importer/jats-dom-parser.d.ts +24 -9
  23. package/dist/types/jats/importer/jats-transformations.d.ts +2 -1
  24. package/dist/types/jats/importer/parse-jats-article.d.ts +2 -2
  25. package/dist/types/lib/{section-group-type.d.ts → section-categories.d.ts} +3 -9
  26. package/dist/types/schema/migration/migration-scripts/3.0.14.d.ts +9 -0
  27. package/dist/types/schema/migration/migration-scripts/index.d.ts +2 -1
  28. package/dist/types/schema/types.d.ts +21 -1
  29. package/dist/types/transformer/index.d.ts +0 -1
  30. package/dist/types/version.d.ts +1 -1
  31. package/package.json +1 -1
  32. package/dist/cjs/lib/table-cell-styles.js +0 -52
  33. package/dist/cjs/transformer/section-category.js +0 -268
  34. package/dist/es/lib/table-cell-styles.js +0 -47
  35. package/dist/es/transformer/section-category.js +0 -254
  36. package/dist/types/lib/table-cell-styles.d.ts +0 -27
  37. package/dist/types/transformer/section-category.d.ts +0 -31
@@ -18,977 +18,997 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  return (mod && mod.__esModule) ? mod : { "default": mod };
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.jatsDOMParser = void 0;
21
+ exports.JATSDOMParser = void 0;
22
22
  const json_schema_1 = require("@manuscripts/json-schema");
23
23
  const mime_1 = __importDefault(require("mime"));
24
24
  const prosemirror_model_1 = require("prosemirror-model");
25
25
  const utils_1 = require("../../lib/utils");
26
- const schema_1 = require("../../schema");
27
- const transformer_1 = require("../../transformer");
28
26
  const jats_comments_1 = require("./jats-comments");
29
27
  const jats_parser_utils_1 = require("./jats-parser-utils");
30
- const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
31
- const chooseContentType = (graphicNode) => {
32
- if (graphicNode) {
33
- const mimetype = graphicNode.getAttribute('mimetype');
34
- const subtype = graphicNode.getAttribute('mime-subtype');
35
- if (mimetype && subtype) {
36
- return [mimetype, subtype].join('/');
37
- }
38
- const href = graphicNode.getAttributeNS(XLINK_NAMESPACE, 'href');
39
- if (href) {
40
- return mime_1.default.getType(href) || undefined;
41
- }
42
- }
43
- };
44
- const parsePriority = (priority) => {
45
- if (!priority) {
46
- return undefined;
47
- }
48
- return parseInt(priority);
49
- };
50
- const getEquationContent = (p) => {
51
- var _a;
52
- const element = p;
53
- const id = element.getAttribute('id');
54
- const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
55
- let contents = '';
56
- let format = '';
57
- for (const child of container.childNodes) {
58
- const nodeName = child.nodeName.replace(/^[a-z]:/, '');
59
- switch (nodeName) {
60
- case 'tex-math':
61
- contents = child.textContent;
62
- format = 'tex';
63
- break;
64
- case 'mml:math':
65
- contents = child.outerHTML;
66
- format = 'mathml';
67
- break;
68
- }
69
- }
70
- return { id, format, contents };
71
- };
72
- const parseDates = (historyNode) => {
73
- if (!historyNode) {
74
- return undefined;
75
- }
76
- const history = {};
77
- for (const date of historyNode.children) {
78
- const dateType = date.getAttribute('date-type');
79
- switch (dateType) {
80
- case 'received': {
81
- history.receiveDate = (0, utils_1.dateToTimestamp)(date);
82
- break;
83
- }
84
- case 'rev-recd': {
85
- history.revisionReceiveDate = (0, utils_1.dateToTimestamp)(date);
86
- break;
28
+ class JATSDOMParser {
29
+ constructor(sectionCategories, schema) {
30
+ this.sectionCategories = sectionCategories;
31
+ this.schema = schema;
32
+ this.XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
33
+ this.chooseContentType = (graphicNode) => {
34
+ if (graphicNode) {
35
+ const mimetype = graphicNode.getAttribute('mimetype');
36
+ const subtype = graphicNode.getAttribute('mime-subtype');
37
+ if (mimetype && subtype) {
38
+ return [mimetype, subtype].join('/');
39
+ }
40
+ const href = graphicNode.getAttributeNS(this.XLINK_NAMESPACE, 'href');
41
+ if (href) {
42
+ return mime_1.default.getType(href) || undefined;
43
+ }
87
44
  }
88
- case 'accepted': {
89
- history.acceptanceDate = (0, utils_1.dateToTimestamp)(date);
90
- break;
45
+ };
46
+ this.parsePriority = (priority) => {
47
+ if (!priority) {
48
+ return undefined;
91
49
  }
92
- case 'rev-request': {
93
- history.revisionRequestDate = (0, utils_1.dateToTimestamp)(date);
94
- break;
50
+ return parseInt(priority);
51
+ };
52
+ this.getEquationContent = (p) => {
53
+ var _a;
54
+ const element = p;
55
+ const id = element.getAttribute('id');
56
+ const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
57
+ let contents = '';
58
+ let format = '';
59
+ for (const child of container.childNodes) {
60
+ const nodeName = child.nodeName.replace(/^[a-z]:/, '');
61
+ switch (nodeName) {
62
+ case 'tex-math':
63
+ contents = child.textContent;
64
+ format = 'tex';
65
+ break;
66
+ case 'mml:math':
67
+ contents = child.outerHTML;
68
+ format = 'mathml';
69
+ break;
70
+ }
95
71
  }
96
- case 'retracted': {
97
- history.retractionDate = (0, utils_1.dateToTimestamp)(date);
98
- break;
72
+ return { id, format, contents };
73
+ };
74
+ this.parseDates = (historyNode) => {
75
+ if (!historyNode) {
76
+ return undefined;
99
77
  }
100
- case 'corrected': {
101
- history.correctionDate = (0, utils_1.dateToTimestamp)(date);
102
- break;
78
+ const history = {};
79
+ for (const date of historyNode.children) {
80
+ const dateType = date.getAttribute('date-type');
81
+ switch (dateType) {
82
+ case 'received': {
83
+ history.receiveDate = (0, utils_1.dateToTimestamp)(date);
84
+ break;
85
+ }
86
+ case 'rev-recd': {
87
+ history.revisionReceiveDate = (0, utils_1.dateToTimestamp)(date);
88
+ break;
89
+ }
90
+ case 'accepted': {
91
+ history.acceptanceDate = (0, utils_1.dateToTimestamp)(date);
92
+ break;
93
+ }
94
+ case 'rev-request': {
95
+ history.revisionRequestDate = (0, utils_1.dateToTimestamp)(date);
96
+ break;
97
+ }
98
+ case 'retracted': {
99
+ history.retractionDate = (0, utils_1.dateToTimestamp)(date);
100
+ break;
101
+ }
102
+ case 'corrected': {
103
+ history.correctionDate = (0, utils_1.dateToTimestamp)(date);
104
+ break;
105
+ }
106
+ }
103
107
  }
104
- }
105
- }
106
- return history;
107
- };
108
- const getEmail = (element) => {
109
- var _a, _b;
110
- const email = element.querySelector('email');
111
- if (email) {
112
- return {
113
- href: (_a = email.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _a !== void 0 ? _a : '',
114
- text: (_b = (0, utils_1.getTrimmedTextContent)(email)) !== null && _b !== void 0 ? _b : '',
108
+ return history;
115
109
  };
116
- }
117
- };
118
- const getInstitutionDetails = (element) => {
119
- let department = '';
120
- let institution = '';
121
- for (const node of element.querySelectorAll('institution')) {
122
- const content = (0, utils_1.getTrimmedTextContent)(node);
123
- if (!content) {
124
- continue;
125
- }
126
- const type = node.getAttribute('content-type');
127
- if (type === 'dept') {
128
- department = content;
129
- }
130
- else {
131
- institution = content;
132
- }
133
- }
134
- return { department, institution };
135
- };
136
- const getAddressLine = (element, index) => {
137
- return (0, utils_1.getTrimmedTextContent)(element, `addr-line:nth-of-type(${index})`) || '';
138
- };
139
- const getHTMLContent = (node, querySelector) => {
140
- return (0, jats_parser_utils_1.htmlFromJatsNode)(node.querySelector(querySelector));
141
- };
142
- const chooseBibliographyItemType = (publicationType) => {
143
- switch (publicationType) {
144
- case 'book':
145
- case 'thesis':
146
- return publicationType;
147
- case 'journal':
148
- default:
149
- return 'article-journal';
150
- }
151
- };
152
- const parseRef = (element) => {
153
- const publicationType = element.getAttribute('publication-type');
154
- const authorNodes = [
155
- ...element.querySelectorAll('person-group[person-group-type="author"] > *'),
156
- ];
157
- const id = element.id;
158
- const attrs = {
159
- id,
160
- type: chooseBibliographyItemType(publicationType),
161
- };
162
- const title = getHTMLContent(element, 'article-title');
163
- if (title) {
164
- attrs.title = title;
165
- }
166
- const mixedCitation = element.querySelector('mixed-citation');
167
- if (authorNodes.length <= 0) {
168
- mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
169
- var _a, _b;
170
- if (item.nodeType === Node.TEXT_NODE &&
171
- ((_a = item.textContent) === null || _a === void 0 ? void 0 : _a.match(/[A-Za-z]+/g))) {
172
- attrs.literal = (_b = (0, utils_1.getTrimmedTextContent)(mixedCitation)) !== null && _b !== void 0 ? _b : '';
173
- return attrs;
174
- }
175
- });
176
- }
177
- const source = getHTMLContent(element, 'source');
178
- if (source) {
179
- attrs.containerTitle = source;
180
- }
181
- const volume = (0, utils_1.getTrimmedTextContent)(element, 'volume');
182
- if (volume) {
183
- attrs.volume = volume;
184
- }
185
- const issue = (0, utils_1.getTrimmedTextContent)(element, 'issue');
186
- if (issue) {
187
- attrs.issue = issue;
188
- }
189
- const supplement = (0, utils_1.getTrimmedTextContent)(element, 'supplement');
190
- if (supplement) {
191
- attrs.supplement = supplement;
192
- }
193
- const fpage = (0, utils_1.getTrimmedTextContent)(element, 'fpage');
194
- const lpage = (0, utils_1.getTrimmedTextContent)(element, 'lpage');
195
- if (fpage) {
196
- attrs.page = lpage ? `${fpage}-${lpage}` : fpage;
197
- }
198
- const year = (0, utils_1.getTrimmedTextContent)(element, 'year');
199
- if (year) {
200
- attrs.issued = (0, json_schema_1.buildBibliographicDate)({
201
- 'date-parts': [[year]],
202
- });
203
- }
204
- const doi = (0, utils_1.getTrimmedTextContent)(element, 'pub-id[pub-id-type="doi"]');
205
- if (doi) {
206
- attrs.doi = doi;
207
- }
208
- const authors = [];
209
- authorNodes.forEach((authorNode) => {
210
- const name = (0, json_schema_1.buildBibliographicName)({});
211
- const given = (0, utils_1.getTrimmedTextContent)(authorNode, 'given-names');
212
- if (given) {
213
- name.given = given;
214
- }
215
- const family = (0, utils_1.getTrimmedTextContent)(authorNode, 'surname');
216
- if (family) {
217
- name.family = family;
218
- }
219
- if (authorNode.nodeName === 'collab') {
220
- name.literal = (0, utils_1.getTrimmedTextContent)(authorNode);
221
- }
222
- authors.push(name);
223
- });
224
- if (authors.length) {
225
- attrs.author = authors;
226
- }
227
- return attrs;
228
- };
229
- const marks = [
230
- {
231
- tag: 'bold',
232
- mark: 'bold',
233
- },
234
- {
235
- tag: 'code',
236
- mark: 'code',
237
- },
238
- {
239
- tag: 'italic',
240
- mark: 'italic',
241
- },
242
- {
243
- tag: 'sc',
244
- mark: 'smallcaps',
245
- },
246
- {
247
- tag: 'strike',
248
- mark: 'strikethrough',
249
- },
250
- {
251
- tag: 'styled-content',
252
- mark: 'styled',
253
- getAttrs: (node) => ({
254
- style: node.getAttribute('style'),
255
- }),
256
- },
257
- {
258
- tag: 'sub',
259
- mark: 'subscript',
260
- },
261
- {
262
- tag: 'sup',
263
- mark: 'superscript',
264
- },
265
- {
266
- tag: 'underline',
267
- mark: 'underline',
268
- },
269
- ];
270
- const nodes = [
271
- {
272
- tag: 'article',
273
- node: 'manuscript',
274
- getAttrs: (node) => {
110
+ this.getEmail = (element) => {
275
111
  var _a, _b;
276
- const element = node;
277
- const doi = element.querySelector('front > article-meta > article-id[pub-id-type="doi"]');
278
- const history = element.querySelector('history');
279
- const dates = parseDates(history);
280
- return Object.assign({ doi: (0, utils_1.getTrimmedTextContent)(doi), articleType: (_a = element.getAttribute('article-type')) !== null && _a !== void 0 ? _a : '', primaryLanguageCode: (_b = element.getAttribute('lang')) !== null && _b !== void 0 ? _b : '' }, dates);
281
- },
282
- },
283
- {
284
- tag: 'article-title',
285
- node: 'title',
286
- getAttrs: (node) => {
287
- const element = node;
288
- return {
289
- id: element.getAttribute('id'),
290
- };
291
- },
292
- },
293
- {
294
- tag: 'highlight-marker',
295
- node: 'highlight_marker',
296
- getAttrs: (node) => {
297
- const element = node;
298
- return {
299
- id: element.id,
300
- position: element.getAttribute('position'),
301
- };
302
- },
303
- },
304
- {
305
- tag: 'comment',
306
- node: 'comment',
307
- getAttrs: (node) => {
308
- const element = node;
309
- return {
310
- id: element.getAttribute('id'),
311
- target: element.getAttribute('target-id'),
312
- contents: (0, utils_1.getTrimmedTextContent)(element),
313
- contributions: [(0, json_schema_1.buildContribution)(jats_comments_1.DEFAULT_PROFILE_ID)],
314
- };
315
- },
316
- },
317
- {
318
- tag: 'author-notes',
319
- node: 'author_notes',
320
- getAttrs: (node) => {
321
- const element = node;
322
- return {
323
- id: element.getAttribute('id'),
324
- };
325
- },
326
- },
327
- {
328
- tag: 'funding-group',
329
- node: 'awards',
330
- },
331
- {
332
- tag: 'award-group',
333
- node: 'award',
334
- getAttrs: (node) => {
335
- const element = node;
336
- return {
337
- id: element.getAttribute('id'),
338
- recipient: (0, utils_1.getTrimmedTextContent)(element, 'principal-award-recipient'),
339
- code: Array.from(element.querySelectorAll('award-id'))
340
- .map((awardID) => (0, utils_1.getTrimmedTextContent)(awardID))
341
- .reduce((acc, text) => (acc ? `${acc};${text}` : text), ''),
342
- source: (0, utils_1.getTrimmedTextContent)(element, 'funding-source'),
343
- };
344
- },
345
- },
346
- {
347
- tag: 'fn:not([fn-type])',
348
- node: 'footnote',
349
- context: 'author_notes/',
350
- getAttrs: (node) => {
351
- const element = node;
352
- return {
353
- id: element.getAttribute('id'),
354
- kind: 'footnote',
355
- };
356
- },
357
- },
358
- {
359
- tag: 'corresp',
360
- node: 'corresp',
361
- getAttrs: (node) => {
362
- const element = node;
363
- const label = element.querySelector('label');
364
- if (label) {
365
- label.remove();
112
+ const email = element.querySelector('email');
113
+ if (email) {
114
+ return {
115
+ href: (_a = email.getAttributeNS(this.XLINK_NAMESPACE, 'href')) !== null && _a !== void 0 ? _a : '',
116
+ text: (_b = (0, utils_1.getTrimmedTextContent)(email)) !== null && _b !== void 0 ? _b : '',
117
+ };
366
118
  }
367
- return {
368
- id: element.getAttribute('id'),
369
- label: (0, utils_1.getTrimmedTextContent)(label),
370
- };
371
- },
372
- getContent: (node) => {
373
- const element = node;
374
- return prosemirror_model_1.Fragment.from(schema_1.schema.text((0, utils_1.getTrimmedTextContent)(element) || ''));
375
- },
376
- },
377
- {
378
- tag: 'contrib[contrib-type="author"]',
379
- node: 'contributor',
380
- getAttrs: (node) => {
381
- const element = node;
382
- const footnote = [];
383
- const affiliations = [];
384
- const corresp = [];
385
- const xrefs = element.querySelectorAll('xref');
386
- for (const xref of xrefs) {
387
- const rid = xref.getAttribute('rid');
388
- const type = xref.getAttribute('ref-type');
389
- if (!rid) {
119
+ };
120
+ this.getInstitutionDetails = (element) => {
121
+ let department = '';
122
+ let institution = '';
123
+ for (const node of element.querySelectorAll('institution')) {
124
+ const content = (0, utils_1.getTrimmedTextContent)(node);
125
+ if (!content) {
390
126
  continue;
391
127
  }
392
- switch (type) {
393
- case 'fn':
394
- footnote.push({
395
- noteID: rid,
396
- noteLabel: (0, utils_1.getTrimmedTextContent)(xref) || '',
397
- });
398
- break;
399
- case 'corresp':
400
- corresp.push({
401
- correspID: rid,
402
- correspLabel: (0, utils_1.getTrimmedTextContent)(xref) || '',
403
- });
404
- break;
405
- case 'aff':
406
- affiliations.push(rid);
407
- break;
128
+ const type = node.getAttribute('content-type');
129
+ if (type === 'dept') {
130
+ department = content;
131
+ }
132
+ else {
133
+ institution = content;
408
134
  }
409
135
  }
410
- return {
411
- id: element.getAttribute('id'),
412
- role: 'author',
413
- affiliations,
414
- corresp,
415
- footnote,
416
- isCorresponding: element.getAttribute('corresp')
417
- ? element.getAttribute('corresp') === 'yes'
418
- : undefined,
419
- bibliographicName: {
420
- given: (0, utils_1.getTrimmedTextContent)(element, 'name > given-names'),
421
- family: (0, utils_1.getTrimmedTextContent)(element, 'name > surname'),
422
- ObjectType: json_schema_1.ObjectTypes.BibliographicName,
423
- },
424
- ORCIDIdentifier: (0, utils_1.getTrimmedTextContent)(element, 'contrib-id[contrib-id-type="orcid"]'),
425
- priority: parsePriority(element.getAttribute('priority')),
426
- };
427
- },
428
- getContent: () => {
429
- return prosemirror_model_1.Fragment.from(schema_1.schema.text('_'));
430
- },
431
- },
432
- {
433
- tag: 'affiliations',
434
- node: 'affiliations',
435
- },
436
- {
437
- tag: 'aff',
438
- node: 'affiliation',
439
- context: 'affiliations/',
440
- getAttrs: (node) => {
441
- var _a, _b;
442
- const element = node;
443
- const { department, institution } = getInstitutionDetails(element);
444
- return {
445
- id: element.getAttribute('id'),
446
- institution: institution !== null && institution !== void 0 ? institution : '',
447
- department: department !== null && department !== void 0 ? department : '',
448
- addressLine1: getAddressLine(element, 1),
449
- addressLine2: getAddressLine(element, 2),
450
- addressLine3: getAddressLine(element, 3),
451
- postCode: (_a = (0, utils_1.getTrimmedTextContent)(element, 'postal-code')) !== null && _a !== void 0 ? _a : '',
452
- country: (_b = (0, utils_1.getTrimmedTextContent)(element, 'country')) !== null && _b !== void 0 ? _b : '',
453
- email: getEmail(element),
454
- priority: parsePriority(element.getAttribute('priority')),
455
- };
456
- },
457
- getContent: () => {
458
- return prosemirror_model_1.Fragment.from(schema_1.schema.text('_'));
459
- },
460
- },
461
- {
462
- tag: 'attrib',
463
- node: 'attribution',
464
- },
465
- {
466
- tag: 'back',
467
- ignore: true,
468
- },
469
- {
470
- tag: 'history',
471
- ignore: true,
472
- },
473
- {
474
- tag: 'break',
475
- node: 'hard_break',
476
- },
477
- {
478
- tag: 'caption',
479
- node: 'figcaption',
480
- context: 'figure/',
481
- },
482
- {
483
- tag: 'caption',
484
- node: 'figcaption',
485
- context: 'figure_element/',
486
- getContent: (node, schema) => {
487
- const element = node;
488
- const content = [];
489
- const title = element.querySelector('title');
136
+ return { department, institution };
137
+ };
138
+ this.getAddressLine = (element, index) => {
139
+ return ((0, utils_1.getTrimmedTextContent)(element, `addr-line:nth-of-type(${index})`) || '');
140
+ };
141
+ this.getHTMLContent = (node, querySelector) => {
142
+ return (0, jats_parser_utils_1.htmlFromJatsNode)(node.querySelector(querySelector));
143
+ };
144
+ this.chooseBibliographyItemType = (publicationType) => {
145
+ switch (publicationType) {
146
+ case 'book':
147
+ case 'thesis':
148
+ return publicationType;
149
+ case 'journal':
150
+ default:
151
+ return 'article-journal';
152
+ }
153
+ };
154
+ this.parseRef = (element) => {
155
+ const publicationType = element.getAttribute('publication-type');
156
+ const authorNodes = [
157
+ ...element.querySelectorAll('person-group[person-group-type="author"] > *'),
158
+ ];
159
+ const id = element.id;
160
+ const attrs = {
161
+ id,
162
+ type: this.chooseBibliographyItemType(publicationType),
163
+ };
164
+ const title = this.getHTMLContent(element, 'article-title');
490
165
  if (title) {
491
- const captionTitle = schema.nodes.caption_title.create();
492
- content.push(exports.jatsDOMParser.parse(title, { topNode: captionTitle }));
166
+ attrs.title = title;
493
167
  }
494
- const paragraphs = element.querySelectorAll('p');
495
- if (paragraphs.length) {
496
- const figcaption = schema.nodes.caption.create();
497
- for (const paragraph of paragraphs) {
498
- content.push(exports.jatsDOMParser.parse(paragraph, { topNode: figcaption }));
499
- }
168
+ const mixedCitation = element.querySelector('mixed-citation');
169
+ if (authorNodes.length <= 0) {
170
+ mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
171
+ var _a, _b;
172
+ if (item.nodeType === Node.TEXT_NODE &&
173
+ ((_a = item.textContent) === null || _a === void 0 ? void 0 : _a.match(/[A-Za-z]+/g))) {
174
+ attrs.literal = (_b = (0, utils_1.getTrimmedTextContent)(mixedCitation)) !== null && _b !== void 0 ? _b : '';
175
+ return attrs;
176
+ }
177
+ });
500
178
  }
501
- return prosemirror_model_1.Fragment.from(content);
502
- },
503
- },
504
- {
505
- tag: 'caption',
506
- node: 'figcaption',
507
- context: 'table_element/',
508
- },
509
- {
510
- tag: 'caption',
511
- node: 'figcaption',
512
- context: 'box_element/',
513
- getAttrs: (node) => {
514
- const element = node;
515
- return {
516
- id: element.getAttribute('id'),
517
- };
518
- },
519
- },
520
- {
521
- tag: 'code',
522
- node: 'listing',
523
- context: 'listing_element/',
524
- getAttrs: (node) => {
525
- var _a;
526
- const element = node;
527
- return {
528
- id: element.getAttribute('id'),
529
- language: (_a = element.getAttribute('language')) !== null && _a !== void 0 ? _a : '',
530
- contents: (0, utils_1.getTrimmedTextContent)(element),
531
- };
532
- },
533
- },
534
- {
535
- tag: 'inline-formula',
536
- node: 'inline_equation',
537
- getAttrs: (node) => {
538
- const element = node;
539
- return getEquationContent(element);
540
- },
541
- },
542
- {
543
- tag: 'disp-formula',
544
- node: 'equation_element',
545
- getAttrs: (node) => {
546
- var _a;
547
- const element = node;
548
- return {
549
- id: element.getAttribute('id'),
550
- label: (_a = (0, utils_1.getTrimmedTextContent)(element, 'label')) !== null && _a !== void 0 ? _a : '',
551
- };
552
- },
553
- getContent: (node, schema) => {
554
- const element = node;
555
- const attrs = getEquationContent(element);
556
- return prosemirror_model_1.Fragment.from([
557
- schema.nodes.equation.createChecked(Object.assign({}, attrs)),
558
- ]);
559
- },
560
- },
561
- {
562
- tag: 'disp-quote[content-type=quote]',
563
- node: 'blockquote_element',
564
- getAttrs: (node) => {
565
- const element = node;
566
- return {
567
- id: element.getAttribute('id'),
568
- };
569
- },
570
- },
571
- {
572
- tag: 'disp-quote[content-type=pullquote]',
573
- node: 'pullquote_element',
574
- getAttrs: (node) => {
575
- const element = node;
576
- return {
577
- id: element.getAttribute('id'),
578
- };
579
- },
580
- },
581
- {
582
- tag: 'ext-link',
583
- node: 'link',
584
- getAttrs: (node) => {
585
- const element = node;
586
- return {
587
- href: element.getAttributeNS(XLINK_NAMESPACE, 'href') || '',
588
- title: element.getAttributeNS(XLINK_NAMESPACE, 'title') || '',
589
- };
590
- },
591
- },
592
- {
593
- tag: 'fig[fig-type=equation]',
594
- node: 'equation_element',
595
- getAttrs: (node) => {
596
- const element = node;
597
- return {
598
- id: element.getAttribute('id'),
599
- };
600
- },
601
- },
602
- {
603
- tag: 'fig[fig-type=listing]',
604
- node: 'listing_element',
605
- getAttrs: (node) => {
606
- const element = node;
607
- return {
608
- id: element.getAttribute('id'),
609
- };
610
- },
611
- },
612
- {
613
- tag: 'graphic[specific-use=MISSING]',
614
- node: 'missing_figure',
615
- context: 'figure_element/',
616
- getAttrs: (node) => {
617
- const element = node;
618
- return {
619
- id: element.getAttribute('id'),
620
- };
621
- },
622
- },
623
- {
624
- tag: 'graphic',
625
- node: 'figure',
626
- context: 'figure_element/',
627
- getAttrs: (node) => {
628
- const element = node;
629
- const position = element.getAttribute('position');
630
- const src = element.getAttributeNS(XLINK_NAMESPACE, 'href');
631
- return {
632
- id: element.getAttribute('id'),
633
- contentType: chooseContentType(element || undefined) || '',
634
- src,
635
- position,
636
- };
637
- },
638
- },
639
- {
640
- tag: 'fig',
641
- node: 'figure_element',
642
- getAttrs: (node) => {
643
- var _a, _b;
644
- const element = node;
645
- const labelNode = element.querySelector('label');
646
- if (labelNode) {
647
- element.removeChild(labelNode);
179
+ const source = this.getHTMLContent(element, 'source');
180
+ if (source) {
181
+ attrs.containerTitle = source;
648
182
  }
649
- const attrib = element.querySelector('attrib');
650
- const position = element.getAttribute('position');
651
- const attribution = attrib
652
- ? {
653
- literal: (_a = (0, utils_1.getTrimmedTextContent)(attrib)) !== null && _a !== void 0 ? _a : '',
654
- }
655
- : undefined;
656
- return {
657
- id: element.getAttribute('id'),
658
- label: (_b = (0, utils_1.getTrimmedTextContent)(labelNode)) !== null && _b !== void 0 ? _b : '',
659
- attribution: attribution,
660
- position,
661
- };
662
- },
663
- },
664
- {
665
- tag: 'fn-group',
666
- node: 'footnotes_element',
667
- context: 'footnotes_section/|table_element_footer/',
668
- getAttrs: (node) => {
669
- const element = node;
670
- return {
671
- id: element.getAttribute('id'),
672
- kind: 'footnote',
673
- };
674
- },
675
- },
676
- {
677
- tag: 'table-wrap-foot',
678
- node: 'table_element_footer',
679
- getAttrs: (node) => {
680
- const element = node;
681
- return {
682
- id: element.getAttribute('id'),
683
- };
684
- },
685
- },
686
- {
687
- tag: 'general-table-footnote',
688
- node: 'general_table_footnote',
689
- context: 'table_element_footer/',
690
- getAttrs: (node) => {
691
- const element = node;
692
- return {
693
- id: element.getAttribute('id'),
694
- };
695
- },
696
- getContent: (node) => {
697
- const paragraphs = [];
698
- node.childNodes.forEach((p) => {
699
- const paragraph = schema_1.schema.nodes.paragraph.create();
700
- const content = exports.jatsDOMParser.parse(p, {
701
- topNode: paragraph,
183
+ const volume = (0, utils_1.getTrimmedTextContent)(element, 'volume');
184
+ if (volume) {
185
+ attrs.volume = volume;
186
+ }
187
+ const issue = (0, utils_1.getTrimmedTextContent)(element, 'issue');
188
+ if (issue) {
189
+ attrs.issue = issue;
190
+ }
191
+ const supplement = (0, utils_1.getTrimmedTextContent)(element, 'supplement');
192
+ if (supplement) {
193
+ attrs.supplement = supplement;
194
+ }
195
+ const fpage = (0, utils_1.getTrimmedTextContent)(element, 'fpage');
196
+ const lpage = (0, utils_1.getTrimmedTextContent)(element, 'lpage');
197
+ if (fpage) {
198
+ attrs.page = lpage ? `${fpage}-${lpage}` : fpage;
199
+ }
200
+ const year = (0, utils_1.getTrimmedTextContent)(element, 'year');
201
+ if (year) {
202
+ attrs.issued = (0, json_schema_1.buildBibliographicDate)({
203
+ 'date-parts': [[year]],
702
204
  });
703
- paragraphs.push(content);
205
+ }
206
+ const doi = (0, utils_1.getTrimmedTextContent)(element, 'pub-id[pub-id-type="doi"]');
207
+ if (doi) {
208
+ attrs.doi = doi;
209
+ }
210
+ const authors = [];
211
+ authorNodes.forEach((authorNode) => {
212
+ const name = (0, json_schema_1.buildBibliographicName)({});
213
+ const given = (0, utils_1.getTrimmedTextContent)(authorNode, 'given-names');
214
+ if (given) {
215
+ name.given = given;
216
+ }
217
+ const family = (0, utils_1.getTrimmedTextContent)(authorNode, 'surname');
218
+ if (family) {
219
+ name.family = family;
220
+ }
221
+ if (authorNode.nodeName === 'collab') {
222
+ name.literal = (0, utils_1.getTrimmedTextContent)(authorNode);
223
+ }
224
+ authors.push(name);
704
225
  });
705
- return prosemirror_model_1.Fragment.from([...paragraphs]);
706
- },
707
- },
708
- {
709
- tag: 'fn',
710
- node: 'footnote',
711
- context: 'footnotes_element/|table_element_footer/',
712
- getAttrs: (node) => {
713
- const element = node;
714
- return {
715
- id: element.getAttribute('id'),
716
- kind: 'footnote',
717
- };
718
- },
719
- },
720
- {
721
- tag: 'front',
722
- ignore: true,
723
- },
724
- {
725
- tag: 'list',
726
- node: 'list',
727
- getAttrs: (node) => {
728
- const element = node;
729
- return {
730
- id: element.getAttribute('id'),
731
- listStyleType: element.getAttribute('list-type'),
732
- };
733
- },
734
- },
735
- {
736
- tag: 'list-item',
737
- node: 'list_item',
738
- },
739
- {
740
- tag: 'p',
741
- node: 'paragraph',
742
- context: 'section/',
743
- getAttrs: (node) => {
744
- const element = node;
745
- return {
746
- id: element.getAttribute('id'),
747
- };
748
- },
749
- },
750
- {
751
- tag: 'p',
752
- node: 'paragraph',
753
- },
754
- {
755
- tag: 'sec[sec-type="endnotes"]',
756
- node: 'footnotes_section',
757
- getAttrs: (node) => {
758
- const element = node;
759
- return {
760
- id: element.getAttribute('id'),
761
- };
762
- },
763
- },
764
- {
765
- tag: 'sec[sec-type="keywords"]',
766
- node: 'keywords',
767
- },
768
- {
769
- tag: 'sec[sec-type="supplementary-material"]',
770
- node: 'supplements',
771
- },
772
- {
773
- tag: 'supplementary-material',
774
- node: 'supplement',
775
- getAttrs: (node) => {
776
- const element = node;
777
- return {
778
- id: element.getAttribute('id'),
779
- href: element.getAttributeNS(XLINK_NAMESPACE, 'href'),
780
- mimeType: element.getAttribute('mimetype'),
781
- mimeSubType: element.getAttribute('mime-subtype'),
782
- title: (0, utils_1.getTrimmedTextContent)(element, 'title'),
783
- };
784
- },
785
- },
786
- {
787
- tag: 'sec[sec-type="abstracts"]',
788
- node: 'abstracts',
789
- },
790
- {
791
- tag: 'sec[sec-type="body"]',
792
- node: 'body',
793
- },
794
- {
795
- tag: 'sec[sec-type="backmatter"]',
796
- node: 'backmatter',
797
- },
798
- {
799
- tag: 'sec[sec-type="box-element"]',
800
- node: 'box_element',
801
- getAttrs: (node) => {
802
- const element = node;
803
- return {
804
- id: element.getAttribute('id'),
805
- label: (0, utils_1.getTrimmedTextContent)(element, 'label'),
806
- };
807
- },
808
- },
809
- {
810
- tag: 'sec[sec-type="bibliography"]',
811
- node: 'bibliography_section',
812
- },
813
- {
814
- tag: 'ref-list',
815
- context: 'bibliography_section/',
816
- node: 'bibliography_element',
817
- },
818
- {
819
- tag: 'ref',
820
- context: 'bibliography_element/',
821
- node: 'bibliography_item',
822
- getAttrs: (node) => parseRef(node),
823
- },
824
- {
825
- tag: 'sec[sec-type="abstract-graphical"]',
826
- node: 'graphical_abstract_section',
827
- },
828
- {
829
- tag: 'sec',
830
- node: 'section',
831
- getAttrs: (node) => {
832
- var _a, _b;
833
- const element = node;
834
- const grandParentNodeName = (_b = (_a = element.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.nodeName.toLowerCase();
835
- if (grandParentNodeName && grandParentNodeName !== 'body') {
836
- element.setAttribute('sec-type', 'subsection');
226
+ if (authors.length) {
227
+ attrs.author = authors;
837
228
  }
838
- return {
839
- id: element.getAttribute('id'),
840
- category: (0, transformer_1.chooseSectionCategory)(element),
841
- };
842
- },
843
- },
844
- {
845
- tag: 'kwd-group-list',
846
- context: 'keywords/',
847
- node: 'keywords_element',
848
- },
849
- {
850
- tag: 'kwd-group',
851
- context: 'keywords_element/',
852
- node: 'keyword_group',
853
- getAttrs: (node) => {
854
- const element = node;
855
- return {
856
- id: element.id,
857
- type: element.getAttribute('kwd-group-type'),
858
- };
859
- },
860
- },
861
- {
862
- tag: 'kwd',
863
- context: 'keyword_group//',
864
- node: 'keyword',
865
- },
866
- {
867
- tag: 'label',
868
- context: 'box_element/',
869
- ignore: true,
870
- },
871
- {
872
- tag: 'boxed-text',
873
- ignore: true,
874
- },
875
- {
876
- tag: 'label',
877
- context: 'section/',
878
- node: 'section_label',
879
- },
880
- {
881
- tag: 'label',
882
- context: 'table_element/',
883
- ignore: true,
884
- },
885
- {
886
- tag: 'label',
887
- context: 'figure/',
888
- ignore: true,
889
- },
890
- {
891
- tag: 'table',
892
- node: 'table',
893
- getAttrs: (node) => {
894
- const element = node;
895
- return {
896
- id: element.getAttribute('id'),
897
- };
898
- },
899
- },
900
- {
901
- tag: 'table-wrap',
902
- node: 'table_element',
903
- getAttrs: (node) => {
904
- const element = node;
905
- return {
906
- id: element.getAttribute('id'),
907
- };
908
- },
909
- },
910
- {
911
- tag: 'title',
912
- node: 'section_title',
913
- context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/|author_notes/|graphical_abstract_section/',
914
- },
915
- {
916
- tag: 'title',
917
- node: 'caption_title',
918
- context: 'figcaption/',
919
- },
920
- {
921
- tag: 'tr',
922
- node: 'table_row',
923
- },
924
- {
925
- tag: 'td',
926
- node: 'table_cell',
927
- getAttrs: (node) => {
928
- const element = node;
929
- const colspan = parseInt(element.getAttribute('colspan') || '1');
930
- const rowspan = parseInt(element.getAttribute('rowspan') || '1');
931
- return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
932
- },
933
- },
934
- {
935
- tag: 'th',
936
- node: 'table_header',
937
- getAttrs: (node) => {
938
- const element = node;
939
- const colspan = parseInt(element.getAttribute('colspan') || '1');
940
- const rowspan = parseInt(element.getAttribute('rowspan') || '1');
941
- return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
942
- },
943
- },
944
- {
945
- tag: 'col',
946
- node: 'table_col',
947
- getAttrs: (node) => {
948
- const element = node;
949
- return {
950
- width: element.getAttribute('width'),
951
- };
952
- },
953
- },
954
- {
955
- tag: 'colgroup',
956
- node: 'table_colgroup',
957
- },
958
- {
959
- tag: 'xref[ref-type="bibr"]',
960
- node: 'citation',
961
- getAttrs: (node) => {
962
- var _a;
963
- const element = node;
964
- return {
965
- rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
966
- contents: (0, utils_1.getTrimmedTextContent)(element),
967
- };
968
- },
969
- },
970
- {
971
- tag: 'xref[ref-type="fn"]',
972
- node: 'inline_footnote',
973
- getAttrs: (node) => {
974
- var _a;
975
- const element = node;
976
- return {
977
- rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
978
- };
979
- },
980
- },
981
- {
982
- tag: 'xref',
983
- node: 'cross_reference',
984
- getAttrs: (node) => {
985
- var _a;
986
- const element = node;
987
- return {
988
- rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
989
- label: (0, utils_1.getTrimmedTextContent)(element),
990
- };
991
- },
992
- },
993
- ];
994
- exports.jatsDOMParser = new prosemirror_model_1.DOMParser(schema_1.schema, [...marks, ...nodes]);
229
+ return attrs;
230
+ };
231
+ this.nodes = [
232
+ {
233
+ tag: 'article',
234
+ node: 'manuscript',
235
+ getAttrs: (node) => {
236
+ var _a, _b;
237
+ const element = node;
238
+ const doi = element.querySelector('front > article-meta > article-id[pub-id-type="doi"]');
239
+ const history = element.querySelector('history');
240
+ const dates = this.parseDates(history);
241
+ return Object.assign({ doi: (0, utils_1.getTrimmedTextContent)(doi), articleType: (_a = element.getAttribute('article-type')) !== null && _a !== void 0 ? _a : '', primaryLanguageCode: (_b = element.getAttribute('lang')) !== null && _b !== void 0 ? _b : '' }, dates);
242
+ },
243
+ },
244
+ {
245
+ tag: 'article-title',
246
+ node: 'title',
247
+ getAttrs: (node) => {
248
+ const element = node;
249
+ return {
250
+ id: element.getAttribute('id'),
251
+ };
252
+ },
253
+ },
254
+ {
255
+ tag: 'highlight-marker',
256
+ node: 'highlight_marker',
257
+ getAttrs: (node) => {
258
+ const element = node;
259
+ return {
260
+ id: element.id,
261
+ position: element.getAttribute('position'),
262
+ };
263
+ },
264
+ },
265
+ {
266
+ tag: 'comment',
267
+ node: 'comment',
268
+ getAttrs: (node) => {
269
+ const element = node;
270
+ return {
271
+ id: element.getAttribute('id'),
272
+ target: element.getAttribute('target-id'),
273
+ contents: (0, utils_1.getTrimmedTextContent)(element),
274
+ contributions: [(0, json_schema_1.buildContribution)(jats_comments_1.DEFAULT_PROFILE_ID)],
275
+ };
276
+ },
277
+ },
278
+ {
279
+ tag: 'author-notes',
280
+ node: 'author_notes',
281
+ getAttrs: (node) => {
282
+ const element = node;
283
+ return {
284
+ id: element.getAttribute('id'),
285
+ };
286
+ },
287
+ },
288
+ {
289
+ tag: 'funding-group',
290
+ node: 'awards',
291
+ },
292
+ {
293
+ tag: 'award-group',
294
+ node: 'award',
295
+ getAttrs: (node) => {
296
+ const element = node;
297
+ return {
298
+ id: element.getAttribute('id'),
299
+ recipient: (0, utils_1.getTrimmedTextContent)(element, 'principal-award-recipient'),
300
+ code: Array.from(element.querySelectorAll('award-id'))
301
+ .map((awardID) => (0, utils_1.getTrimmedTextContent)(awardID))
302
+ .reduce((acc, text) => (acc ? `${acc};${text}` : text), ''),
303
+ source: (0, utils_1.getTrimmedTextContent)(element, 'funding-source'),
304
+ };
305
+ },
306
+ },
307
+ {
308
+ tag: 'fn:not([fn-type])',
309
+ node: 'footnote',
310
+ context: 'author_notes/',
311
+ getAttrs: (node) => {
312
+ const element = node;
313
+ return {
314
+ id: element.getAttribute('id'),
315
+ kind: 'footnote',
316
+ };
317
+ },
318
+ },
319
+ {
320
+ tag: 'corresp',
321
+ node: 'corresp',
322
+ getAttrs: (node) => {
323
+ const element = node;
324
+ const label = element.querySelector('label');
325
+ if (label) {
326
+ label.remove();
327
+ }
328
+ return {
329
+ id: element.getAttribute('id'),
330
+ label: (0, utils_1.getTrimmedTextContent)(label),
331
+ };
332
+ },
333
+ getContent: (node) => {
334
+ const element = node;
335
+ return prosemirror_model_1.Fragment.from(this.schema.text((0, utils_1.getTrimmedTextContent)(element) || ''));
336
+ },
337
+ },
338
+ {
339
+ tag: 'contrib[contrib-type="author"]',
340
+ node: 'contributor',
341
+ getAttrs: (node) => {
342
+ const element = node;
343
+ const footnote = [];
344
+ const affiliations = [];
345
+ const corresp = [];
346
+ const xrefs = element.querySelectorAll('xref');
347
+ for (const xref of xrefs) {
348
+ const rid = xref.getAttribute('rid');
349
+ const type = xref.getAttribute('ref-type');
350
+ if (!rid) {
351
+ continue;
352
+ }
353
+ switch (type) {
354
+ case 'fn':
355
+ footnote.push({
356
+ noteID: rid,
357
+ noteLabel: (0, utils_1.getTrimmedTextContent)(xref) || '',
358
+ });
359
+ break;
360
+ case 'corresp':
361
+ corresp.push({
362
+ correspID: rid,
363
+ correspLabel: (0, utils_1.getTrimmedTextContent)(xref) || '',
364
+ });
365
+ break;
366
+ case 'aff':
367
+ affiliations.push(rid);
368
+ break;
369
+ }
370
+ }
371
+ return {
372
+ id: element.getAttribute('id'),
373
+ role: 'author',
374
+ affiliations,
375
+ corresp,
376
+ footnote,
377
+ isCorresponding: element.getAttribute('corresp')
378
+ ? element.getAttribute('corresp') === 'yes'
379
+ : undefined,
380
+ bibliographicName: {
381
+ given: (0, utils_1.getTrimmedTextContent)(element, 'name > given-names'),
382
+ family: (0, utils_1.getTrimmedTextContent)(element, 'name > surname'),
383
+ ObjectType: json_schema_1.ObjectTypes.BibliographicName,
384
+ },
385
+ ORCIDIdentifier: (0, utils_1.getTrimmedTextContent)(element, 'contrib-id[contrib-id-type="orcid"]'),
386
+ priority: this.parsePriority(element.getAttribute('priority')),
387
+ };
388
+ },
389
+ getContent: () => {
390
+ return prosemirror_model_1.Fragment.from(this.schema.text('_'));
391
+ },
392
+ },
393
+ {
394
+ tag: 'affiliations',
395
+ node: 'affiliations',
396
+ },
397
+ {
398
+ tag: 'aff',
399
+ node: 'affiliation',
400
+ context: 'affiliations/',
401
+ getAttrs: (node) => {
402
+ var _a, _b;
403
+ const element = node;
404
+ const { department, institution } = this.getInstitutionDetails(element);
405
+ return {
406
+ id: element.getAttribute('id'),
407
+ institution: institution !== null && institution !== void 0 ? institution : '',
408
+ department: department !== null && department !== void 0 ? department : '',
409
+ addressLine1: this.getAddressLine(element, 1),
410
+ addressLine2: this.getAddressLine(element, 2),
411
+ addressLine3: this.getAddressLine(element, 3),
412
+ postCode: (_a = (0, utils_1.getTrimmedTextContent)(element, 'postal-code')) !== null && _a !== void 0 ? _a : '',
413
+ country: (_b = (0, utils_1.getTrimmedTextContent)(element, 'country')) !== null && _b !== void 0 ? _b : '',
414
+ email: this.getEmail(element),
415
+ priority: this.parsePriority(element.getAttribute('priority')),
416
+ };
417
+ },
418
+ getContent: () => {
419
+ return prosemirror_model_1.Fragment.from(this.schema.text('_'));
420
+ },
421
+ },
422
+ {
423
+ tag: 'attrib',
424
+ node: 'attribution',
425
+ },
426
+ {
427
+ tag: 'back',
428
+ ignore: true,
429
+ },
430
+ {
431
+ tag: 'history',
432
+ ignore: true,
433
+ },
434
+ {
435
+ tag: 'break',
436
+ node: 'hard_break',
437
+ },
438
+ {
439
+ tag: 'caption',
440
+ node: 'figcaption',
441
+ context: 'figure/',
442
+ },
443
+ {
444
+ tag: 'caption',
445
+ node: 'figcaption',
446
+ context: 'figure_element/',
447
+ getContent: (node, schema) => {
448
+ const element = node;
449
+ const content = [];
450
+ const title = element.querySelector('title');
451
+ if (title) {
452
+ const captionTitle = schema.nodes.caption_title.create();
453
+ content.push(this.parse(title, { topNode: captionTitle }));
454
+ }
455
+ const paragraphs = element.querySelectorAll('p');
456
+ if (paragraphs.length) {
457
+ const figcaption = schema.nodes.caption.create();
458
+ for (const paragraph of paragraphs) {
459
+ content.push(this.parse(paragraph, { topNode: figcaption }));
460
+ }
461
+ }
462
+ return prosemirror_model_1.Fragment.from(content);
463
+ },
464
+ },
465
+ {
466
+ tag: 'caption',
467
+ node: 'figcaption',
468
+ context: 'table_element/',
469
+ },
470
+ {
471
+ tag: 'caption',
472
+ node: 'figcaption',
473
+ context: 'box_element/',
474
+ getAttrs: (node) => {
475
+ const element = node;
476
+ return {
477
+ id: element.getAttribute('id'),
478
+ };
479
+ },
480
+ },
481
+ {
482
+ tag: 'code',
483
+ node: 'listing',
484
+ context: 'listing_element/',
485
+ getAttrs: (node) => {
486
+ var _a;
487
+ const element = node;
488
+ return {
489
+ id: element.getAttribute('id'),
490
+ language: (_a = element.getAttribute('language')) !== null && _a !== void 0 ? _a : '',
491
+ contents: (0, utils_1.getTrimmedTextContent)(element),
492
+ };
493
+ },
494
+ },
495
+ {
496
+ tag: 'inline-formula',
497
+ node: 'inline_equation',
498
+ getAttrs: (node) => {
499
+ const element = node;
500
+ return this.getEquationContent(element);
501
+ },
502
+ },
503
+ {
504
+ tag: 'disp-formula',
505
+ node: 'equation_element',
506
+ getAttrs: (node) => {
507
+ var _a;
508
+ const element = node;
509
+ return {
510
+ id: element.getAttribute('id'),
511
+ label: (_a = (0, utils_1.getTrimmedTextContent)(element, 'label')) !== null && _a !== void 0 ? _a : '',
512
+ };
513
+ },
514
+ getContent: (node, schema) => {
515
+ const element = node;
516
+ const attrs = this.getEquationContent(element);
517
+ return prosemirror_model_1.Fragment.from([
518
+ schema.nodes.equation.createChecked(Object.assign({}, attrs)),
519
+ ]);
520
+ },
521
+ },
522
+ {
523
+ tag: 'disp-quote[content-type=quote]',
524
+ node: 'blockquote_element',
525
+ getAttrs: (node) => {
526
+ const element = node;
527
+ return {
528
+ id: element.getAttribute('id'),
529
+ };
530
+ },
531
+ },
532
+ {
533
+ tag: 'disp-quote[content-type=pullquote]',
534
+ node: 'pullquote_element',
535
+ getAttrs: (node) => {
536
+ const element = node;
537
+ return {
538
+ id: element.getAttribute('id'),
539
+ };
540
+ },
541
+ },
542
+ {
543
+ tag: 'ext-link',
544
+ node: 'link',
545
+ getAttrs: (node) => {
546
+ const element = node;
547
+ return {
548
+ href: element.getAttributeNS(this.XLINK_NAMESPACE, 'href') || '',
549
+ title: element.getAttributeNS(this.XLINK_NAMESPACE, 'title') || '',
550
+ };
551
+ },
552
+ },
553
+ {
554
+ tag: 'fig[fig-type=equation]',
555
+ node: 'equation_element',
556
+ getAttrs: (node) => {
557
+ const element = node;
558
+ return {
559
+ id: element.getAttribute('id'),
560
+ };
561
+ },
562
+ },
563
+ {
564
+ tag: 'fig[fig-type=listing]',
565
+ node: 'listing_element',
566
+ getAttrs: (node) => {
567
+ const element = node;
568
+ return {
569
+ id: element.getAttribute('id'),
570
+ };
571
+ },
572
+ },
573
+ {
574
+ tag: 'graphic[specific-use=MISSING]',
575
+ node: 'missing_figure',
576
+ context: 'figure_element/',
577
+ getAttrs: (node) => {
578
+ const element = node;
579
+ return {
580
+ id: element.getAttribute('id'),
581
+ };
582
+ },
583
+ },
584
+ {
585
+ tag: 'graphic',
586
+ node: 'figure',
587
+ context: 'figure_element/',
588
+ getAttrs: (node) => {
589
+ const element = node;
590
+ const position = element.getAttribute('position');
591
+ const src = element.getAttributeNS(this.XLINK_NAMESPACE, 'href');
592
+ return {
593
+ id: element.getAttribute('id'),
594
+ contentType: this.chooseContentType(element || undefined) || '',
595
+ src,
596
+ position,
597
+ };
598
+ },
599
+ },
600
+ {
601
+ tag: 'fig',
602
+ node: 'figure_element',
603
+ getAttrs: (node) => {
604
+ var _a, _b;
605
+ const element = node;
606
+ const labelNode = element.querySelector('label');
607
+ if (labelNode) {
608
+ element.removeChild(labelNode);
609
+ }
610
+ const attrib = element.querySelector('attrib');
611
+ const position = element.getAttribute('position');
612
+ const attribution = attrib
613
+ ? {
614
+ literal: (_a = (0, utils_1.getTrimmedTextContent)(attrib)) !== null && _a !== void 0 ? _a : '',
615
+ }
616
+ : undefined;
617
+ return {
618
+ id: element.getAttribute('id'),
619
+ label: (_b = (0, utils_1.getTrimmedTextContent)(labelNode)) !== null && _b !== void 0 ? _b : '',
620
+ attribution: attribution,
621
+ position,
622
+ };
623
+ },
624
+ },
625
+ {
626
+ tag: 'fn-group',
627
+ node: 'footnotes_element',
628
+ context: 'footnotes_section/|table_element_footer/',
629
+ getAttrs: (node) => {
630
+ const element = node;
631
+ return {
632
+ id: element.getAttribute('id'),
633
+ kind: 'footnote',
634
+ };
635
+ },
636
+ },
637
+ {
638
+ tag: 'table-wrap-foot',
639
+ node: 'table_element_footer',
640
+ getAttrs: (node) => {
641
+ const element = node;
642
+ return {
643
+ id: element.getAttribute('id'),
644
+ };
645
+ },
646
+ },
647
+ {
648
+ tag: 'general-table-footnote',
649
+ node: 'general_table_footnote',
650
+ context: 'table_element_footer/',
651
+ getAttrs: (node) => {
652
+ const element = node;
653
+ return {
654
+ id: element.getAttribute('id'),
655
+ };
656
+ },
657
+ getContent: (node) => {
658
+ const paragraphs = [];
659
+ node.childNodes.forEach((p) => {
660
+ const paragraph = this.schema.nodes.paragraph.create();
661
+ const content = this.parse(p, {
662
+ topNode: paragraph,
663
+ });
664
+ paragraphs.push(content);
665
+ });
666
+ return prosemirror_model_1.Fragment.from([...paragraphs]);
667
+ },
668
+ },
669
+ {
670
+ tag: 'fn',
671
+ node: 'footnote',
672
+ context: 'footnotes_element/|table_element_footer/',
673
+ getAttrs: (node) => {
674
+ const element = node;
675
+ return {
676
+ id: element.getAttribute('id'),
677
+ kind: 'footnote',
678
+ };
679
+ },
680
+ },
681
+ {
682
+ tag: 'front',
683
+ ignore: true,
684
+ },
685
+ {
686
+ tag: 'list',
687
+ node: 'list',
688
+ getAttrs: (node) => {
689
+ const element = node;
690
+ return {
691
+ id: element.getAttribute('id'),
692
+ listStyleType: element.getAttribute('list-type'),
693
+ };
694
+ },
695
+ },
696
+ {
697
+ tag: 'list-item',
698
+ node: 'list_item',
699
+ },
700
+ {
701
+ tag: 'p',
702
+ node: 'paragraph',
703
+ context: 'section/',
704
+ getAttrs: (node) => {
705
+ const element = node;
706
+ return {
707
+ id: element.getAttribute('id'),
708
+ };
709
+ },
710
+ },
711
+ {
712
+ tag: 'p',
713
+ node: 'paragraph',
714
+ },
715
+ {
716
+ tag: 'sec[sec-type="endnotes"]',
717
+ node: 'footnotes_section',
718
+ getAttrs: (node) => {
719
+ const element = node;
720
+ return {
721
+ id: element.getAttribute('id'),
722
+ };
723
+ },
724
+ },
725
+ {
726
+ tag: 'sec[sec-type="keywords"]',
727
+ node: 'keywords',
728
+ },
729
+ {
730
+ tag: 'sec[sec-type="supplementary-material"]',
731
+ node: 'supplements',
732
+ },
733
+ {
734
+ tag: 'supplementary-material',
735
+ node: 'supplement',
736
+ getAttrs: (node) => {
737
+ const element = node;
738
+ return {
739
+ id: element.getAttribute('id'),
740
+ href: element.getAttributeNS(this.XLINK_NAMESPACE, 'href'),
741
+ mimeType: element.getAttribute('mimetype'),
742
+ mimeSubType: element.getAttribute('mime-subtype'),
743
+ title: (0, utils_1.getTrimmedTextContent)(element, 'title'),
744
+ };
745
+ },
746
+ },
747
+ {
748
+ tag: 'sec[sec-type="abstracts"]',
749
+ node: 'abstracts',
750
+ },
751
+ {
752
+ tag: 'sec[sec-type="body"]',
753
+ node: 'body',
754
+ },
755
+ {
756
+ tag: 'sec[sec-type="backmatter"]',
757
+ node: 'backmatter',
758
+ },
759
+ {
760
+ tag: 'sec[sec-type="box-element"]',
761
+ node: 'box_element',
762
+ getAttrs: (node) => {
763
+ const element = node;
764
+ return {
765
+ id: element.getAttribute('id'),
766
+ label: (0, utils_1.getTrimmedTextContent)(element, 'label'),
767
+ };
768
+ },
769
+ },
770
+ {
771
+ tag: 'sec[sec-type="bibliography"]',
772
+ node: 'bibliography_section',
773
+ },
774
+ {
775
+ tag: 'ref-list',
776
+ context: 'bibliography_section/',
777
+ node: 'bibliography_element',
778
+ },
779
+ {
780
+ tag: 'ref',
781
+ context: 'bibliography_element/',
782
+ node: 'bibliography_item',
783
+ getAttrs: (node) => this.parseRef(node),
784
+ },
785
+ {
786
+ tag: 'sec',
787
+ node: 'section',
788
+ getAttrs: (node) => {
789
+ const element = node;
790
+ return {
791
+ id: element.getAttribute('id'),
792
+ category: this.chooseSectionCategory(element),
793
+ };
794
+ },
795
+ },
796
+ {
797
+ tag: 'kwd-group-list',
798
+ context: 'keywords/',
799
+ node: 'keywords_element',
800
+ },
801
+ {
802
+ tag: 'kwd-group',
803
+ context: 'keywords_element/',
804
+ node: 'keyword_group',
805
+ getAttrs: (node) => {
806
+ const element = node;
807
+ return {
808
+ id: element.id,
809
+ type: element.getAttribute('kwd-group-type'),
810
+ };
811
+ },
812
+ },
813
+ {
814
+ tag: 'kwd',
815
+ context: 'keyword_group//',
816
+ node: 'keyword',
817
+ },
818
+ {
819
+ tag: 'label',
820
+ context: 'box_element/',
821
+ ignore: true,
822
+ },
823
+ {
824
+ tag: 'boxed-text',
825
+ ignore: true,
826
+ },
827
+ {
828
+ tag: 'label',
829
+ context: 'section/',
830
+ node: 'section_label',
831
+ },
832
+ {
833
+ tag: 'label',
834
+ context: 'table_element/',
835
+ ignore: true,
836
+ },
837
+ {
838
+ tag: 'label',
839
+ context: 'figure/',
840
+ ignore: true,
841
+ },
842
+ {
843
+ tag: 'table',
844
+ node: 'table',
845
+ getAttrs: (node) => {
846
+ const element = node;
847
+ return {
848
+ id: element.getAttribute('id'),
849
+ };
850
+ },
851
+ },
852
+ {
853
+ tag: 'table-wrap',
854
+ node: 'table_element',
855
+ getAttrs: (node) => {
856
+ const element = node;
857
+ return {
858
+ id: element.getAttribute('id'),
859
+ };
860
+ },
861
+ },
862
+ {
863
+ tag: 'title',
864
+ node: 'section_title',
865
+ context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/|author_notes/',
866
+ },
867
+ {
868
+ tag: 'title',
869
+ node: 'caption_title',
870
+ context: 'figcaption/',
871
+ },
872
+ {
873
+ tag: 'tr',
874
+ node: 'table_row',
875
+ },
876
+ {
877
+ tag: 'td',
878
+ node: 'table_cell',
879
+ getAttrs: (node) => {
880
+ const element = node;
881
+ const colspan = parseInt(element.getAttribute('colspan') || '1');
882
+ const rowspan = parseInt(element.getAttribute('rowspan') || '1');
883
+ return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
884
+ },
885
+ },
886
+ {
887
+ tag: 'th',
888
+ node: 'table_header',
889
+ getAttrs: (node) => {
890
+ const element = node;
891
+ const colspan = parseInt(element.getAttribute('colspan') || '1');
892
+ const rowspan = parseInt(element.getAttribute('rowspan') || '1');
893
+ return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
894
+ },
895
+ },
896
+ {
897
+ tag: 'col',
898
+ node: 'table_col',
899
+ getAttrs: (node) => {
900
+ const element = node;
901
+ return {
902
+ width: element.getAttribute('width'),
903
+ };
904
+ },
905
+ },
906
+ {
907
+ tag: 'colgroup',
908
+ node: 'table_colgroup',
909
+ },
910
+ {
911
+ tag: 'xref[ref-type="bibr"]',
912
+ node: 'citation',
913
+ getAttrs: (node) => {
914
+ var _a;
915
+ const element = node;
916
+ return {
917
+ rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
918
+ contents: (0, utils_1.getTrimmedTextContent)(element),
919
+ };
920
+ },
921
+ },
922
+ {
923
+ tag: 'xref[ref-type="fn"]',
924
+ node: 'inline_footnote',
925
+ getAttrs: (node) => {
926
+ var _a;
927
+ const element = node;
928
+ return {
929
+ rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
930
+ };
931
+ },
932
+ },
933
+ {
934
+ tag: 'xref',
935
+ node: 'cross_reference',
936
+ getAttrs: (node) => {
937
+ var _a;
938
+ const element = node;
939
+ return {
940
+ rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
941
+ label: (0, utils_1.getTrimmedTextContent)(element),
942
+ };
943
+ },
944
+ },
945
+ ];
946
+ this.marks = [
947
+ {
948
+ tag: 'bold',
949
+ mark: 'bold',
950
+ },
951
+ {
952
+ tag: 'code',
953
+ mark: 'code',
954
+ },
955
+ {
956
+ tag: 'italic',
957
+ mark: 'italic',
958
+ },
959
+ {
960
+ tag: 'sc',
961
+ mark: 'smallcaps',
962
+ },
963
+ {
964
+ tag: 'strike',
965
+ mark: 'strikethrough',
966
+ },
967
+ {
968
+ tag: 'styled-content',
969
+ mark: 'styled',
970
+ getAttrs: (node) => ({
971
+ style: node.getAttribute('style'),
972
+ }),
973
+ },
974
+ {
975
+ tag: 'sub',
976
+ mark: 'subscript',
977
+ },
978
+ {
979
+ tag: 'sup',
980
+ mark: 'superscript',
981
+ },
982
+ {
983
+ tag: 'underline',
984
+ mark: 'underline',
985
+ },
986
+ ];
987
+ this.parser = new prosemirror_model_1.DOMParser(this.schema, [...this.marks, ...this.nodes]);
988
+ }
989
+ parse(doc, options) {
990
+ return this.parser.parse(doc, options);
991
+ }
992
+ isMatchingCategory(secType, titleNode, category) {
993
+ if (secType && category.synonyms.includes(secType)) {
994
+ return true;
995
+ }
996
+ if (titleNode && titleNode.nodeName === 'title' && titleNode.textContent) {
997
+ const textContent = titleNode.textContent.trim().toLowerCase();
998
+ if (category.synonyms.includes(textContent)) {
999
+ return true;
1000
+ }
1001
+ }
1002
+ return false;
1003
+ }
1004
+ chooseSectionCategory(section) {
1005
+ const secType = section.getAttribute('sec-type');
1006
+ const titleNode = section.firstElementChild;
1007
+ for (const category of this.sectionCategories) {
1008
+ if (this.isMatchingCategory(secType, titleNode, category)) {
1009
+ return category.id;
1010
+ }
1011
+ }
1012
+ }
1013
+ }
1014
+ exports.JATSDOMParser = JATSDOMParser;