@manuscripts/transform 2.3.37 → 2.3.38-LEAN-3911.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 (123) hide show
  1. package/dist/cjs/index.js +6 -6
  2. package/dist/cjs/jats/{jats-exporter.js → exporter/jats-exporter.js} +263 -390
  3. package/dist/cjs/jats/{jats-versions.js → exporter/jats-versions.js} +1 -3
  4. package/dist/cjs/{transformer → jats/exporter}/labels.js +4 -4
  5. package/dist/cjs/{transformer/filename.js → jats/importer/create-article-node.js} +10 -9
  6. package/dist/cjs/jats/importer/jats-body-transformations.js +73 -0
  7. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  8. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +281 -10
  9. package/dist/cjs/jats/importer/jats-front-transformations.js +79 -0
  10. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  11. package/dist/cjs/jats/importer/jats-parser-utils.js +43 -5
  12. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -23
  13. package/dist/cjs/jats/importer/jats-references.js +18 -18
  14. package/dist/cjs/jats/importer/parse-jats-article.js +40 -78
  15. package/dist/cjs/jats/index.js +7 -7
  16. package/dist/cjs/{transformer/models.js → lib/deafults.js} +3 -1
  17. package/dist/cjs/lib/utils.js +12 -1
  18. package/dist/cjs/transformer/id.js +10 -5
  19. package/dist/cjs/transformer/index.js +0 -18
  20. package/dist/cjs/version.js +1 -1
  21. package/dist/es/index.js +5 -5
  22. package/dist/es/jats/{jats-exporter.js → exporter/jats-exporter.js} +257 -384
  23. package/dist/es/jats/{jats-versions.js → exporter/jats-versions.js} +0 -1
  24. package/dist/es/{transformer → jats/exporter}/labels.js +4 -4
  25. package/dist/es/{transformer/filename.js → jats/importer/create-article-node.js} +8 -7
  26. package/dist/es/jats/importer/jats-body-transformations.js +73 -0
  27. package/dist/es/jats/importer/jats-comments.js +26 -101
  28. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +282 -11
  29. package/dist/es/jats/importer/jats-front-transformations.js +76 -0
  30. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  31. package/dist/es/jats/importer/jats-parser-utils.js +44 -6
  32. package/dist/es/jats/importer/jats-reference-parser.js +16 -23
  33. package/dist/es/jats/importer/jats-references.js +18 -18
  34. package/dist/es/jats/importer/parse-jats-article.js +41 -77
  35. package/dist/es/jats/index.js +5 -3
  36. package/dist/{types/transformer/timestamp.d.ts → es/lib/deafults.js} +2 -2
  37. package/dist/es/lib/utils.js +9 -0
  38. package/dist/es/transformer/id.js +8 -3
  39. package/dist/es/transformer/index.js +0 -16
  40. package/dist/es/version.js +1 -1
  41. package/dist/types/index.d.ts +6 -6
  42. package/dist/types/jats/{jats-exporter.d.ts → exporter/jats-exporter.d.ts} +15 -29
  43. package/dist/types/jats/{jats-versions.d.ts → exporter/jats-versions.d.ts} +0 -1
  44. package/dist/types/{transformer → jats/exporter}/labels.d.ts +2 -2
  45. package/dist/{es/transformer/footnote-category.js → types/jats/importer/create-article-node.d.ts} +3 -2
  46. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  47. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  48. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  49. package/dist/{cjs/transformer/serializer.js → types/jats/importer/jats-front-transformations.d.ts} +7 -8
  50. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  51. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  52. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  53. package/dist/types/jats/index.d.ts +5 -3
  54. package/dist/types/jats/types.d.ts +1 -0
  55. package/dist/{es/transformer/models.js → types/lib/deafults.d.ts} +2 -2
  56. package/dist/types/lib/utils.d.ts +2 -0
  57. package/dist/types/schema/nodes/bibliography_item.d.ts +3 -3
  58. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  59. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  60. package/dist/types/schema/nodes/manuscript.d.ts +8 -7
  61. package/dist/types/schema/nodes/title.d.ts +0 -3
  62. package/dist/types/transformer/id.d.ts +5 -2
  63. package/dist/types/transformer/index.d.ts +0 -16
  64. package/dist/types/version.d.ts +1 -1
  65. package/package.json +2 -1
  66. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  67. package/dist/cjs/jats/importer/index.js +0 -22
  68. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  69. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  70. package/dist/cjs/transformer/builders.js +0 -219
  71. package/dist/cjs/transformer/decode.js +0 -874
  72. package/dist/cjs/transformer/document-object-types.js +0 -31
  73. package/dist/cjs/transformer/encode.js +0 -664
  74. package/dist/cjs/transformer/footnote-category.js +0 -20
  75. package/dist/cjs/transformer/footnotes-order.js +0 -60
  76. package/dist/cjs/transformer/highlight-markers.js +0 -138
  77. package/dist/cjs/transformer/html.js +0 -400
  78. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  79. package/dist/cjs/transformer/model-map.js +0 -26
  80. package/dist/cjs/transformer/object-types.js +0 -57
  81. package/dist/cjs/transformer/project-bundle.js +0 -94
  82. package/dist/cjs/transformer/timestamp.js +0 -20
  83. package/dist/cjs/transformer/update-identifiers.js +0 -93
  84. package/dist/es/__tests__/data/project-dump.json +0 -825
  85. package/dist/es/jats/importer/index.js +0 -16
  86. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  87. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  88. package/dist/es/transformer/builders.js +0 -186
  89. package/dist/es/transformer/decode.js +0 -864
  90. package/dist/es/transformer/document-object-types.js +0 -28
  91. package/dist/es/transformer/encode.js +0 -654
  92. package/dist/es/transformer/footnotes-order.js +0 -55
  93. package/dist/es/transformer/highlight-markers.js +0 -132
  94. package/dist/es/transformer/html.js +0 -393
  95. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  96. package/dist/es/transformer/model-map.js +0 -22
  97. package/dist/es/transformer/object-types.js +0 -52
  98. package/dist/es/transformer/project-bundle.js +0 -85
  99. package/dist/es/transformer/serializer.js +0 -17
  100. package/dist/es/transformer/timestamp.js +0 -16
  101. package/dist/es/transformer/update-identifiers.js +0 -87
  102. package/dist/types/jats/importer/index.d.ts +0 -16
  103. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  104. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  105. package/dist/types/transformer/builders.d.ts +0 -61
  106. package/dist/types/transformer/decode.d.ts +0 -51
  107. package/dist/types/transformer/document-object-types.d.ts +0 -17
  108. package/dist/types/transformer/encode.d.ts +0 -29
  109. package/dist/types/transformer/filename.d.ts +0 -16
  110. package/dist/types/transformer/footnote-category.d.ts +0 -17
  111. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  112. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  113. package/dist/types/transformer/html.d.ts +0 -36
  114. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  115. package/dist/types/transformer/model-map.d.ts +0 -19
  116. package/dist/types/transformer/models.d.ts +0 -48
  117. package/dist/types/transformer/object-types.d.ts +0 -30
  118. package/dist/types/transformer/project-bundle.d.ts +0 -30
  119. package/dist/types/transformer/serializer.d.ts +0 -19
  120. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  121. package/dist/types/types.d.ts +0 -2
  122. /package/dist/cjs/{types.js → jats/types.js} +0 -0
  123. /package/dist/es/{types.js → jats/types.js} +0 -0
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.selectVersionIds = exports.supportedVersions = void 0;
18
+ exports.selectVersionIds = void 0;
19
19
  const versions = {
20
20
  '1.1': {
21
21
  publicId: '-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD with OASIS Tables with MathML3 v1.1 20151215//EN',
@@ -30,8 +30,6 @@ const versions = {
30
30
  systemId: 'http://jats.nlm.nih.gov/archiving/1.2/JATS-archive-oasis-article1-mathml3.dtd',
31
31
  },
32
32
  };
33
- const supportedVersions = () => Object.keys(versions);
34
- exports.supportedVersions = supportedVersions;
35
33
  const selectVersionIds = (version) => {
36
34
  if (!(version in versions)) {
37
35
  throw new Error(`Unknown version ${version}`);
@@ -16,8 +16,8 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.buildTargets = void 0;
19
- const schema_1 = require("../schema");
20
- const node_names_1 = require("./node-names");
19
+ const schema_1 = require("../../schema");
20
+ const node_names_1 = require("../../transformer/node-names");
21
21
  const labelledNodeTypes = [
22
22
  schema_1.schema.nodes.figure_element,
23
23
  schema_1.schema.nodes.table_element,
@@ -28,7 +28,7 @@ const excludedTypes = [schema_1.schema.nodes.graphical_abstract_section];
28
28
  const chooseLabel = (nodeType) => {
29
29
  return node_names_1.nodeNames.get(nodeType);
30
30
  };
31
- const buildTargets = (fragment) => {
31
+ const buildTargets = (node) => {
32
32
  const counters = {};
33
33
  for (const nodeType of labelledNodeTypes) {
34
34
  counters[nodeType.name] = {
@@ -42,7 +42,7 @@ const buildTargets = (fragment) => {
42
42
  return `${counter.label} ${counter.index}`;
43
43
  };
44
44
  const targets = new Map();
45
- fragment.descendants((node, pos, parent) => {
45
+ node.descendants((node, pos, parent) => {
46
46
  var _a;
47
47
  if (node.type.name in counters) {
48
48
  if (parent && excludedTypes.includes(parent.type)) {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*!
3
- * © 2019 Atypon Systems LLC
3
+ * © 2024 Atypon Systems LLC
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -15,13 +15,14 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.generateAttachmentFilename = void 0;
19
- const generateAttachmentFilename = (id, contentType) => {
20
- const basename = id.replace(':', '_');
21
- if (!contentType) {
22
- return basename;
18
+ exports.createArticleNode = void 0;
19
+ const deafults_1 = require("../../lib/deafults");
20
+ const schema_1 = require("../../schema");
21
+ const createArticleNode = (attrs) => {
22
+ const title = schema_1.schema.nodes.title.createChecked({}, schema_1.schema.text(deafults_1.defaultTitle));
23
+ if (!attrs.id) {
24
+ throw new Error('Manuscript ID is missing');
23
25
  }
24
- const [, mimeSubType] = contentType.split('/');
25
- return `${basename}.${mimeSubType}`;
26
+ return schema_1.schema.nodes.manuscript.createAndFill(attrs, title);
26
27
  };
27
- exports.generateAttachmentFilename = generateAttachmentFilename;
28
+ exports.createArticleNode = createArticleNode;
@@ -302,4 +302,77 @@ exports.jatsBodyTransformations = {
302
302
  body.prepend(section);
303
303
  }
304
304
  },
305
+ moveReferencesToBackmatter(body, references, createElement) {
306
+ const backmatter = body.querySelector('sec[sec-type="backmatter"]');
307
+ if (!references || !references.items.size || !backmatter) {
308
+ return;
309
+ }
310
+ const bibliographySection = this.createBibliographySection(createElement);
311
+ const bibliographyElement = createElement('bibliography-element');
312
+ references.getBibliographyItems().forEach((item) => {
313
+ const bibliographyItem = this.createBibliographyItem(item, createElement);
314
+ bibliographyElement.appendChild(bibliographyItem);
315
+ });
316
+ bibliographySection.appendChild(bibliographyElement);
317
+ backmatter.appendChild(bibliographySection);
318
+ },
319
+ createBibliographySection(createElement) {
320
+ const section = createElement('sec');
321
+ section.setAttribute('sec-type', 'bibliography_section');
322
+ const title = createElement('title');
323
+ title.textContent = 'References';
324
+ section.appendChild(title);
325
+ return section;
326
+ },
327
+ createBibliographyItem(item, createElement) {
328
+ var _a, _b, _c;
329
+ const bibliographyItem = createElement('bibliography-item');
330
+ bibliographyItem.setAttribute('id', item.id);
331
+ bibliographyItem.setAttribute('type', item.type);
332
+ (_a = item.author) === null || _a === void 0 ? void 0 : _a.forEach((author) => {
333
+ const authorElement = createElement('author');
334
+ authorElement.setAttribute('id', author._id);
335
+ authorElement.setAttribute('family', author.family || '');
336
+ authorElement.setAttribute('given', author.given || '');
337
+ bibliographyItem.appendChild(authorElement);
338
+ });
339
+ if (item.issued) {
340
+ const issuedEl = createElement('issued');
341
+ issuedEl.setAttribute('id', ((_b = item.issued) === null || _b === void 0 ? void 0 : _b._id) || '');
342
+ const dateParts = item.issued['date-parts'];
343
+ const year = (_c = dateParts === null || dateParts === void 0 ? void 0 : dateParts[0]) === null || _c === void 0 ? void 0 : _c[0];
344
+ if (year) {
345
+ issuedEl.setAttribute('year', year.toString());
346
+ }
347
+ bibliographyItem.appendChild(issuedEl);
348
+ }
349
+ if (item.containerTitle) {
350
+ bibliographyItem.setAttribute('containerTitle', item.containerTitle);
351
+ }
352
+ if (item.volume) {
353
+ bibliographyItem.setAttribute('volume', item.volume.toString());
354
+ }
355
+ if (item.issue) {
356
+ bibliographyItem.setAttribute('issue', item.issue.toString());
357
+ }
358
+ if (item.supplement) {
359
+ bibliographyItem.setAttribute('supplement', item.supplement);
360
+ }
361
+ if (item.page) {
362
+ bibliographyItem.setAttribute('page', item.page.toString());
363
+ }
364
+ if (item.title) {
365
+ bibliographyItem.setAttribute('title', item.title);
366
+ }
367
+ if (item.literal) {
368
+ bibliographyItem.setAttribute('literal', item.literal);
369
+ }
370
+ if (item.doi) {
371
+ bibliographyItem.setAttribute('DOI', item.doi);
372
+ }
373
+ if (item.literal) {
374
+ bibliographyItem.setAttribute('literal', item.literal);
375
+ }
376
+ return bibliographyItem;
377
+ },
305
378
  };
@@ -15,10 +15,10 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.createReferenceComments = exports.createComments = exports.markComments = exports.parseJATSComment = exports.isJATSComment = void 0;
19
- const uuid_1 = require("uuid");
18
+ exports.markComments = exports.parseJATSComment = exports.isJATSComment = exports.DEFAULT_PROFILE_ID = void 0;
19
+ const json_schema_1 = require("@manuscripts/json-schema");
20
20
  const transformer_1 = require("../../transformer");
21
- const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
21
+ exports.DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
22
22
  const isJATSComment = (node) => {
23
23
  return (node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
24
24
  node.nodeName === 'AuthorQuery');
@@ -27,35 +27,34 @@ exports.isJATSComment = isJATSComment;
27
27
  const parseJATSComment = (node) => {
28
28
  const text = node.textContent;
29
29
  if (text) {
30
- const id = /id="(.+)"/.exec(text);
31
30
  const queryText = /queryText="(.+)"/.exec(text);
32
- if (id && queryText) {
31
+ if (queryText) {
32
+ const parentNode = node.parentNode;
33
+ const index = parentNode.outerHTML.indexOf(queryText[1]);
33
34
  return {
34
- id: id[1],
35
+ id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.CommentAnnotation),
35
36
  text: queryText[1],
37
+ index,
36
38
  };
37
39
  }
38
40
  }
39
41
  };
40
42
  exports.parseJATSComment = parseJATSComment;
41
43
  const markComments = (doc) => {
42
- const marks = [];
44
+ var _a;
43
45
  const root = doc.getRootNode();
44
46
  const queue = [root];
47
+ const commentsElement = doc.createElement('comments-annotations');
45
48
  while (queue.length !== 0) {
46
49
  const node = queue.shift();
47
50
  if (node) {
48
51
  if ((0, exports.isJATSComment)(node)) {
49
52
  const comment = (0, exports.parseJATSComment)(node);
50
53
  if (comment) {
51
- const token = addMark(doc, node);
52
- if (token) {
53
- const mark = {
54
- token,
55
- comment,
56
- };
57
- marks.push(mark);
58
- }
54
+ const highlightMarker = createHighlightMarkerElement(doc, comment.id);
55
+ (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(highlightMarker, node);
56
+ const commentElement = createCommentElement(doc, comment);
57
+ commentsElement.appendChild(commentElement);
59
58
  }
60
59
  }
61
60
  node.childNodes.forEach((child) => {
@@ -63,96 +62,20 @@ const markComments = (doc) => {
63
62
  });
64
63
  }
65
64
  }
66
- return marks;
67
- };
68
- exports.markComments = markComments;
69
- const addMark = (doc, node) => {
70
- const parent = node.parentElement;
71
- if (parent) {
72
- const token = (0, uuid_1.v4)();
73
- const tokenNode = doc.createTextNode(token);
74
- parent.insertBefore(tokenNode, node);
75
- return token;
65
+ if (commentsElement.hasChildNodes()) {
66
+ doc.documentElement.appendChild(commentsElement);
76
67
  }
77
68
  };
78
- const createComments = (models, marks) => {
79
- const comments = [];
80
- for (const model of models) {
81
- if ((0, transformer_1.isHighlightableModel)(model)) {
82
- comments.push(...processModel(model, marks));
83
- }
84
- else if ((0, transformer_1.isKeyword)(model)) {
85
- comments.push(...processKeyword(model, marks));
86
- }
87
- }
88
- return comments;
89
- };
90
- exports.createComments = createComments;
91
- const getFieldMarks = (content, marks) => {
92
- return marks
93
- .filter((m) => content.indexOf(m.token) >= 0)
94
- .sort((a, b) => content.indexOf(a.token) - content.indexOf(b.token));
95
- };
96
- const processModel = (model, marks) => {
97
- const comments = [];
98
- for (const field of transformer_1.highlightableFields) {
99
- const content = model[field];
100
- if (!content) {
101
- continue;
102
- }
103
- const results = processContent(model, content, getFieldMarks(content, marks));
104
- model[field] = results.content;
105
- comments.push(...results.comments);
106
- }
107
- return comments;
108
- };
109
- const processKeyword = (model, marks) => {
110
- const comments = [];
111
- const name = model.name;
112
- let content = name;
113
- for (const mark of getFieldMarks(name, marks)) {
114
- content = name.replace(mark.token, '');
115
- const target = model.containedGroup;
116
- if (!target) {
117
- continue;
118
- }
119
- const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
120
- const comment = (0, transformer_1.buildComment)(target, mark.comment.text, undefined, contributions);
121
- model.name = content;
122
- comments.push(comment);
123
- }
124
- return comments;
125
- };
126
- const processContent = (model, content, marks) => {
127
- const comments = [];
128
- let result = content;
129
- for (const mark of marks) {
130
- const token = mark.token;
131
- const index = result.indexOf(token);
132
- result = result.replace(token, '');
133
- const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
134
- const selector = {
135
- from: index,
136
- to: index,
137
- };
138
- const comment = (0, transformer_1.buildComment)(model._id, mark.comment.text, selector, contributions);
139
- comments.push(comment);
140
- }
141
- return {
142
- content: result,
143
- comments,
144
- };
69
+ exports.markComments = markComments;
70
+ const createHighlightMarkerElement = (doc, id) => {
71
+ const highlightMarker = doc.createElement('highlight-marker');
72
+ highlightMarker.setAttribute('id', id);
73
+ highlightMarker.setAttribute('position', 'point');
74
+ return highlightMarker;
145
75
  };
146
- const createReferenceComments = (references) => {
147
- const comments = [];
148
- for (const item of references.getBibliographyItems()) {
149
- const id = item._id;
150
- for (const comment of references.getComments(id)) {
151
- const contributions = [(0, transformer_1.buildContribution)(DEFAULT_PROFILE_ID)];
152
- const c = (0, transformer_1.buildComment)(id, comment.text, undefined, contributions);
153
- comments.push(c);
154
- }
155
- }
156
- return comments;
76
+ const createCommentElement = (doc, comment) => {
77
+ const commentElement = doc.createElement('comment-annotation');
78
+ commentElement.setAttribute('id', comment.id);
79
+ commentElement.textContent = comment.text;
80
+ return commentElement;
157
81
  };
158
- exports.createReferenceComments = createReferenceComments;
@@ -18,11 +18,14 @@ 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.jatsBodyDOMParser = void 0;
21
+ exports.jatsDOMParser = void 0;
22
+ const json_schema_1 = require("@manuscripts/json-schema");
22
23
  const mime_1 = __importDefault(require("mime"));
23
24
  const prosemirror_model_1 = require("prosemirror-model");
25
+ const utils_1 = require("../../lib/utils");
24
26
  const schema_1 = require("../../schema");
25
27
  const transformer_1 = require("../../transformer");
28
+ const jats_comments_1 = require("./jats-comments");
26
29
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
27
30
  const chooseContentType = (graphicNode) => {
28
31
  if (graphicNode) {
@@ -37,6 +40,12 @@ const chooseContentType = (graphicNode) => {
37
40
  }
38
41
  }
39
42
  };
43
+ const parsePriority = (priority) => {
44
+ if (!priority) {
45
+ return undefined;
46
+ }
47
+ return parseInt(priority);
48
+ };
40
49
  const getEquationContent = (p) => {
41
50
  var _a;
42
51
  const element = p;
@@ -101,6 +110,224 @@ const marks = [
101
110
  },
102
111
  ];
103
112
  const nodes = [
113
+ {
114
+ tag: 'article',
115
+ node: 'manuscript',
116
+ getAttrs: (node) => {
117
+ var _a, _b, _c, _d;
118
+ const element = node;
119
+ return {
120
+ doi: (_a = element.getAttribute('DOI')) !== null && _a !== void 0 ? _a : '',
121
+ articleType: (_b = element.getAttribute('article-type')) !== null && _b !== void 0 ? _b : '',
122
+ prototype: (_c = element.getAttribute('prototype')) !== null && _c !== void 0 ? _c : '',
123
+ primaryLanguageCode: (_d = element.getAttribute('primary-language-code')) !== null && _d !== void 0 ? _d : '',
124
+ };
125
+ },
126
+ },
127
+ {
128
+ tag: 'article-title',
129
+ node: 'title',
130
+ getAttrs: (node) => {
131
+ const element = node;
132
+ return {
133
+ id: element.getAttribute('id'),
134
+ };
135
+ },
136
+ },
137
+ {
138
+ tag: 'highlight-marker',
139
+ node: 'highlight_marker',
140
+ getAttrs: (node) => {
141
+ var _a;
142
+ const element = node;
143
+ const id = element.getAttribute('id');
144
+ return {
145
+ id: id,
146
+ position: (_a = element.getAttribute('position')) !== null && _a !== void 0 ? _a : '',
147
+ };
148
+ },
149
+ },
150
+ {
151
+ tag: 'comment-annotation',
152
+ node: 'comment',
153
+ getAttrs: (node) => {
154
+ const element = node;
155
+ return {
156
+ id: element.getAttribute('id'),
157
+ contents: element.textContent,
158
+ contributions: [
159
+ {
160
+ _id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.Contribution),
161
+ objecType: json_schema_1.ObjectTypes.Contribution,
162
+ profileID: jats_comments_1.DEFAULT_PROFILE_ID,
163
+ timestamp: (0, utils_1.timestamp)(),
164
+ },
165
+ ],
166
+ };
167
+ },
168
+ },
169
+ {
170
+ tag: 'author-notes',
171
+ node: 'author_notes',
172
+ getAttrs: (node) => {
173
+ const element = node;
174
+ return {
175
+ id: element.getAttribute('id'),
176
+ };
177
+ },
178
+ },
179
+ {
180
+ tag: 'fn:not([fn-type])',
181
+ node: 'footnote',
182
+ context: 'author_notes/',
183
+ getAttrs: (node) => {
184
+ const element = node;
185
+ return {
186
+ id: element.getAttribute('id'),
187
+ kind: 'footnote',
188
+ };
189
+ },
190
+ },
191
+ {
192
+ tag: 'corresp',
193
+ node: 'corresp',
194
+ getAttrs: (node) => {
195
+ var _a;
196
+ const element = node;
197
+ const label = element.querySelector('label');
198
+ if (label) {
199
+ label.remove();
200
+ }
201
+ return {
202
+ id: element.getAttribute('id'),
203
+ label: (_a = label === null || label === void 0 ? void 0 : label.textContent) === null || _a === void 0 ? void 0 : _a.trim(),
204
+ };
205
+ },
206
+ getContent: (node) => {
207
+ var _a;
208
+ const element = node;
209
+ return prosemirror_model_1.Fragment.from(schema_1.schema.text(((_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || ''));
210
+ },
211
+ },
212
+ {
213
+ tag: 'contrib[contrib-type="author"]',
214
+ node: 'contributor',
215
+ getAttrs: (node) => {
216
+ var _a, _b;
217
+ const element = node;
218
+ const footnote = [];
219
+ const affiliations = [];
220
+ const corresp = [];
221
+ const xrefs = element.querySelectorAll('xref');
222
+ for (const xref of xrefs) {
223
+ const rid = xref.getAttribute('rid');
224
+ const type = xref.getAttribute('ref-type');
225
+ if (!rid) {
226
+ continue;
227
+ }
228
+ switch (type) {
229
+ case 'fn':
230
+ footnote.push({
231
+ noteID: rid,
232
+ noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
233
+ });
234
+ break;
235
+ case 'corresp':
236
+ corresp.push({
237
+ correspID: rid,
238
+ correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
239
+ });
240
+ break;
241
+ case 'aff':
242
+ affiliations.push(rid);
243
+ break;
244
+ }
245
+ }
246
+ return {
247
+ id: element.getAttribute('id'),
248
+ role: 'author',
249
+ affiliations,
250
+ corresp,
251
+ footnote,
252
+ isCorresponding: element.getAttribute('corresp')
253
+ ? element.getAttribute('corresp') === 'yes'
254
+ : undefined,
255
+ bibliographicName: {
256
+ given: (0, utils_1.getTrimmedTextContent)(element, 'name > given-names'),
257
+ family: (0, utils_1.getTrimmedTextContent)(element, 'name > surname'),
258
+ ObjectType: json_schema_1.ObjectTypes.BibliographicName,
259
+ _id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.BibliographicName),
260
+ },
261
+ ORCIDIdentifier: (0, utils_1.getTrimmedTextContent)(element, 'contrib-id[contrib-id-type="orcid"]'),
262
+ priority: parsePriority(element.getAttribute('priority')),
263
+ };
264
+ },
265
+ getContent: () => {
266
+ return prosemirror_model_1.Fragment.from(schema_1.schema.text('_'));
267
+ },
268
+ },
269
+ {
270
+ tag: 'affiliations',
271
+ node: 'affiliations',
272
+ },
273
+ {
274
+ tag: 'aff',
275
+ node: 'affiliation',
276
+ context: 'affiliations/',
277
+ getAttrs: (node) => {
278
+ var _a, _b;
279
+ const element = node;
280
+ const getEmail = (element) => {
281
+ var _a, _b, _c;
282
+ const email = element.querySelector('email');
283
+ if (email) {
284
+ return {
285
+ href: (_a = email.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _a !== void 0 ? _a : '',
286
+ text: (_c = (_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '',
287
+ };
288
+ }
289
+ };
290
+ const getInstitutionDetails = (element) => {
291
+ var _a;
292
+ let department = '';
293
+ let institution = '';
294
+ for (const node of element.querySelectorAll('institution')) {
295
+ const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
296
+ if (!content) {
297
+ continue;
298
+ }
299
+ const type = node.getAttribute('content-type');
300
+ if (type === 'dept') {
301
+ department = content;
302
+ }
303
+ else {
304
+ institution = content;
305
+ }
306
+ }
307
+ return { department, institution };
308
+ };
309
+ const getAddressLine = (element, index) => {
310
+ return ((0, utils_1.getTrimmedTextContent)(element, `addr-line:nth-of-type(${index})`) ||
311
+ '');
312
+ };
313
+ const { department, institution } = getInstitutionDetails(element);
314
+ return {
315
+ id: element.getAttribute('id'),
316
+ institution: institution !== null && institution !== void 0 ? institution : '',
317
+ department: department !== null && department !== void 0 ? department : '',
318
+ addressLine1: getAddressLine(element, 1),
319
+ addressLine2: getAddressLine(element, 2),
320
+ addressLine3: getAddressLine(element, 3),
321
+ postCode: (_a = (0, utils_1.getTrimmedTextContent)(element, 'postal-code')) !== null && _a !== void 0 ? _a : '',
322
+ country: (_b = (0, utils_1.getTrimmedTextContent)(element, 'country')) !== null && _b !== void 0 ? _b : '',
323
+ email: getEmail(element),
324
+ priority: parsePriority(element.getAttribute('priority')),
325
+ };
326
+ },
327
+ getContent: () => {
328
+ return prosemirror_model_1.Fragment.from(schema_1.schema.text('_'));
329
+ },
330
+ },
104
331
  {
105
332
  tag: 'attrib',
106
333
  node: 'attribution',
@@ -109,10 +336,6 @@ const nodes = [
109
336
  tag: 'back',
110
337
  ignore: true,
111
338
  },
112
- {
113
- tag: 'body',
114
- node: 'manuscript',
115
- },
116
339
  {
117
340
  tag: 'break',
118
341
  node: 'hard_break',
@@ -132,13 +355,13 @@ const nodes = [
132
355
  const title = element.querySelector('title');
133
356
  if (title) {
134
357
  const captionTitle = schema.nodes.caption_title.create();
135
- content.push(exports.jatsBodyDOMParser.parse(title, { topNode: captionTitle }));
358
+ content.push(exports.jatsDOMParser.parse(title, { topNode: captionTitle }));
136
359
  }
137
360
  const paragraphs = element.querySelectorAll('p');
138
361
  if (paragraphs.length) {
139
362
  const figcaption = schema.nodes.caption.create();
140
363
  for (const paragraph of paragraphs) {
141
- content.push(exports.jatsBodyDOMParser.parse(paragraph, { topNode: figcaption }));
364
+ content.push(exports.jatsDOMParser.parse(paragraph, { topNode: figcaption }));
142
365
  }
143
366
  }
144
367
  return prosemirror_model_1.Fragment.from(content);
@@ -329,7 +552,7 @@ const nodes = [
329
552
  const paragraphs = [];
330
553
  node.childNodes.forEach((p) => {
331
554
  const paragraph = schema_1.schema.nodes.paragraph.create();
332
- const content = exports.jatsBodyDOMParser.parse(p, {
555
+ const content = exports.jatsDOMParser.parse(p, {
333
556
  topNode: paragraph,
334
557
  });
335
558
  paragraphs.push(content);
@@ -428,6 +651,54 @@ const nodes = [
428
651
  tag: 'sec[sec-type="backmatter"]',
429
652
  node: 'backmatter',
430
653
  },
654
+ {
655
+ tag: 'bibliography-element',
656
+ node: 'bibliography_element',
657
+ getAttrs: (node) => {
658
+ const element = node;
659
+ return {
660
+ id: element.getAttribute('id'),
661
+ };
662
+ },
663
+ },
664
+ {
665
+ tag: 'bibliography-item',
666
+ node: 'bibliography_item',
667
+ getAttrs: (node) => {
668
+ const element = node;
669
+ const authors = [];
670
+ element.querySelectorAll('author').forEach((author) => {
671
+ authors.push({
672
+ _id: author.getAttribute('id') || '',
673
+ given: author.getAttribute('given') || '',
674
+ family: author.getAttribute('family') || '',
675
+ objectType: 'MPBibliographicName',
676
+ });
677
+ });
678
+ const issuedEl = element.querySelector('issued');
679
+ const issued = issuedEl
680
+ ? {
681
+ objectType: 'MPBibliographicDate',
682
+ _id: issuedEl.getAttribute('id'),
683
+ 'date-parts': [[issuedEl.getAttribute('year')]],
684
+ }
685
+ : undefined;
686
+ return {
687
+ id: element.getAttribute('id'),
688
+ type: element.getAttribute('type'),
689
+ containerTitle: element.getAttribute('container-title'),
690
+ volume: element.getAttribute('volume'),
691
+ issue: element.getAttribute('issue'),
692
+ supplement: element.getAttribute('supplement'),
693
+ page: element.getAttribute('page'),
694
+ title: element.getAttribute('title'),
695
+ literal: element.getAttribute('literal'),
696
+ author: authors,
697
+ issued,
698
+ DOI: element.getAttribute('DOI'),
699
+ };
700
+ },
701
+ },
431
702
  {
432
703
  tag: 'sec',
433
704
  node: 'section',
@@ -498,7 +769,7 @@ const nodes = [
498
769
  {
499
770
  tag: 'title',
500
771
  node: 'section_title',
501
- context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/',
772
+ context: 'section/|footnotes_section/|bibliography_section/|keywords/|supplements/|author_notes/',
502
773
  },
503
774
  {
504
775
  tag: 'title',
@@ -580,4 +851,4 @@ const nodes = [
580
851
  },
581
852
  },
582
853
  ];
583
- exports.jatsBodyDOMParser = new prosemirror_model_1.DOMParser(schema_1.schema, [...marks, ...nodes]);
854
+ exports.jatsDOMParser = new prosemirror_model_1.DOMParser(schema_1.schema, [...marks, ...nodes]);