@manuscripts/transform 3.0.21-LEAN-4076.1 → 3.0.21

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 (40) 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 +972 -948
  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/index.js +0 -2
  8. package/dist/cjs/schema/migration/migration-scripts/3.0.21.js +25 -0
  9. package/dist/cjs/schema/migration/migration-scripts/index.js +2 -0
  10. package/dist/cjs/transformer/index.js +0 -1
  11. package/dist/cjs/version.js +1 -1
  12. package/dist/es/index.js +1 -2
  13. package/dist/es/jats/exporter/jats-exporter.js +8 -8
  14. package/dist/es/jats/importer/jats-dom-parser.js +970 -947
  15. package/dist/es/jats/importer/jats-transformations.js +9 -14
  16. package/dist/es/jats/importer/parse-jats-article.js +8 -6
  17. package/dist/es/lib/{section-group-type.js → section-categories.js} +2 -13
  18. package/dist/es/schema/index.js +0 -2
  19. package/dist/es/schema/migration/migration-scripts/3.0.21.js +23 -0
  20. package/dist/es/schema/migration/migration-scripts/index.js +2 -0
  21. package/dist/es/transformer/index.js +0 -1
  22. package/dist/es/version.js +1 -1
  23. package/dist/types/index.d.ts +1 -2
  24. package/dist/types/jats/importer/jats-dom-parser.d.ts +24 -9
  25. package/dist/types/jats/importer/jats-transformations.d.ts +2 -1
  26. package/dist/types/jats/importer/parse-jats-article.d.ts +2 -2
  27. package/dist/types/lib/{section-group-type.d.ts → section-categories.d.ts} +3 -9
  28. package/dist/types/schema/index.d.ts +0 -2
  29. package/dist/types/schema/migration/migration-scripts/3.0.21.d.ts +9 -0
  30. package/dist/types/schema/migration/migration-scripts/index.d.ts +2 -1
  31. package/dist/types/schema/types.d.ts +21 -1
  32. package/dist/types/transformer/index.d.ts +0 -1
  33. package/dist/types/version.d.ts +1 -1
  34. package/package.json +1 -1
  35. package/dist/cjs/lib/table-cell-styles.js +0 -52
  36. package/dist/cjs/transformer/section-category.js +0 -263
  37. package/dist/es/lib/table-cell-styles.js +0 -47
  38. package/dist/es/transformer/section-category.js +0 -249
  39. package/dist/types/lib/table-cell-styles.d.ts +0 -27
  40. package/dist/types/transformer/section-category.d.ts +0 -31
@@ -18,976 +18,1000 @@ 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 attribution = attrib
651
- ? {
652
- literal: (_a = (0, utils_1.getTrimmedTextContent)(attrib)) !== null && _a !== void 0 ? _a : '',
653
- }
654
- : undefined;
655
- return {
656
- id: element.getAttribute('id'),
657
- label: (_b = (0, utils_1.getTrimmedTextContent)(labelNode)) !== null && _b !== void 0 ? _b : '',
658
- attribution,
659
- type: element.getAttribute('fig-type'),
660
- };
661
- },
662
- },
663
- {
664
- tag: 'fn-group',
665
- node: 'footnotes_element',
666
- context: 'footnotes_section/|table_element_footer/',
667
- getAttrs: (node) => {
668
- const element = node;
669
- return {
670
- id: element.getAttribute('id'),
671
- kind: 'footnote',
672
- };
673
- },
674
- },
675
- {
676
- tag: 'table-wrap-foot',
677
- node: 'table_element_footer',
678
- getAttrs: (node) => {
679
- const element = node;
680
- return {
681
- id: element.getAttribute('id'),
682
- };
683
- },
684
- },
685
- {
686
- tag: 'general-table-footnote',
687
- node: 'general_table_footnote',
688
- context: 'table_element_footer/',
689
- getAttrs: (node) => {
690
- const element = node;
691
- return {
692
- id: element.getAttribute('id'),
693
- };
694
- },
695
- getContent: (node) => {
696
- const paragraphs = [];
697
- node.childNodes.forEach((p) => {
698
- const paragraph = schema_1.schema.nodes.paragraph.create();
699
- const content = exports.jatsDOMParser.parse(p, {
700
- 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]],
701
204
  });
702
- 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);
703
225
  });
