@manuscripts/transform 2.3.34-LEAN-3911.2 → 2.3.35

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
@@ -15,8 +15,8 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.parseJATSArticle = exports.createArticleNode = void 0;
19
- var create_article_node_1 = require("./create-article-node");
20
- Object.defineProperty(exports, "createArticleNode", { enumerable: true, get: function () { return create_article_node_1.createArticleNode; } });
18
+ exports.parseJATSArticle = exports.parseJATSBody = exports.parseJATSFront = void 0;
21
19
  var parse_jats_article_1 = require("./parse-jats-article");
20
+ Object.defineProperty(exports, "parseJATSFront", { enumerable: true, get: function () { return parse_jats_article_1.parseJATSFront; } });
21
+ Object.defineProperty(exports, "parseJATSBody", { enumerable: true, get: function () { return parse_jats_article_1.parseJATSBody; } });
22
22
  Object.defineProperty(exports, "parseJATSArticle", { enumerable: true, get: function () { return parse_jats_article_1.parseJATSArticle; } });
@@ -18,13 +18,11 @@ 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;
22
- const json_schema_1 = require("@manuscripts/json-schema");
21
+ exports.jatsBodyDOMParser = void 0;
23
22
  const mime_1 = __importDefault(require("mime"));
24
23
  const prosemirror_model_1 = require("prosemirror-model");
25
24
  const schema_1 = require("../../schema");
26
25
  const transformer_1 = require("../../transformer");
27
- const jats_comments_1 = require("./jats-comments");
28
26
  const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
29
27
  const chooseContentType = (graphicNode) => {
30
28
  if (graphicNode) {
@@ -39,12 +37,6 @@ const chooseContentType = (graphicNode) => {
39
37
  }
40
38
  }
41
39
  };
42
- const parsePriority = (priority) => {
43
- if (!priority) {
44
- return undefined;
45
- }
46
- return parseInt(priority);
47
- };
48
40
  const getEquationContent = (p) => {
49
41
  var _a;
50
42
  const element = p;
@@ -109,174 +101,6 @@ const marks = [
109
101
  },
110
102
  ];
