@manuscripts/transform 2.3.34-LEAN-3911.2 → 2.3.34

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 (116) hide show
  1. package/dist/cjs/__tests__/data/project-dump.json +825 -0
  2. package/dist/cjs/jats/importer/index.js +3 -3
  3. package/dist/cjs/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +9 -229
  4. package/dist/cjs/jats/importer/jats-body-transformations.js +0 -70
  5. package/dist/cjs/jats/importer/jats-comments.js +104 -27
  6. package/dist/cjs/jats/importer/jats-front-parser.js +321 -0
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +1 -8
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +5 -39
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +27 -16
  10. package/dist/cjs/jats/importer/jats-references.js +18 -18
  11. package/dist/cjs/jats/importer/parse-jats-article.js +78 -42
  12. package/dist/cjs/jats/index.js +3 -4
  13. package/dist/cjs/jats/jats-exporter.js +354 -251
  14. package/dist/cjs/lib/utils.js +1 -9
  15. package/dist/cjs/schema/nodes/inline_footnote.js +1 -0
  16. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +37 -0
  17. package/dist/cjs/transformer/builders.js +219 -0
  18. package/dist/cjs/transformer/decode.js +874 -0
  19. package/dist/cjs/transformer/document-object-types.js +31 -0
  20. package/dist/cjs/transformer/encode.js +664 -0
  21. package/dist/cjs/transformer/footnote-category.js +20 -0
  22. package/dist/cjs/transformer/footnotes-order.js +60 -0
  23. package/dist/cjs/transformer/highlight-markers.js +138 -0
  24. package/dist/cjs/transformer/html.js +400 -0
  25. package/dist/cjs/transformer/id.js +6 -6
  26. package/dist/cjs/transformer/index.js +18 -0
  27. package/dist/cjs/{jats → transformer}/labels.js +3 -3
  28. package/dist/cjs/transformer/manuscript-dependencies.js +21 -0
  29. package/dist/cjs/transformer/model-map.js +26 -0
  30. package/dist/cjs/transformer/models.js +17 -0
  31. package/dist/cjs/transformer/object-types.js +57 -0
  32. package/dist/cjs/transformer/project-bundle.js +94 -0
  33. package/dist/cjs/transformer/serializer.js +23 -0
  34. package/dist/cjs/transformer/update-identifiers.js +93 -0
  35. package/dist/cjs/version.js +1 -1
  36. package/dist/es/__tests__/data/project-dump.json +825 -0
  37. package/dist/es/jats/importer/index.js +1 -2
  38. package/dist/es/jats/importer/{jats-dom-parser.js → jats-body-dom-parser.js} +10 -230
  39. package/dist/es/jats/importer/jats-body-transformations.js +0 -70
  40. package/dist/es/jats/importer/jats-comments.js +101 -26
  41. package/dist/es/jats/importer/jats-front-parser.js +315 -0
  42. package/dist/es/jats/importer/jats-journal-meta-parser.js +0 -6
  43. package/dist/es/jats/importer/jats-parser-utils.js +6 -40
  44. package/dist/es/jats/importer/jats-reference-parser.js +27 -16
  45. package/dist/es/jats/importer/jats-references.js +18 -18
  46. package/dist/es/jats/importer/parse-jats-article.js +77 -43
  47. package/dist/es/jats/index.js +1 -3
  48. package/dist/es/jats/jats-exporter.js +356 -253
  49. package/dist/es/lib/utils.js +0 -7
  50. package/dist/es/schema/nodes/inline_footnote.js +1 -0
  51. package/dist/es/transformer/__tests__/__helpers__/doc.js +29 -0
  52. package/dist/es/transformer/builders.js +186 -0
  53. package/dist/es/transformer/decode.js +864 -0
  54. package/dist/es/transformer/document-object-types.js +28 -0
  55. package/dist/es/transformer/encode.js +654 -0
  56. package/dist/{types/jats/importer/create-article-node.d.ts → es/transformer/footnote-category.js} +2 -3
  57. package/dist/es/transformer/footnotes-order.js +55 -0
  58. package/dist/es/transformer/highlight-markers.js +132 -0
  59. package/dist/es/transformer/html.js +393 -0
  60. package/dist/es/transformer/id.js +4 -5
  61. package/dist/es/transformer/index.js +16 -0
  62. package/dist/es/{jats → transformer}/labels.js +3 -3
  63. package/dist/es/transformer/manuscript-dependencies.js +17 -0
  64. package/dist/es/transformer/model-map.js +22 -0
  65. package/dist/es/transformer/models.js +16 -0
  66. package/dist/es/transformer/object-types.js +52 -0
  67. package/dist/es/transformer/project-bundle.js +85 -0
  68. package/dist/es/transformer/serializer.js +17 -0
  69. package/dist/es/transformer/update-identifiers.js +87 -0
  70. package/dist/es/version.js +1 -1
  71. package/dist/types/jats/importer/index.d.ts +1 -2
  72. package/dist/types/jats/importer/{jats-dom-parser.d.ts → jats-body-dom-parser.d.ts} +1 -1
  73. package/dist/types/jats/importer/jats-body-transformations.d.ts +0 -5
  74. package/dist/types/jats/importer/jats-comments.d.ts +10 -4
  75. package/dist/types/jats/importer/jats-front-parser.d.ts +84 -0
  76. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +0 -10
  77. package/dist/types/jats/importer/jats-references.d.ts +8 -19
  78. package/dist/types/jats/importer/parse-jats-article.d.ts +5 -12
  79. package/dist/types/jats/index.d.ts +1 -3
  80. package/dist/types/jats/jats-exporter.d.ts +29 -10
  81. package/dist/types/lib/utils.d.ts +0 -3
  82. package/dist/types/schema/nodes/bibliography_item.d.ts +6 -16
  83. package/dist/types/schema/nodes/contributor.d.ts +0 -10
  84. package/dist/types/schema/nodes/keyword_group.d.ts +0 -1
  85. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +18 -0
  86. package/dist/types/transformer/builders.d.ts +61 -0
  87. package/dist/types/transformer/decode.d.ts +51 -0
  88. package/dist/types/transformer/document-object-types.d.ts +17 -0
  89. package/dist/types/transformer/encode.d.ts +29 -0
  90. package/dist/types/transformer/footnote-category.d.ts +17 -0
  91. package/dist/types/transformer/footnotes-order.d.ts +22 -0
  92. package/dist/types/transformer/highlight-markers.d.ts +31 -0
  93. package/dist/types/transformer/html.d.ts +36 -0
  94. package/dist/types/transformer/id.d.ts +3 -4
  95. package/dist/types/transformer/index.d.ts +16 -0
  96. package/dist/types/{jats → transformer}/labels.d.ts +1 -2
  97. package/dist/types/transformer/manuscript-dependencies.d.ts +4 -0
  98. package/dist/types/transformer/model-map.d.ts +19 -0
  99. package/dist/types/transformer/models.d.ts +48 -0
  100. package/dist/types/transformer/object-types.d.ts +30 -0
  101. package/dist/types/transformer/project-bundle.d.ts +30 -0
  102. package/dist/types/transformer/serializer.d.ts +19 -0
  103. package/dist/types/transformer/update-identifiers.d.ts +23 -0
  104. package/dist/types/version.d.ts +1 -1
  105. package/package.json +1 -2
  106. package/dist/cjs/jats/importer/create-article-node.js +0 -31
  107. package/dist/cjs/jats/importer/jats-front-transformations.js +0 -262
  108. package/dist/es/jats/importer/create-article-node.js +0 -27
  109. package/dist/es/jats/importer/jats-front-transformations.js +0 -259
  110. package/dist/types/jats/importer/jats-front-transformations.d.ts +0 -38
  111. /package/dist/cjs/{jats → transformer}/filename.js +0 -0
  112. /package/dist/cjs/{jats → transformer}/timestamp.js +0 -0
  113. /package/dist/es/{jats → transformer}/filename.js +0 -0
  114. /package/dist/es/{jats → transformer}/timestamp.js +0 -0
  115. /package/dist/types/{jats → transformer}/filename.d.ts +0 -0
  116. /package/dist/types/{jats → transformer}/timestamp.d.ts +0 -0