704
- return prosemirror_model_1.Fragment.from([...paragraphs]);
705
- },
706
- },
707
- {
708
- tag: 'fn',
709
- node: 'footnote',
710
- context: 'footnotes_element/|table_element_footer/',
711
- getAttrs: (node) => {
712
- const element = node;
713
- return {
714
- id: element.getAttribute('id'),
715
- kind: 'footnote',
716
- };
717
- },
718
- },
719
- {
720
- tag: 'front',
721
- ignore: true,
722
- },
723
- {
724
- tag: 'list',
725
- node: 'list',
726
- getAttrs: (node) => {
727
- const element = node;
728
- return {
729
- id: element.getAttribute('id'),
730
- listStyleType: element.getAttribute('list-type'),
731
- };
732
- },
733
- },
734
- {
735
- tag: 'list-item',
736
- node: 'list_item',
737
- },
738
- {
739
- tag: 'p',
740
- node: 'paragraph',
741
- context: 'section/',
742
- getAttrs: (node) => {
743
- const element = node;
744
- return {
745
- id: element.getAttribute('id'),
746
- };
747
- },
748
- },
749
- {
750
- tag: 'p',
751
- node: 'paragraph',
752
- },
753
- {
754
- tag: 'sec[sec-type="endnotes"]',
755
- node: 'footnotes_section',
756
- getAttrs: (node) => {
757
- const element = node;
758
- return {
759
- id: element.getAttribute('id'),
760
- };
761
- },
762
- },
763
- {
764
- tag: 'sec[sec-type="keywords"]',
765
- node: 'keywords',
766
- },
767
- {
768
- tag: 'sec[sec-type="supplementary-material"]',
769
- node: 'supplements',
770
- },
771
- {
772
- tag: 'supplementary-material',
773
- node: 'supplement',
774
- getAttrs: (node) => {
775
- const element = node;
776
- return {
777
- id: element.getAttribute('id'),
778
- href: element.getAttributeNS(XLINK_NAMESPACE, 'href'),
779
- mimeType: element.getAttribute('mimetype'),
780
- mimeSubType: element.getAttribute('mime-subtype'),
781
- title: (0, utils_1.getTrimmedTextContent)(element, 'title'),
782
- };
783
- },
784
- },
785
- {
786
- tag: 'sec[sec-type="abstracts"]',
787
- node: 'abstracts',
788
- },
789
- {
790
- tag: 'sec[sec-type="body"]',
791
- node: 'body',
792
- },
793
- {
794
- tag: 'sec[sec-type="backmatter"]',
795
- node: 'backmatter',
796
- },
797
- {
798
- tag: 'sec[sec-type="box-element"]',
799
- node: 'box_element',
800
- getAttrs: (node) => {
801
- const element = node;
802
- return {
803
- id: element.getAttribute('id'),
804
- label: (0, utils_1.getTrimmedTextContent)(element, 'label'),
805
- };
806
- },
807
- },
808
- {
809
- tag: 'sec[sec-type="bibliography"]',
810
- node: 'bibliography_section',
811
- },
812
- {
813
- tag: 'ref-list',
814
- context: 'bibliography_section/',
815
- node: 'bibliography_element',
816
- },
817
- {
818
- tag: 'ref',
819
- context: 'bibliography_element/',
820
- node: 'bibliography_item',
821
- getAttrs: (node) => parseRef(node),
822
- },
823
- {
824
- tag: 'sec[sec-type="abstract-graphical"]',
825
- node: 'graphical_abstract_section',
826
- },
827
- {
828
- tag: 'sec',
829
- node: 'section',
830
- getAttrs: (node) => {
831
- var _a, _b;
832
- const element = node;
833
- const grandParentNodeName = (_b = (_a = element.parentNode) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.nodeName.toLowerCase();
834
- if (grandParentNodeName && grandParentNodeName !== 'body') {
835
- element.setAttribute('sec-type', 'subsection');
226
+ if (authors.length) {
227
+ attrs.author = authors;
836
228
  }
837
- return {
838
- id: element.getAttribute('id'),
839
- category: (0, transformer_1.chooseSectionCategory)(element),
840
- };
841
- },
842
- },
843
- {
844
- tag: 'kwd-group-list',
845
- context: 'keywords/',
846
- node: 'keywords_element',
847
- },
848
- {
849
- tag: 'kwd-group',
850
- context: 'keywords_element/',
851
- node: 'keyword_group',
852
- getAttrs: (node) => {
853
- const element = node;
854
- return {
855
- id: element.id,
856
- type: element.getAttribute('kwd-group-type'),
857
- };
858
- },
859
- },
860
- {
861
- tag: 'kwd',
862
- context: 'keyword_group//',
863
- node: 'keyword',
864
- },
865
- {
866
- tag: 'label',
867
- context: 'box_element/',
868
- ignore: true,
869
- },
870
- {
871
- tag: 'boxed-text',
872
- ignore: true,
873
- },
874
- {
875
- tag: 'label',
876
- context: 'section/',
877
- node: 'section_label',
878
- },
879
- {
880
- tag: 'label',
881
- context: 'table_element/',
882
- ignore: true,
883
- },
884
- {
885
- tag: 'label',
886
- context: 'figure/',
887
- ignore: true,
888
- },
889
- {
890
- tag: 'table',
891
- node: 'table',
892
- getAttrs: (node) => {
893
- const element = node;
894
- return {
895
- id: element.getAttribute('id'),
896
- };
897
- },
898
- },
899
- {
900
- tag: 'table-wrap',
901
- node: 'table_element',
902
- getAttrs: (node) => {
903
- const element = node;
904
- return {
905
- id: element.getAttribute('id'),
906
- };
907
- },
908
- },
909
- {
910
- tag: 'title',
911
- node: 'section_title',
912
- context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/|author_notes/|graphical_abstract_section/',
913
- },
914
- {
915
- tag: 'title',
916
- node: 'caption_title',
917
- context: 'figcaption/',
918
- },
919
- {
920
- tag: 'tr',
921
- node: 'table_row',
922
- },
923
- {
924
- tag: 'td',
925
- node: 'table_cell',
926
- getAttrs: (node) => {
927
- const element = node;
928
- const colspan = parseInt(element.getAttribute('colspan') || '1');
929
- const rowspan = parseInt(element.getAttribute('rowspan') || '1');
930
- 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') });
931
- },
932
- },
933
- {
934
- tag: 'th',
935
- node: 'table_header',
936
- getAttrs: (node) => {
937
- const element = node;
938
- const colspan = parseInt(element.getAttribute('colspan') || '1');
939
- const rowspan = parseInt(element.getAttribute('rowspan') || '1');
940
- 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') });
941
- },
942
- },
943
- {
944
- tag: 'col',
945
- node: 'table_col',
946
- getAttrs: (node) => {
947
- const element = node;
948
- return {
949
- width: element.getAttribute('width'),
950
- };
951
- },
952
- },
953
- {
954
- tag: 'colgroup',
955
- node: 'table_colgroup',
956
- },
957
- {
958
- tag: 'xref[ref-type="bibr"]',
959
- node: 'citation',
960
- getAttrs: (node) => {
961
- var _a;
962
- const element = node;
963
- return {
964
- rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
965
- contents: (0, utils_1.getTrimmedTextContent)(element),
966
- };
967
- },
968
- },
969
- {
970
- tag: 'xref[ref-type="fn"]',
971
- node: 'inline_footnote',
972
- getAttrs: (node) => {
973
- var _a;
974
- const element = node;
975
- return {
976
- rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
977
- };
978
- },
979
- },
980
- {
981
- tag: 'xref',
982
- node: 'cross_reference',
983
- getAttrs: (node) => {
984
- var _a;
985
- const element = node;
986
- return {
987
- rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
988
- label: (0, utils_1.getTrimmedTextContent)(element),
989
- };
990
- },
991
- },
992
- ];
993
- 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 attribution = attrib
612
+ ? {
613
+ literal: (_a = (0, utils_1.getTrimmedTextContent)(attrib)) !== null && _a !== void 0 ? _a : '',
614
+ }
615
+ : undefined;
616
+ return {
617
+ id: element.getAttribute('id'),
618
+ label: (_b = (0, utils_1.getTrimmedTextContent)(labelNode)) !== null && _b !== void 0 ? _b : '',
619
+ attribution,
620
+ type: element.getAttribute('fig-type'),
621
+ };
622
+ },
623
+ },
624
+ {
625
+ tag: 'fn-group',
626
+ node: 'footnotes_element',
627
+ context: 'footnotes_section/|table_element_footer/',
628
+ getAttrs: (node) => {
629
+ const element = node;
630
+ return {
631
+ id: element.getAttribute('id'),
632
+ kind: 'footnote',
633
+ };
634
+ },
635
+ },
636
+ {
637
+ tag: 'table-wrap-foot',
638
+ node: 'table_element_footer',
639
+ getAttrs: (node) => {
640
+ const element = node;
641
+ return {
642
+ id: element.getAttribute('id'),
643
+ };
644
+ },
645
+ },
646
+ {
647
+ tag: 'general-table-footnote',
648
+ node: 'general_table_footnote',
649
+ context: 'table_element_footer/',
650
+ getAttrs: (node) => {
651
+ const element = node;
652
+ return {
653
+ id: element.getAttribute('id'),
654
+ };
655
+ },
656
+ getContent: (node) => {
657
+ const paragraphs = [];
658
+ node.childNodes.forEach((p) => {
659
+ const paragraph = this.schema.nodes.paragraph.create();
660
+ const content = this.parse(p, {
661
+ topNode: paragraph,
662
+ });
663
+ paragraphs.push(content);
664
+ });
665
+ return prosemirror_model_1.Fragment.from([...paragraphs]);
666
+ },
667
+ },
668
+ {
669
+ tag: 'fn',
670
+ node: 'footnote',
671
+ context: 'footnotes_element/|table_element_footer/',
672
+ getAttrs: (node) => {
673
+ const element = node;
674
+ return {
675
+ id: element.getAttribute('id'),
676
+ kind: 'footnote',
677
+ };
678
+ },
679
+ },
680
+ {
681
+ tag: 'front',
682
+ ignore: true,
683
+ },
684
+ {
685
+ tag: 'list',
686
+ node: 'list',
687
+ getAttrs: (node) => {
688
+ const element = node;
689
+ return {
690
+ id: element.getAttribute('id'),
691
+ listStyleType: element.getAttribute('list-type'),
692
+ };
693
+ },
694
+ },
695
+ {
696
+ tag: 'list-item',
697
+ node: 'list_item',
698
+ },
699
+ {
700
+ tag: 'p',
701
+ node: 'paragraph',
702
+ context: 'section/',
703
+ getAttrs: (node) => {
704
+ const element = node;
705
+ return {
706
+ id: element.getAttribute('id'),
707
+ };
708
+ },
709
+ },
710
+ {
711
+ tag: 'p',
712
+ node: 'paragraph',
713
+ },
714
+ {
715
+ tag: 'sec[sec-type="endnotes"]',
716
+ node: 'footnotes_section',
717
+ getAttrs: (node) => {
718
+ const element = node;
719
+ return {
720
+ id: element.getAttribute('id'),
721
+ };
722
+ },
723
+ },
724
+ {
725
+ tag: 'sec[sec-type="keywords"]',
726
+ node: 'keywords',
727
+ },
728
+ {
729
+ tag: 'sec[sec-type="supplementary-material"]',
730
+ node: 'supplements',
731
+ },
732
+ {
733
+ tag: 'supplementary-material',
734
+ node: 'supplement',
735
+ getAttrs: (node) => {
736
+ const element = node;
737
+ return {
738
+ id: element.getAttribute('id'),
739
+ href: element.getAttributeNS(this.XLINK_NAMESPACE, 'href'),
740
+ mimeType: element.getAttribute('mimetype'),
741
+ mimeSubType: element.getAttribute('mime-subtype'),
742
+ title: (0, utils_1.getTrimmedTextContent)(element, 'title'),
743
+ };
744
+ },
745
+ },
746
+ {
747
+ tag: 'sec[sec-type="abstracts"]',
748
+ node: 'abstracts',
749
+ },
750
+ {
751
+ tag: 'sec[sec-type="body"]',
752
+ node: 'body',
753
+ },
754
+ {
755
+ tag: 'sec[sec-type="backmatter"]',
756
+ node: 'backmatter',
757
+ },
758
+ {
759
+ tag: 'sec[sec-type="box-element"]',
760
+ node: 'box_element',
761
+ getAttrs: (node) => {
762
+ const element = node;
763
+ return {
764
+ id: element.getAttribute('id'),
765
+ label: (0, utils_1.getTrimmedTextContent)(element, 'label'),
766
+ };
767
+ },
768
+ },
769
+ {
770
+ tag: 'sec[sec-type="bibliography"]',
771
+ node: 'bibliography_section',
772
+ },
773
+ {
774
+ tag: 'ref-list',
775
+ context: 'bibliography_section/',
776
+ node: 'bibliography_element',
777
+ },
778
+ {
779
+ tag: 'ref',
780
+ context: 'bibliography_element/',
781
+ node: 'bibliography_item',
782
+ getAttrs: (node) => this.parseRef(node),
783
+ },
784
+ {
785
+ tag: 'sec[sec-type="abstract-graphical"]',
786
+ node: 'graphical_abstract_section',
787
+ },
788
+ {
789
+ tag: 'sec',
790
+ node: 'section',
791
+ getAttrs: (node) => {
792
+ const element = node;
793
+ return {
794
+ id: element.getAttribute('id'),
795
+ category: this.chooseSectionCategory(element),
796
+ };
797
+ },
798
+ },
799
+ {
800
+ tag: 'kwd-group-list',
801
+ context: 'keywords/',
802
+ node: 'keywords_element',
803
+ },
804
+ {
805
+ tag: 'kwd-group',
806
+ context: 'keywords_element/',
807
+ node: 'keyword_group',
808
+ getAttrs: (node) => {
809
+ const element = node;
810
+ return {
811
+ id: element.id,
812
+ type: element.getAttribute('kwd-group-type'),
813
+ };
814
+ },
815
+ },
816
+ {
817
+ tag: 'kwd',
818
+ context: 'keyword_group//',
819
+ node: 'keyword',
820
+ },
821
+ {
822
+ tag: 'label',
823
+ context: 'box_element/',
824
+ ignore: true,
825
+ },
826
+ {
827
+ tag: 'boxed-text',
828
+ ignore: true,
829
+ },
830
+ {
831
+ tag: 'label',
832
+ context: 'section/',
833
+ node: 'section_label',
834
+ },
835
+ {
836
+ tag: 'label',
837
+ context: 'table_element/',
838
+ ignore: true,
839
+ },
840
+ {
841
+ tag: 'label',
842
+ context: 'figure/',
843
+ ignore: true,
844
+ },
845
+ {
846
+ tag: 'table',
847
+ node: 'table',
848
+ getAttrs: (node) => {
849
+ const element = node;
850
+ return {
851
+ id: element.getAttribute('id'),
852
+ };
853
+ },
854
+ },
855
+ {
856
+ tag: 'table-wrap',
857
+ node: 'table_element',
858
+ getAttrs: (node) => {
859
+ const element = node;
860
+ return {
861
+ id: element.getAttribute('id'),
862
+ };
863
+ },
864
+ },
865
+ {
866
+ tag: 'title',
867
+ node: 'section_title',
868
+ context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/|author_notes/|graphical_abstract_section/',
869
+ },
870
+ {
871
+ tag: 'title',
872
+ node: 'caption_title',
873
+ context: 'figcaption/',
874
+ },
875
+ {
876
+ tag: 'tr',
877
+ node: 'table_row',
878
+ },
879
+ {
880
+ tag: 'td',
881
+ node: 'table_cell',
882
+ getAttrs: (node) => {
883
+ const element = node;
884
+ const colspan = parseInt(element.getAttribute('colspan') || '1');
885
+ const rowspan = parseInt(element.getAttribute('rowspan') || '1');
886
+ 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') });
887
+ },
888
+ },
889
+ {
890
+ tag: 'th',
891
+ node: 'table_header',
892
+ getAttrs: (node) => {
893
+ const element = node;
894
+ const colspan = parseInt(element.getAttribute('colspan') || '1');
895
+ const rowspan = parseInt(element.getAttribute('rowspan') || '1');
896
+ 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') });
897
+ },
898
+ },
899
+ {
900
+ tag: 'col',
901
+ node: 'table_col',
902
+ getAttrs: (node) => {
903
+ const element = node;
904
+ return {
905
+ width: element.getAttribute('width'),
906
+ };
907
+ },
908
+ },
909
+ {
910
+ tag: 'colgroup',
911
+ node: 'table_colgroup',
912
+ },
913
+ {
914
+ tag: 'xref[ref-type="bibr"]',
915
+ node: 'citation',
916
+ getAttrs: (node) => {
917
+ var _a;
918
+ const element = node;
919
+ return {
920
+ rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
921
+ contents: (0, utils_1.getTrimmedTextContent)(element),
922
+ };
923
+ },
924
+ },
925
+ {
926
+ tag: 'xref[ref-type="fn"]',
927
+ node: 'inline_footnote',
928
+ getAttrs: (node) => {
929
+ var _a;
930
+ const element = node;
931
+ return {
932
+ rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
933
+ };
934
+ },
935
+ },
936
+ {
937
+ tag: 'xref',
938
+ node: 'cross_reference',
939
+ getAttrs: (node) => {
940
+ var _a;
941
+ const element = node;
942
+ return {
943
+ rids: ((_a = element.getAttribute('rid')) === null || _a === void 0 ? void 0 : _a.split(/\s+/)) || [],
944
+ label: (0, utils_1.getTrimmedTextContent)(element),
945
+ };
946
+ },
947
+ },
948
+ ];
949
+ this.marks = [
950
+ {
951
+ tag: 'bold',
952
+ mark: 'bold',
953
+ },
954
+ {
955
+ tag: 'code',
956
+ mark: 'code',
957
+ },
958
+ {
959
+ tag: 'italic',
960
+ mark: 'italic',
961
+ },
962
+ {
963
+ tag: 'sc',
964
+ mark: 'smallcaps',
965
+ },
966
+ {
967
+ tag: 'strike',
968
+ mark: 'strikethrough',
969
+ },
970
+ {
971
+ tag: 'styled-content',
972
+ mark: 'styled',
973
+ getAttrs: (node) => ({
974
+ style: node.getAttribute('style'),
975
+ }),
976
+ },
977
+ {
978
+ tag: 'sub',
979
+ mark: 'subscript',
980
+ },
981
+ {
982
+ tag: 'sup',
983
+ mark: 'superscript',
984
+ },
985
+ {
986
+ tag: 'underline',
987
+ mark: 'underline',
988
+ },
989
+ ];
990
+ this.parser = new prosemirror_model_1.DOMParser(this.schema, [...this.marks, ...this.nodes]);
991
+ }
992
+ parse(doc, options) {
993
+ return this.parser.parse(doc, options);
994
+ }
995
+ isMatchingCategory(secType, titleNode, category) {
996
+ if (secType && category.synonyms.includes(secType)) {
997
+ return true;
998
+ }
999
+ if (titleNode && titleNode.nodeName === 'title' && titleNode.textContent) {
1000
+ const textContent = titleNode.textContent.trim().toLowerCase();
1001
+ if (category.synonyms.includes(textContent)) {
1002
+ return true;
1003
+ }
1004
+ }
1005
+ return false;
1006
+ }
1007
+ chooseSectionCategory(section) {
1008
+ const secType = section.getAttribute('sec-type');
1009
+ const titleNode = section.firstElementChild;
1010
+ for (const category of this.sectionCategories) {
1011
+ if (this.isMatchingCategory(secType, titleNode, category)) {
1012
+ return category.id;
1013
+ }
1014
+ }
1015
+ }
1016
+ }
1017
+ exports.JATSDOMParser = JATSDOMParser;