111
103
  const nodes = [
112
- {
113
- tag: 'article',
114
- node: 'manuscript',
115
- getAttrs: (node) => {
116
- const element = node;
117
- return {
118
- doi: element.getAttribute('DOI'),
119
- articleType: element.getAttribute('article-type') || '',
120
- prototype: element.getAttribute('prototype') || '',
121
- primaryLanguageCode: element.getAttribute('primary-language-code') || '',
122
- };
123
- },
124
- },
125
- {
126
- tag: 'article-title',
127
- node: 'title',
128
- getAttrs: (node) => {
129
- const element = node;
130
- return {
131
- id: element.getAttribute('id'),
132
- };
133
- },
134
- },
135
- {
136
- tag: 'highlight-marker',
137
- node: 'highlight_marker',
138
- getAttrs: (node) => {
139
- var _a;
140
- const element = node;
141
- const id = element.getAttribute('id');
142
- return {
143
- id: id,
144
- position: (_a = element.getAttribute('position')) !== null && _a !== void 0 ? _a : '',
145
- };
146
- },
147
- },
148
- {
149
- tag: 'comment-annotation',
150
- node: 'comment',
151
- getAttrs: (node) => {
152
- const element = node;
153
- return {
154
- id: element.getAttribute('id'),
155
- contents: element.textContent,
156
- contributions: [
157
- {
158
- _id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.Contribution),
159
- objecType: json_schema_1.ObjectTypes.Contribution,
160
- profileID: jats_comments_1.DEFAULT_PROFILE_ID,
161
- timestamp: (0, json_schema_1.timestamp)(),
162
- },
163
- ],
164
- };
165
- },
166
- },
167
- {
168
- tag: 'author-notes',
169
- node: 'author_notes',
170
- getAttrs: (node) => {
171
- const element = node;
172
- return {
173
- id: element.getAttribute('id'),
174
- };
175
- },
176
- },
177
- {
178
- tag: 'fn-author',
179
- node: 'footnote',
180
- getAttrs: (node) => {
181
- const element = node;
182
- return {
183
- id: element.getAttribute('id'),
184
- kind: 'footnote',
185
- };
186
- },
187
- },
188
- {
189
- tag: 'corresp',
190
- node: 'corresp',
191
- getAttrs: (node) => {
192
- const element = node;
193
- return {
194
- id: element.getAttribute('id'),
195
- label: element.getAttribute('label'),
196
- };
197
- },
198
- },
199
- {
200
- tag: 'contributor',
201
- node: 'contributor',
202
- getAttrs: (node) => {
203
- const element = node;
204
- const footnote = [];
205
- const affiliations = [];
206
- const corresp = [];
207
- element.querySelectorAll('fn').forEach((fn) => {
208
- const noteID = fn.getAttribute('noteID');
209
- const noteLabel = fn.getAttribute('noteLabel');
210
- if (noteID && noteLabel) {
211
- footnote.push({ noteID, noteLabel });
212
- }
213
- });
214
- element.querySelectorAll('corresp').forEach((correspondence) => {
215
- const correspLabel = correspondence.getAttribute('correspLabel');
216
- const correspID = correspondence.getAttribute('correspID');
217
- if (correspID && correspLabel) {
218
- corresp.push({ correspID, correspLabel });
219
- }
220
- });
221
- element.querySelectorAll('aff').forEach((aff) => {
222
- const affID = aff.getAttribute('affiliationID');
223
- if (affID) {
224
- affiliations.push(affID);
225
- }
226
- });
227
- const isCorrespondingEl = element.getAttribute('isCorresponding');
228
- return {
229
- id: element.getAttribute('id'),
230
- role: 'author',
231
- isCorresponding: isCorrespondingEl
232
- ? isCorrespondingEl === 'true'
233
- : undefined,
234
- bibliographicName: {
235
- given: element.getAttribute('given'),
236
- family: element.getAttribute('family'),
237
- ObjectType: 'MPBibliographicName',
238
- _id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.BibliographicName),
239
- },
240
- affiliations,
241
- corresp: corresp.length ? corresp : undefined,
242
- footnote: footnote.length ? footnote : undefined,
243
- ORCIDIdentifier: element.getAttribute('ORCIDIdentifier'),
244
- priority: parsePriority(element.getAttribute('priority')),
245
- };
246
- },
247
- getContent: () => {
248
- return prosemirror_model_1.Fragment.from(schema_1.schema.text('_'));
249
- },
250
- },
251
- {
252
- tag: 'affiliation',
253
- node: 'affiliation',
254
- getAttrs: (node) => {
255
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
256
- const element = node;
257
- const emailEl = element.querySelector('email');
258
- return {
259
- id: element.getAttribute('id'),
260
- institution: (_a = element.getAttribute('institution')) !== null && _a !== void 0 ? _a : '',
261
- department: (_b = element.getAttribute('department')) !== null && _b !== void 0 ? _b : '',
262
- addressLine1: (_c = element.getAttribute('addressLine1')) !== null && _c !== void 0 ? _c : '',
263
- addressLine2: (_d = element.getAttribute('addressLine2')) !== null && _d !== void 0 ? _d : '',
264
- addressLine3: (_e = element.getAttribute('addressLine3')) !== null && _e !== void 0 ? _e : '',
265
- postCode: (_f = element.getAttribute('postCode')) !== null && _f !== void 0 ? _f : '',
266
- country: (_g = element.getAttribute('country')) !== null && _g !== void 0 ? _g : '',
267
- email: emailEl
268
- ? {
269
- href: (_h = emailEl.getAttributeNS(XLINK_NAMESPACE, 'href')) !== null && _h !== void 0 ? _h : '',
270
- text: (_k = (_j = emailEl.textContent) === null || _j === void 0 ? void 0 : _j.trim()) !== null && _k !== void 0 ? _k : '',
271
- }
272
- : undefined,
273
- priority: parsePriority(element.getAttribute('priority')),
274
- };
275
- },
276
- getContent: () => {
277
- return prosemirror_model_1.Fragment.from(schema_1.schema.text('_'));
278
- },
279
- },
280
104
  {
281
105
  tag: 'attrib',
282
106
  node: 'attribution',
@@ -285,6 +109,10 @@ const nodes = [
285
109
  tag: 'back',
286
110
  ignore: true,
287
111
  },
112
+ {
113
+ tag: 'body',
114
+ node: 'manuscript',
115
+ },
288
116
  {
289
117
  tag: 'break',
290
118
  node: 'hard_break',
@@ -304,13 +132,13 @@ const nodes = [
304
132
  const title = element.querySelector('title');
305
133
  if (title) {
306
134
  const captionTitle = schema.nodes.caption_title.create();
307
- content.push(exports.jatsDOMParser.parse(title, { topNode: captionTitle }));
135
+ content.push(exports.jatsBodyDOMParser.parse(title, { topNode: captionTitle }));
308
136
  }
309
137
  const paragraphs = element.querySelectorAll('p');
310
138
  if (paragraphs.length) {
311
139
  const figcaption = schema.nodes.caption.create();
312
140
  for (const paragraph of paragraphs) {
313
- content.push(exports.jatsDOMParser.parse(paragraph, { topNode: figcaption }));
141
+ content.push(exports.jatsBodyDOMParser.parse(paragraph, { topNode: figcaption }));
314
142
  }
315
143
  }
316
144
  return prosemirror_model_1.Fragment.from(content);
@@ -501,7 +329,7 @@ const nodes = [
501
329
  const paragraphs = [];
502
330
  node.childNodes.forEach((p) => {
503
331
  const paragraph = schema_1.schema.nodes.paragraph.create();
504
- const content = exports.jatsDOMParser.parse(p, {
332
+ const content = exports.jatsBodyDOMParser.parse(p, {
505
333
  topNode: paragraph,
506
334
  });
507
335
  paragraphs.push(content);
@@ -600,54 +428,6 @@ const nodes = [
600
428
  tag: 'sec[sec-type="backmatter"]',
601
429
  node: 'backmatter',
602
430
  },
603
- {
604
- tag: 'bibliography-element',
605
- node: 'bibliography_element',
606
- getAttrs: (node) => {
607
- const element = node;
608
- return {
609
- id: element.getAttribute('id'),
610
- };
611
- },
612
- },
613
- {
614
- tag: 'bibliography-item',
615
- node: 'bibliography_item',
616
- getAttrs: (node) => {
617
- const element = node;
618
- const authors = [];
619
- element.querySelectorAll('author').forEach((author) => {
620
- authors.push({
621
- _id: author.getAttribute('id') || '',
622
- given: author.getAttribute('given') || '',
623
- family: author.getAttribute('family') || '',
624
- objectType: 'MPBibliographicName',
625
- });
626
- });
627
- const issuedEl = element.querySelector('issued');
628
- const issued = issuedEl
629
- ? {
630
- objectType: 'MPBibliographicDate',
631
- _id: issuedEl.getAttribute('id'),
632
- 'date-parts': [[issuedEl.getAttribute('year')]],
633
- }
634
- : undefined;
635
- return {
636
- id: element.getAttribute('id'),
637
- type: element.getAttribute('type'),
638
- containerTitle: element.getAttribute('container-title'),
639
- volume: element.getAttribute('volume'),
640
- issue: element.getAttribute('issue'),
641
- supplement: element.getAttribute('supplement'),
642
- page: element.getAttribute('page'),
643
- title: element.getAttribute('title'),
644
- literal: element.getAttribute('literal'),
645
- author: authors,
646
- issued,
647
- DOI: element.getAttribute('DOI'),
648
- };
649
- },
650
- },
651
431
  {
652
432
  tag: 'sec',
653
433
  node: 'section',
@@ -800,4 +580,4 @@ const nodes = [
800
580
  },
801
581
  },
802
582
  ];
803
- exports.jatsDOMParser = new prosemirror_model_1.DOMParser(schema_1.schema, [...marks, ...nodes]);
583
+ exports.jatsBodyDOMParser = new prosemirror_model_1.DOMParser(schema_1.schema, [...marks, ...nodes]);
@@ -302,74 +302,4 @@ 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
- return bibliographyItem;
374
- },
375
305
  };
@@ -15,10 +15,10 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.markComments = exports.parseJATSComment = exports.isJATSComment = exports.DEFAULT_PROFILE_ID = void 0;
19
- const json_schema_1 = require("@manuscripts/json-schema");
18
+ exports.createReferenceComments = exports.createComments = exports.markComments = exports.parseJATSComment = exports.isJATSComment = void 0;
19
+ const uuid_1 = require("uuid");
20
20
  const transformer_1 = require("../../transformer");
21
- exports.DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
21
+ const 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,34 +27,35 @@ exports.isJATSComment = isJATSComment;
27
27
  const parseJATSComment = (node) => {
28
28
  const text = node.textContent;
29
29
  if (text) {
30
+ const id = /id="(.+)"/.exec(text);
30
31
  const queryText = /queryText="(.+)"/.exec(text);
31
- if (queryText) {
32
- const parentNode = node.parentNode;
33
- const index = parentNode.outerHTML.indexOf(queryText[1]);
32
+ if (id && queryText) {
34
33
  return {
35
- id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.CommentAnnotation),
34
+ id: id[1],
36
35
  text: queryText[1],
37
- index,
38
36
  };
39
37
  }
40
38
  }
41
39
  };
42
40
  exports.parseJATSComment = parseJATSComment;
43
41
  const markComments = (doc) => {
44
- var _a;
42
+ const marks = [];
45
43
  const root = doc.getRootNode();
46
44
  const queue = [root];
47
- const commentsElement = doc.createElement('comments-annotations');
48
45
  while (queue.length !== 0) {
49
46
  const node = queue.shift();
50
47
  if (node) {
51
48
  if ((0, exports.isJATSComment)(node)) {
52
49
  const comment = (0, exports.parseJATSComment)(node);
53
50
  if (comment) {
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);
51
+ const token = addMark(doc, node);
52
+ if (token) {
53
+ const mark = {
54
+ token,
55
+ comment,
56
+ };
57
+ marks.push(mark);
58
+ }
58
59
  }
59
60
  }
60
61
  node.childNodes.forEach((child) => {
@@ -62,20 +63,96 @@ const markComments = (doc) => {
62
63
  });
63
64
  }
64
65
  }
65
- if (commentsElement.hasChildNodes()) {
66
- doc.documentElement.appendChild(commentsElement);
67
- }
66
+ return marks;
68
67
  };
69
68
  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;
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;
76
+ }
75
77
  };
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;
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
+ };
145
+ };
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;
81
157
  };
158
+ exports.createReferenceComments = createReferenceComments;