@@ -0,0 +1,315 @@
1
+ /*!
2
+ * © 2020 Atypon Systems LLC
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import debug from 'debug';
17
+ import { getTrimmedTextContent } from '../../lib/utils';
18
+ import { buildAffiliation, buildAuthorNotes, buildBibliographicName, buildContributor, buildCorresp, buildFootnote, buildJournal, buildParagraph, buildTitles, } from '../../transformer';
19
+ import { parseJournalMeta } from './jats-journal-meta-parser';
20
+ import { htmlFromJatsNode } from './jats-parser-utils';
21
+ const warn = debug('manuscripts-transform');
22
+ const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
23
+ const defaultTitle = 'Untitled Manuscript';
24
+ export const jatsFrontParser = {
25
+ parseTitles(element, createElement) {
26
+ var _a;
27
+ if (!element) {
28
+ return buildTitles(defaultTitle);
29
+ }
30
+ const title = element.querySelector('article-title');
31
+ const subtitle = element.querySelector('subtitle');
32
+ const runningTitle = element.querySelector('alt-title[alt-title-type="right-running"]');
33
+ const titles = buildTitles((_a = htmlFromJatsNode(title, createElement)) !== null && _a !== void 0 ? _a : defaultTitle);
34
+ if (subtitle) {
35
+ titles.subtitle = htmlFromJatsNode(subtitle, createElement);
36
+ }
37
+ if (runningTitle) {
38
+ titles.runningTitle = htmlFromJatsNode(runningTitle, createElement);
39
+ }
40
+ return titles;
41
+ },
42
+ parseDOI(front) {
43
+ var _a;
44
+ const doi = front === null || front === void 0 ? void 0 : front.querySelector('article-meta > article-id[pub-id-type="doi"]');
45
+ return (_a = doi === null || doi === void 0 ? void 0 : doi.textContent) !== null && _a !== void 0 ? _a : undefined;
46
+ },
47
+ parseCounts(counts) {
48
+ var _a, _b, _c, _d, _e;
49
+ if (counts) {
50
+ const parseCount = (count) => {
51
+ if (count && /^-?\d+$/.test(count)) {
52
+ return parseInt(count);
53
+ }
54
+ else if (count) {
55
+ warn(`Invalid count number for ${count}`);
56
+ }
57
+ };
58
+ const genericCounts = [];
59
+ const countElements = counts.querySelectorAll('count');
60
+ for (const element of countElements.values()) {
61
+ const countType = element.getAttribute('count-type');
62
+ const count = parseCount(element.getAttribute('count'));
63
+ if (countType) {
64
+ const genericCount = { count, countType };
65
+ genericCounts.push(genericCount);
66
+ }
67
+ }
68
+ return {
69
+ wordCount: parseCount((_a = counts.querySelector('word-count')) === null || _a === void 0 ? void 0 : _a.getAttribute('count')),
70
+ figureCount: parseCount((_b = counts.querySelector('fig-count')) === null || _b === void 0 ? void 0 : _b.getAttribute('count')),
71
+ tableCount: parseCount((_c = counts.querySelector('table-count')) === null || _c === void 0 ? void 0 : _c.getAttribute('count')),
72
+ equationCount: parseCount((_d = counts.querySelector('equation-count')) === null || _d === void 0 ? void 0 : _d.getAttribute('count')),
73
+ referencesCount: parseCount((_e = counts.querySelector('ref-count')) === null || _e === void 0 ? void 0 : _e.getAttribute('count')),
74
+ genericCounts: genericCounts.length > 0 ? genericCounts : undefined,
75
+ };
76
+ }
77
+ },
78
+ parseJournal(element) {
79
+ const meta = parseJournalMeta(element);
80
+ return Object.assign(Object.assign({}, meta), buildJournal());
81
+ },
82
+ parseDates(historyNode) {
83
+ if (!historyNode) {
84
+ return undefined;
85
+ }
86
+ const history = {};
87
+ const dateToTimestamp = (dateElement) => {
88
+ const selectors = ['year', 'month', 'day'];
89
+ const values = [];
90
+ for (const selector of selectors) {
91
+ const value = getTrimmedTextContent(dateElement, selector);
92
+ if (!value || isNaN(+value)) {
93
+ return;
94
+ }
95
+ values.push(+value);
96
+ }
97
+ return Date.UTC(values[0], values[1], values[2]) / 1000;
98
+ };
99
+ for (const date of historyNode.children) {
100
+ const dateType = date.getAttribute('date-type');
101
+ switch (dateType) {
102
+ case 'received': {
103
+ history.receiveDate = dateToTimestamp(date);
104
+ break;
105
+ }
106
+ case 'rev-recd': {
107
+ history.revisionReceiveDate = dateToTimestamp(date);
108
+ break;
109
+ }
110
+ case 'accepted': {
111
+ history.acceptanceDate = dateToTimestamp(date);
112
+ break;
113
+ }
114
+ case 'rev-request': {
115
+ history.revisionRequestDate = dateToTimestamp(date);
116
+ break;
117
+ }
118
+ case 'retracted': {
119
+ history.retractionDate = dateToTimestamp(date);
120
+ break;
121
+ }
122
+ case 'corrected': {
123
+ history.correctionDate = dateToTimestamp(date);
124
+ break;
125
+ }
126
+ }
127
+ }
128
+ return history;
129
+ },
130
+ parseAffiliations(elements) {
131
+ const affiliationIDs = new Map();
132
+ const affiliations = elements.map((element, priority) => {
133
+ var _a, _b;
134
+ const affiliation = buildAffiliation('', priority);
135
+ for (const node of element.querySelectorAll('institution')) {
136
+ const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
137
+ if (!content) {
138
+ continue;
139
+ }
140
+ const type = node.getAttribute('content-type');
141
+ if (type === 'dept') {
142
+ affiliation.department = content;
143
+ }
144
+ else {
145
+ affiliation.institution = content;
146
+ }
147
+ }
148
+ affiliation.addressLine1 =
149
+ getTrimmedTextContent(element, 'addr-line:nth-of-type(1)') || undefined;
150
+ affiliation.addressLine2 =
151
+ getTrimmedTextContent(element, 'addr-line:nth-of-type(2)') || undefined;
152
+ affiliation.addressLine3 =
153
+ getTrimmedTextContent(element, 'addr-line:nth-of-type(3)') || undefined;
154
+ affiliation.postCode =
155
+ getTrimmedTextContent(element, 'postal-code') || undefined;
156
+ affiliation.country =
157
+ getTrimmedTextContent(element, 'country') || undefined;
158
+ const email = element.querySelector('email');
159
+ if (email) {
160
+ affiliation.email = {
161
+ href: email.getAttributeNS(XLINK_NAMESPACE, 'href') || undefined,
162
+ text: ((_b = email.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
163
+ };
164
+ }
165
+ const id = element.getAttribute('id');
166
+ if (id) {
167
+ affiliationIDs.set(id, affiliation._id);
168
+ }
169
+ return affiliation;
170
+ });
171
+ return {
172
+ affiliations,
173
+ affiliationIDs,
174
+ };
175
+ },
176
+ parseAuthorNotes(element) {
177
+ if (!element) {
178
+ return {
179
+ footnotes: [],
180
+ footnoteIDs: new Map(),
181
+ authorNotes: [],
182
+ authorNotesParagraphs: [],
183
+ correspondingIDs: new Map(),
184
+ correspondingList: [],
185
+ };
186
+ }
187
+ const { footnotes, footnoteIDs } = this.parseFootnotes([
188
+ ...element.querySelectorAll('fn:not([fn-type])'),
189
+ ]);
190
+ const authorNotesParagraphs = this.parseParagraphs([
191
+ ...element.querySelectorAll(':scope > p'),
192
+ ]);
193
+ const { correspondingList, correspondingIDs } = this.parseCorresp([
194
+ ...element.querySelectorAll('corresp'),
195
+ ]);
196
+ const authorNotes = [
197
+ buildAuthorNotes([
198
+ ...correspondingIDs.values(),
199
+ ...footnoteIDs.values(),
200
+ ...authorNotesParagraphs.map((p) => p._id),
201
+ ]),
202
+ ];
203
+ return {
204
+ footnotes,
205
+ footnoteIDs,
206
+ authorNotesParagraphs,
207
+ authorNotes,
208
+ correspondingIDs,
209
+ correspondingList,
210
+ };
211
+ },
212
+ parseParagraphs(elements) {
213
+ return elements.map((p) => buildParagraph(p.innerHTML));
214
+ },
215
+ parseFootnotes(elements) {
216
+ const footnoteIDs = new Map();
217
+ const footnotes = elements.map((element) => {
218
+ const fn = buildFootnote('', element.innerHTML);
219
+ const id = element.getAttribute('id');
220
+ if (id) {
221
+ footnoteIDs.set(id, fn._id);
222
+ }
223
+ return fn;
224
+ });
225
+ return {
226
+ footnotes,
227
+ footnoteIDs,
228
+ };
229
+ },
230
+ parseCorresp(elements) {
231
+ const correspondingIDs = new Map();
232
+ const correspondingList = elements.map((element) => {
233
+ var _a, _b, _c;
234
+ const label = element.querySelector('label');
235
+ if (label) {
236
+ label.remove();
237
+ }
238
+ const corresponding = buildCorresp((_b = (_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '');
239
+ corresponding.label = ((_c = label === null || label === void 0 ? void 0 : label.textContent) === null || _c === void 0 ? void 0 : _c.trim()) || undefined;
240
+ const id = element.getAttribute('id');
241
+ if (id) {
242
+ correspondingIDs.set(id, corresponding._id);
243
+ }
244
+ return corresponding;
245
+ });
246
+ return {
247
+ correspondingList,
248
+ correspondingIDs,
249
+ };
250
+ },
251
+ parseContributors(elements, affiliationIDs, footnoteIDs, correspondingIDs) {
252
+ return elements.map((element, priority) => {
253
+ var _a, _b;
254
+ const name = buildBibliographicName({});
255
+ const given = getTrimmedTextContent(element, 'name > given-names');
256
+ if (given) {
257
+ name.given = given;
258
+ }
259
+ const surname = getTrimmedTextContent(element, 'name > surname');
260
+ if (surname) {
261
+ name.family = surname;
262
+ }
263
+ const contributor = buildContributor(name, 'author', priority);
264
+ const corresponding = element.getAttribute('corresp') === 'yes';
265
+ if (corresponding) {
266
+ contributor.isCorresponding = corresponding;
267
+ }
268
+ const orcid = getTrimmedTextContent(element, 'contrib-id[contrib-id-type="orcid"]');
269
+ if (orcid) {
270
+ contributor.ORCIDIdentifier = orcid;
271
+ }
272
+ const xrefs = element.querySelectorAll('xref');
273
+ for (const xref of xrefs) {
274
+ if (xref) {
275
+ const rid = xref.getAttribute('rid');
276
+ const type = xref.getAttribute('ref-type');
277
+ if (rid) {
278
+ if (type === 'fn') {
279
+ contributor.footnote = [];
280
+ const footnoteID = footnoteIDs.get(rid);
281
+ if (footnoteID) {
282
+ const authorFootNoteRef = {
283
+ noteID: footnoteID,
284
+ noteLabel: ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '',
285
+ };
286
+ contributor.footnote.push(authorFootNoteRef);
287
+ }
288
+ }
289
+ else if (type === 'corresp') {
290
+ contributor.corresp = [];
291
+ const correspID = correspondingIDs.get(rid);
292
+ if (correspID) {
293
+ const authorCorrespRef = {
294
+ correspID: correspID,
295
+ correspLabel: ((_b = xref.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '',
296
+ };
297
+ contributor.corresp.push(authorCorrespRef);
298
+ }
299
+ }
300
+ else if (type === 'aff') {
301
+ const rids = rid
302
+ .split(/\s+/)
303
+ .map((id) => affiliationIDs.get(id))
304
+ .filter(Boolean);
305
+ if (rids.length) {
306
+ contributor.affiliations = rids;
307
+ }
308
+ }
309
+ }
310
+ }
311
+ }
312
+ return contributor;
313
+ });
314
+ },
315
+ };
@@ -13,9 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ObjectTypes } from '@manuscripts/json-schema';
17
16
  import { getTrimmedTextContent } from '../../lib/utils';
18
- import { generateID } from '../../transformer';
19
17
  export const parseJournalIdentifiers = (element) => {
20
18
  var _a;
21
19
  if (!element) {
@@ -86,7 +84,3 @@ export const parseJournalMeta = (element) => {
86
84
  title: (_b = getTrimmedTextContent(element, 'journal-title-group > journal-title')) !== null && _b !== void 0 ? _b : undefined,
87
85
  };
88
86
  };
89
- export const parseJournal = (element) => {
90
- const meta = parseJournalMeta(element);
91
- return Object.assign(Object.assign({}, meta), { _id: generateID(ObjectTypes.Journal), objectType: ObjectTypes.Journal });
92
- };
@@ -14,38 +14,24 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import { v4 as uuidv4 } from 'uuid';
17
- import { schema, } from '../../schema';
17
+ import { schema } from '../../schema';
18
18
  import { generateID, nodeTypesMap } from '../../transformer';
19
19
  export const updateDocumentIDs = (node, replacements) => {
20
20
  const warnings = [];
21
- const highlightNodes = [];
22
- recurseDoc(node, (n, parent) => updateNodeID(n, parent, replacements, warnings, highlightNodes));
21
+ recurseDoc(node, (n) => updateNodeID(n, replacements, warnings));
23
22
  recurseDoc(node, (n) => updateNodeRID(n, replacements, warnings));
24
23
  recurseDoc(node, (n) => updateNodeRIDS(n, replacements, warnings));
25
- recurseDoc(node, (n) => updateContributorNodesIDS(n, replacements, warnings));
26
24
  return warnings;
27
25
  };
28
- function recurseDoc(node, fn, parent = null) {
29
- fn(node, parent);
30
- node.descendants((n, pos, parent) => fn(n, parent));
26
+ function recurseDoc(node, fn) {
27
+ fn(node);
28
+ node.descendants((n) => fn(n));
31
29
  }
32
- const updateNodeID = (node, parent, replacements, warnings, highlightNodes) => {
30
+ const updateNodeID = (node, replacements, warnings) => {
33
31
  if (node.type === schema.nodes.inline_equation) {
34
32
  node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${uuidv4()}` });
35
33
  return;
36
34
  }
37
- if (node.type === schema.nodes.highlight_marker) {
38
- node.attrs = Object.assign(Object.assign({}, node.attrs), { tid: parent === null || parent === void 0 ? void 0 : parent.attrs.id });
39
- highlightNodes.push(node);
40
- return;
41
- }
42
- if (node.type === schema.nodes.comment) {
43
- const highlightNode = highlightNodes.find((n) => n.attrs.id === node.attrs.id);
44
- if (highlightNode) {
45
- node.attrs = Object.assign(Object.assign({}, node.attrs), { target: highlightNode.attrs.tid });
46
- }
47
- return;
48
- }
49
35
  if (node.type === schema.nodes.general_table_footnote) {
50
36
  node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `GeneralTableFootnote:${uuidv4()}` });
51
37
  return;
@@ -88,26 +74,6 @@ const updateNodeRIDS = (node, replacements, warnings) => {
88
74
  }
89
75
  node.attrs = Object.assign(Object.assign({}, node.attrs), { rids: previousRIDs.map((r) => replacements.get(r) || r) });
90
76
  };
91
- const updateContributorNodesIDS = (node, replacements, warnings) => {
92
- var _a, _b;
93
- if (node.type === schema.nodes.contributor) {
94
- const footnote = (_a = node.attrs.footnote) === null || _a === void 0 ? void 0 : _a.map((fn) => {
95
- return Object.assign(Object.assign({}, fn), { noteID: replacements.get(fn.noteID) });
96
- });
97
- const corresp = (_b = node.attrs.corresp) === null || _b === void 0 ? void 0 : _b.map((corresp) => {
98
- return Object.assign(Object.assign({}, corresp), { correspID: replacements.get(corresp.correspID) });
99
- });
100
- const affiliations = node.attrs.affiliations.map((affiliation) => {
101
- return replacements.get(affiliation);
102
- });
103
- node.attrs = Object.assign(Object.assign({}, node.attrs), { footnote,
104
- corresp,
105
- affiliations });
106
- }
107
- if (node.type !== schema.nodes.contributors) {
108
- return false;
109
- }
110
- };
111
77
  const JATS_TO_HTML_MAPPING = new Map([
112
78
  ['bold', 'b'],
113
79
  ['italic', 'i'],
@@ -13,9 +13,9 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { ObjectTypes } from '@manuscripts/json-schema';
17
16
  import { getTrimmedTextContent } from '../../lib/utils';
18
- import { generateID } from '../../transformer';
17
+ import { buildBibliographicDate, buildBibliographicName, buildBibliographyItem, } from '../../transformer/builders';
18
+ import { isJATSComment, parseJATSComment } from './jats-comments';
19
19
  import { htmlFromJatsNode } from './jats-parser-utils';
20
20
  import { References } from './jats-references';
21
21
  const chooseBibliographyItemType = (publicationType) => {
@@ -37,15 +37,23 @@ export const jatsReferenceParser = {
37
37
  const authorNodes = [
38
38
  ...element.querySelectorAll('person-group[person-group-type="author"] > *'),
39
39
  ];
40
- const bibliographyItem = {
41
- id: generateID(ObjectTypes.BibliographyItem),
40
+ const bibliographyItem = buildBibliographyItem({
42
41
  type: chooseBibliographyItemType(publicationType),
43
- };
42
+ });
44
43
  const titleNode = element.querySelector('article-title');
45
44
  if (titleNode) {
46
45
  bibliographyItem.title = (_a = htmlFromJatsNode(titleNode, createElement)) === null || _a === void 0 ? void 0 : _a.trim();
47
46
  }
47
+ const comments = [];
48
48
  const mixedCitation = element.querySelector('mixed-citation');
49
+ mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
50
+ if (isJATSComment(item)) {
51
+ const comment = parseJATSComment(item);
52
+ if (comment) {
53
+ comments.push(comment);
54
+ }
55
+ }
56
+ });
49
57
  if (authorNodes.length <= 0) {
50
58
  mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
51
59
  var _a, _b, _c;
@@ -58,7 +66,7 @@ export const jatsReferenceParser = {
58
66
  }
59
67
  const source = getTrimmedTextContent(element, 'source');
60
68
  if (source) {
61
- bibliographyItem.containerTitle = source;
69
+ bibliographyItem['container-title'] = source;
62
70
  }
63
71
  const volume = getTrimmedTextContent(element, 'volume');
64
72
  if (volume) {
@@ -79,22 +87,18 @@ export const jatsReferenceParser = {
79
87
  }
80
88
  const year = getTrimmedTextContent(element, 'year');
81
89
  if (year) {
82
- bibliographyItem.issued = {
90
+ bibliographyItem.issued = buildBibliographicDate({
83
91
  'date-parts': [[year]],
84
- _id: generateID(ObjectTypes.BibliographicDate),
85
- objectType: ObjectTypes.BibliographicDate,
86
- };
92
+ });
87
93
  }
88
94
  const doi = getTrimmedTextContent(element, 'pub-id[pub-id-type="doi"]');
89
95
  if (doi) {
90
- bibliographyItem.doi = doi;
96
+ bibliographyItem.DOI = doi;
91
97
  }
92
98
  const authors = [];
93
99
  authorNodes.forEach((authorNode) => {
94
- const name = {
95
- _id: generateID(ObjectTypes.BibliographicName),
96
- objectType: ObjectTypes.BibliographicName,
97
- };
100
+ var _a;
101
+ const name = buildBibliographicName({});
98
102
  const given = getTrimmedTextContent(authorNode, 'given-names');
99
103
  if (given) {
100
104
  name.given = given;
@@ -103,13 +107,20 @@ export const jatsReferenceParser = {
103
107
  if (family) {
104
108
  name.family = family;
105
109
  }
110
+ const suffix = getTrimmedTextContent(authorNode, 'suffix');
111
+ if (suffix) {
112
+ name.suffix = suffix;
113
+ }
114
+ if (authorNode.nodeName === 'collab') {
115
+ name.literal = (_a = authorNode.textContent) === null || _a === void 0 ? void 0 : _a.trim();
116
+ }
106
117
  authors.push(name);
107
118
  });
108
119
  if (authors.length) {
109
120
  bibliographyItem.author = authors;
110
121
  }
111
122
  const id = element.getAttribute('id');
112
- references.add(bibliographyItem, id);
123
+ references.add(bibliographyItem, id, comments);
113
124
  });
114
125
  return references;
115
126
  },
@@ -1,30 +1,30 @@
1
- /*!
2
- * © 2023 Atypon Systems LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
1
  export class References {
17
2
  constructor() {
18
3
  this.items = new Map();
19
4
  this.IDs = new Map();
5
+ this.comments = new Map();
20
6
  }
21
- add(item, id) {
22
- this.items.set(item.id, item);
7
+ add(item, id, comments) {
8
+ this.items.set(item._id, item);
9
+ this.comments.set(item._id, comments);
23
10
  if (id) {
24
- this.IDs.set(id, item.id);
11
+ this.IDs.set(id, item._id);
25
12
  }
26
13
  }
27
14
  getBibliographyItems() {
28
15
  return [...this.items.values()];
29
16
  }
17
+ getComments(id) {
18
+ return this.getValue(id, this.comments) || [];
19
+ }
20
+ getValue(id, map) {
21
+ const value = map.get(id);
22
+ if (value) {
23
+ return value;
24
+ }
25
+ const id2 = this.IDs.get(id);
26
+ if (id2) {
27
+ return map.get(id2);
28
+ }
29
+ }
30
30
  }