@manuscripts/transform 2.3.35 → 2.3.37-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/jats/importer/create-article-node.js +31 -0
  2. package/dist/cjs/jats/importer/index.js +3 -3
  3. package/dist/cjs/jats/importer/jats-body-transformations.js +70 -0
  4. package/dist/cjs/jats/importer/jats-comments.js +27 -104
  5. package/dist/cjs/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +229 -9
  6. package/dist/cjs/jats/importer/jats-front-transformations.js +262 -0
  7. package/dist/cjs/jats/importer/jats-journal-meta-parser.js +8 -1
  8. package/dist/cjs/jats/importer/jats-parser-utils.js +39 -5
  9. package/dist/cjs/jats/importer/jats-reference-parser.js +16 -27
  10. package/dist/cjs/jats/importer/jats-references.js +18 -18
  11. package/dist/cjs/jats/importer/parse-jats-article.js +42 -78
  12. package/dist/cjs/jats/index.js +4 -3
  13. package/dist/cjs/jats/jats-exporter.js +252 -354
  14. package/dist/cjs/{transformer → jats}/labels.js +3 -3
  15. package/dist/cjs/lib/utils.js +9 -1
  16. package/dist/cjs/schema/index.js +2 -0
  17. package/dist/cjs/schema/nodes/box_element.js +55 -0
  18. package/dist/cjs/transformer/id.js +10 -5
  19. package/dist/cjs/transformer/index.js +0 -18
  20. package/dist/cjs/transformer/node-types.js +1 -0
  21. package/dist/cjs/transformer/section-category.js +8 -0
  22. package/dist/cjs/version.js +1 -1
  23. package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
  24. package/dist/es/jats/importer/index.js +2 -1
  25. package/dist/es/jats/importer/jats-body-transformations.js +70 -0
  26. package/dist/es/jats/importer/jats-comments.js +26 -101
  27. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
  28. package/dist/es/jats/importer/jats-front-transformations.js +259 -0
  29. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  30. package/dist/es/jats/importer/jats-parser-utils.js +40 -6
  31. package/dist/es/jats/importer/jats-reference-parser.js +16 -27
  32. package/dist/es/jats/importer/jats-references.js +18 -18
  33. package/dist/es/jats/importer/parse-jats-article.js +43 -77
  34. package/dist/es/jats/index.js +3 -1
  35. package/dist/es/jats/jats-exporter.js +254 -356
  36. package/dist/es/{transformer → jats}/labels.js +3 -3
  37. package/dist/es/lib/utils.js +7 -0
  38. package/dist/es/schema/index.js +2 -0
  39. package/dist/es/schema/nodes/box_element.js +52 -0
  40. package/dist/es/transformer/id.js +8 -3
  41. package/dist/es/transformer/index.js +0 -16
  42. package/dist/es/transformer/node-types.js +1 -0
  43. package/dist/es/transformer/section-category.js +8 -0
  44. package/dist/es/version.js +1 -1
  45. package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
  46. package/dist/types/jats/importer/index.d.ts +2 -1
  47. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  48. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  49. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  50. package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
  51. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  52. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  53. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  54. package/dist/types/jats/index.d.ts +3 -1
  55. package/dist/types/jats/jats-exporter.d.ts +10 -29
  56. package/dist/types/{transformer → jats}/labels.d.ts +2 -1
  57. package/dist/types/lib/utils.d.ts +3 -0
  58. package/dist/types/schema/nodes/bibliography_item.d.ts +28 -5
  59. package/dist/{es/transformer/models.js → types/schema/nodes/box_element.d.ts} +10 -0
  60. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  61. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  62. package/dist/types/schema/types.d.ts +1 -1
  63. package/dist/types/transformer/id.d.ts +5 -2
  64. package/dist/types/transformer/index.d.ts +0 -16
  65. package/dist/types/transformer/section-category.d.ts +2 -2
  66. package/dist/types/version.d.ts +1 -1
  67. package/package.json +2 -1
  68. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  69. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  70. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  71. package/dist/cjs/transformer/builders.js +0 -219
  72. package/dist/cjs/transformer/decode.js +0 -874
  73. package/dist/cjs/transformer/document-object-types.js +0 -31
  74. package/dist/cjs/transformer/encode.js +0 -664
  75. package/dist/cjs/transformer/footnote-category.js +0 -20
  76. package/dist/cjs/transformer/footnotes-order.js +0 -60
  77. package/dist/cjs/transformer/highlight-markers.js +0 -138
  78. package/dist/cjs/transformer/html.js +0 -400
  79. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  80. package/dist/cjs/transformer/model-map.js +0 -26
  81. package/dist/cjs/transformer/object-types.js +0 -57
  82. package/dist/cjs/transformer/project-bundle.js +0 -94
  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/jats-front-parser.js +0 -315
  86. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  87. package/dist/es/transformer/builders.js +0 -186
  88. package/dist/es/transformer/decode.js +0 -864
  89. package/dist/es/transformer/document-object-types.js +0 -28
  90. package/dist/es/transformer/encode.js +0 -654
  91. package/dist/es/transformer/footnote-category.js +0 -16
  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/update-identifiers.js +0 -87
  101. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  102. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  103. package/dist/types/transformer/builders.d.ts +0 -61
  104. package/dist/types/transformer/decode.d.ts +0 -51
  105. package/dist/types/transformer/document-object-types.d.ts +0 -17
  106. package/dist/types/transformer/encode.d.ts +0 -29
  107. package/dist/types/transformer/footnote-category.d.ts +0 -17
  108. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  109. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  110. package/dist/types/transformer/html.d.ts +0 -36
  111. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  112. package/dist/types/transformer/model-map.d.ts +0 -19
  113. package/dist/types/transformer/models.d.ts +0 -48
  114. package/dist/types/transformer/object-types.d.ts +0 -30
  115. package/dist/types/transformer/project-bundle.d.ts +0 -30
  116. package/dist/types/transformer/serializer.d.ts +0 -19
  117. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  118. /package/dist/cjs/{transformer → jats}/filename.js +0 -0
  119. /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
  120. /package/dist/es/{transformer → jats}/filename.js +0 -0
  121. /package/dist/es/{transformer → jats}/timestamp.js +0 -0
  122. /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
  123. /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
@@ -17,7 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.buildTargets = void 0;
19
19
  const schema_1 = require("../schema");
20
- const node_names_1 = require("./node-names");
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)) {
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
18
+ exports.setElementAttributes = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
19
19
  const bibliography_section_1 = require("../schema/nodes/bibliography_section");
20
20
  const graphical_abstract_section_1 = require("../schema/nodes/graphical_abstract_section");
21
21
  function* iterateChildren(node, recurse = false) {
@@ -83,3 +83,11 @@ const getTrimmedTextContent = (node, querySelector) => {
83
83
  return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
84
84
  };
85
85
  exports.getTrimmedTextContent = getTrimmedTextContent;
86
+ const setElementAttributes = (element, attributes) => {
87
+ Object.entries(attributes).forEach(([key, value]) => {
88
+ if (value) {
89
+ element.setAttribute(key, value);
90
+ }
91
+ });
92
+ };
93
+ exports.setElementAttributes = setElementAttributes;
@@ -43,6 +43,7 @@ const bibliography_item_1 = require("./nodes/bibliography_item");
43
43
  const bibliography_section_1 = require("./nodes/bibliography_section");
44
44
  const blockquote_element_1 = require("./nodes/blockquote_element");
45
45
  const body_1 = require("./nodes/body");
46
+ const box_element_1 = require("./nodes/box_element");
46
47
  const caption_1 = require("./nodes/caption");
47
48
  const caption_title_1 = require("./nodes/caption_title");
48
49
  const citation_1 = require("./nodes/citation");
@@ -237,5 +238,6 @@ exports.schema = new prosemirror_model_1.Schema({
237
238
  supplement: supplement_1.supplement,
238
239
  author_notes: author_notes_1.authorNotes,
239
240
  corresp: corresp_1.corresp,
241
+ box_element: box_element_1.box_element,
240
242
  },
241
243
  });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2019 Atypon Systems LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.box_element = void 0;
19
+ exports.box_element = {
20
+ content: 'figcaption? section?',
21
+ attrs: {
22
+ id: { default: '' },
23
+ label: { default: '' },
24
+ dataTracked: { default: null },
25
+ },
26
+ group: 'block element',
27
+ selectable: false,
28
+ parseDOM: [
29
+ {
30
+ tag: 'div.boxed-text',
31
+ getAttrs: (p) => {
32
+ const dom = p;
33
+ const attrs = {
34
+ id: dom.getAttribute('id') || undefined,
35
+ label: dom.getAttribute('label') || undefined,
36
+ };
37
+ return attrs;
38
+ },
39
+ },
40
+ ],
41
+ toDOM: (node) => {
42
+ const boxElementNode = node;
43
+ const attrs = {};
44
+ if (boxElementNode.attrs.id) {
45
+ attrs.id = boxElementNode.attrs.id;
46
+ }
47
+ if (boxElementNode.attrs.label) {
48
+ attrs.label = boxElementNode.attrs.label;
49
+ }
50
+ return [
51
+ 'div',
52
+ Object.assign({ class: 'boxed-text' }, attrs),
53
+ ];
54
+ },
55
+ };
@@ -15,14 +15,19 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.generateID = exports.generateNodeID = void 0;
18
+ exports.generateNodeID = exports.generateID = exports.ExtraObjectTypes = void 0;
19
19
  const uuid_1 = require("uuid");
20
20
  const node_types_1 = require("./node-types");
21
- const generateNodeID = (type) => {
22
- return node_types_1.nodeTypesMap.get(type) + ':' + (0, uuid_1.v4)().toUpperCase();
23
- };
24
- exports.generateNodeID = generateNodeID;
21
+ var ExtraObjectTypes;
22
+ (function (ExtraObjectTypes) {
23
+ ExtraObjectTypes["PlaceholderElement"] = "MPPlaceholderElement";
24
+ ExtraObjectTypes["GeneralTableFootnote"] = "MPGeneralTableFootnote";
25
+ })(ExtraObjectTypes = exports.ExtraObjectTypes || (exports.ExtraObjectTypes = {}));
25
26
  const generateID = (objectType) => {
26
27
  return objectType + ':' + (0, uuid_1.v4)().toUpperCase();
27
28
  };
28
29
  exports.generateID = generateID;
30
+ const generateNodeID = (type) => {
31
+ return node_types_1.nodeTypesMap.get(type) + ':' + (0, uuid_1.v4)().toUpperCase();
32
+ };
33
+ exports.generateNodeID = generateNodeID;
@@ -29,26 +29,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
29
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.createTestDoc = void 0;
33
- __exportStar(require("./builders"), exports);
34
- __exportStar(require("./decode"), exports);
35
- __exportStar(require("./document-object-types"), exports);
36
- __exportStar(require("./encode"), exports);
37
- __exportStar(require("./filename"), exports);
38
- __exportStar(require("./highlight-markers"), exports);
39
- __exportStar(require("./html"), exports);
40
32
  __exportStar(require("./id"), exports);
41
- __exportStar(require("./labels"), exports);
42
- __exportStar(require("./manuscript-dependencies"), exports);
43
- __exportStar(require("./models"), exports);
44
33
  __exportStar(require("./node-names"), exports);
45
34
  __exportStar(require("./node-title"), exports);
46
35
  __exportStar(require("./node-types"), exports);
47
- __exportStar(require("./object-types"), exports);
48
- __exportStar(require("./project-bundle"), exports);
49
36
  __exportStar(require("./section-category"), exports);
50
- __exportStar(require("./serializer"), exports);
51
- __exportStar(require("./timestamp"), exports);
52
- __exportStar(require("./update-identifiers"), exports);
53
- var doc_1 = require("./__tests__/__helpers__/doc");
54
- Object.defineProperty(exports, "createTestDoc", { enumerable: true, get: function () { return doc_1.createTestDoc; } });
@@ -62,6 +62,7 @@ exports.nodeTypesMap = new Map([
62
62
  [schema_1.schema.nodes.supplement, json_schema_1.ObjectTypes.Supplement],
63
63
  [schema_1.schema.nodes.author_notes, json_schema_1.ObjectTypes.AuthorNotes],
64
64
  [schema_1.schema.nodes.corresp, json_schema_1.ObjectTypes.Corresponding],
65
+ [schema_1.schema.nodes.box_element, json_schema_1.ObjectTypes.Section],
65
66
  ]);
66
67
  const isExecutableNodeType = (type) => (0, schema_1.hasGroup)(type, schema_1.GROUP_EXECUTABLE);
67
68
  exports.isExecutableNodeType = isExecutableNodeType;
@@ -40,6 +40,8 @@ const chooseSectionNodeType = (category) => {
40
40
  return schema_1.schema.nodes.keywords;
41
41
  case 'MPSectionCategory:toc':
42
42
  return schema_1.schema.nodes.toc_section;
43
+ case 'MPSectionCategory:box-element':
44
+ return schema_1.schema.nodes.box_element;
43
45
  default:
44
46
  return schema_1.schema.nodes.section;
45
47
  }
@@ -84,6 +86,8 @@ const buildSectionCategory = (node) => {
84
86
  return 'MPSectionCategory:toc';
85
87
  case schema_1.schema.nodes.graphical_abstract_section:
86
88
  return 'MPSectionCategory:abstract-graphical';
89
+ case schema_1.schema.nodes.box_element:
90
+ return 'MPSectionCategory:box-element';
87
91
  default:
88
92
  return node.attrs.category || undefined;
89
93
  }
@@ -197,6 +201,8 @@ const chooseSectionCategoryByType = (secType) => {
197
201
  return 'MPSectionCategory:supported-by';
198
202
  case 'ethics-statement':
199
203
  return 'MPSectionCategory:ethics-statement';
204
+ case 'box-element':
205
+ return 'MPSectionCategory:box-element';
200
206
  default:
201
207
  return undefined;
202
208
  }
@@ -253,6 +259,8 @@ const chooseSectionCategoryFromTitle = (title) => {
253
259
  case 'financial-disclosure':
254
260
  case 'funding information':
255
261
  return 'MPSectionCategory:financial-disclosure';
262
+ case 'box-element':
263
+ return 'MPSectionCategory:box-element';
256
264
  }
257
265
  };
258
266
  exports.chooseSectionCategoryFromTitle = chooseSectionCategoryFromTitle;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "2.3.35";
4
+ exports.VERSION = "2.3.37-LEAN-3911.0";
@@ -1,6 +1,5 @@
1
- "use strict";
2
1
  /*!
3
- * © 2019 Atypon Systems LLC
2
+ * © 2024 Atypon Systems LLC
4
3
  *
5
4
  * Licensed under the Apache License, Version 2.0 (the "License");
6
5
  * you may not use this file except in compliance with the License.
@@ -14,10 +13,15 @@
14
13
  * See the License for the specific language governing permissions and
15
14
  * limitations under the License.
16
15
  */
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
+ import { schema } from '../../schema';
17
+ import { defaultTitle } from './jats-front-transformations';
18
+ export const createArticleNode = (manuscript) => {
19
+ const title = schema.nodes.title.createChecked({}, schema.text(defaultTitle));
20
+ return schema.nodes.manuscript.createAndFill({
21
+ id: manuscript._id,
22
+ doi: manuscript.DOI,
23
+ articleType: manuscript.articleType,
24
+ prototype: manuscript.prototype,
25
+ primaryLanguageCode: manuscript.primaryLanguageCode,
26
+ }, title);
19
27
  };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.xmlSerializer = void 0;
22
- const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
23
- exports.xmlSerializer = { serializeToString: w3c_xmlserializer_1.default };
@@ -13,4 +13,5 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export { parseJATSFront, parseJATSBody, parseJATSArticle, } from './parse-jats-article';
16
+ export { createArticleNode } from './create-article-node';
17
+ export { parseJATSArticle } from './parse-jats-article';
@@ -299,4 +299,74 @@ export const jatsBodyTransformations = {
299
299
  body.prepend(section);
300
300
  }
301
301
  },
302
+ moveReferencesToBackmatter(body, references, createElement) {
303
+ const backmatter = body.querySelector('sec[sec-type="backmatter"]');
304
+ if (!references || !references.items.size || !backmatter) {
305
+ return;
306
+ }
307
+ const bibliographySection = this.createBibliographySection(createElement);
308
+ const bibliographyElement = createElement('bibliography-element');
309
+ references.getBibliographyItems().forEach((item) => {
310
+ const bibliographyItem = this.createBibliographyItem(item, createElement);
311
+ bibliographyElement.appendChild(bibliographyItem);
312
+ });
313
+ bibliographySection.appendChild(bibliographyElement);
314
+ backmatter.appendChild(bibliographySection);
315
+ },
316
+ createBibliographySection(createElement) {
317
+ const section = createElement('sec');
318
+ section.setAttribute('sec-type', 'bibliography_section');
319
+ const title = createElement('title');
320
+ title.textContent = 'References';
321
+ section.appendChild(title);
322
+ return section;
323
+ },
324
+ createBibliographyItem(item, createElement) {
325
+ var _a, _b, _c;
326
+ const bibliographyItem = createElement('bibliography-item');
327
+ bibliographyItem.setAttribute('id', item.id);
328
+ bibliographyItem.setAttribute('type', item.type);
329
+ (_a = item.author) === null || _a === void 0 ? void 0 : _a.forEach((author) => {
330
+ const authorElement = createElement('author');
331
+ authorElement.setAttribute('id', author._id);
332
+ authorElement.setAttribute('family', author.family || '');
333
+ authorElement.setAttribute('given', author.given || '');
334
+ bibliographyItem.appendChild(authorElement);
335
+ });
336
+ if (item.issued) {
337
+ const issuedEl = createElement('issued');
338
+ issuedEl.setAttribute('id', ((_b = item.issued) === null || _b === void 0 ? void 0 : _b._id) || '');
339
+ const dateParts = item.issued['date-parts'];
340
+ const year = (_c = dateParts === null || dateParts === void 0 ? void 0 : dateParts[0]) === null || _c === void 0 ? void 0 : _c[0];
341
+ if (year) {
342
+ issuedEl.setAttribute('year', year.toString());
343
+ }
344
+ bibliographyItem.appendChild(issuedEl);
345
+ }
346
+ if (item.containerTitle) {
347
+ bibliographyItem.setAttribute('containerTitle', item.containerTitle);
348
+ }
349
+ if (item.volume) {
350
+ bibliographyItem.setAttribute('volume', item.volume.toString());
351
+ }
352
+ if (item.issue) {
353
+ bibliographyItem.setAttribute('issue', item.issue.toString());
354
+ }
355
+ if (item.supplement) {
356
+ bibliographyItem.setAttribute('supplement', item.supplement);
357
+ }
358
+ if (item.page) {
359
+ bibliographyItem.setAttribute('page', item.page.toString());
360
+ }
361
+ if (item.title) {
362
+ bibliographyItem.setAttribute('title', item.title);
363
+ }
364
+ if (item.literal) {
365
+ bibliographyItem.setAttribute('literal', item.literal);
366
+ }
367
+ if (item.doi) {
368
+ bibliographyItem.setAttribute('DOI', item.doi);
369
+ }
370
+ return bibliographyItem;
371
+ },
302
372
  };
@@ -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 { v4 as uuidv4 } from 'uuid';
17
- import { buildComment, buildContribution, highlightableFields, isHighlightableModel, isKeyword, } from '../../transformer';
18
- const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
16
+ import { ObjectTypes } from '@manuscripts/json-schema';
17
+ import { generateID } from '../../transformer';
18
+ export const DEFAULT_PROFILE_ID = 'MPUserProfile:0000000000000000000000000000000000000001';
19
19
  export const isJATSComment = (node) => {
20
20
  return (node.nodeType === node.PROCESSING_INSTRUCTION_NODE &&
21
21
  node.nodeName === 'AuthorQuery');
@@ -23,34 +23,33 @@ export const isJATSComment = (node) => {
23
23
  export const parseJATSComment = (node) => {
24
24
  const text = node.textContent;
25
25
  if (text) {
26
- const id = /id="(.+)"/.exec(text);
27
26
  const queryText = /queryText="(.+)"/.exec(text);
28
- if (id && queryText) {
27
+ if (queryText) {
28
+ const parentNode = node.parentNode;
29
+ const index = parentNode.outerHTML.indexOf(queryText[1]);
29
30
  return {
30
- id: id[1],
31
+ id: generateID(ObjectTypes.CommentAnnotation),
31
32
  text: queryText[1],
33
+ index,
32
34
  };
33
35
  }
34
36
  }
35
37
  };
36
38
  export const markComments = (doc) => {
37
- const marks = [];
39
+ var _a;
38
40
  const root = doc.getRootNode();
39
41
  const queue = [root];
42
+ const commentsElement = doc.createElement('comments-annotations');
40
43
  while (queue.length !== 0) {
41
44
  const node = queue.shift();
42
45
  if (node) {
43
46
  if (isJATSComment(node)) {
44
47
  const comment = parseJATSComment(node);
45
48
  if (comment) {
46
- const token = addMark(doc, node);
47
- if (token) {
48
- const mark = {
49
- token,
50
- comment,
51
- };
52
- marks.push(mark);
53
- }
49
+ const highlightMarker = createHighlightMarkerElement(doc, comment.id);
50
+ (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(highlightMarker, node);
51
+ const commentElement = createCommentElement(doc, comment);
52
+ commentsElement.appendChild(commentElement);
54
53
  }
55
54
  }
56
55
  node.childNodes.forEach((child) => {
@@ -58,93 +57,19 @@ export const markComments = (doc) => {
58
57
  });
59
58
  }
60
59
  }
61
- return marks;
62
- };
63
- const addMark = (doc, node) => {
64
- const parent = node.parentElement;
65
- if (parent) {
66
- const token = uuidv4();
67
- const tokenNode = doc.createTextNode(token);
68
- parent.insertBefore(tokenNode, node);
69
- return token;
70
- }
71
- };
72
- export const createComments = (models, marks) => {
73
- const comments = [];
74
- for (const model of models) {
75
- if (isHighlightableModel(model)) {
76
- comments.push(...processModel(model, marks));
77
- }
78
- else if (isKeyword(model)) {
79
- comments.push(...processKeyword(model, marks));
80
- }
60
+ if (commentsElement.hasChildNodes()) {
61
+ doc.documentElement.appendChild(commentsElement);
81
62
  }
82
- return comments;
83
- };
84
- const getFieldMarks = (content, marks) => {
85
- return marks
86
- .filter((m) => content.indexOf(m.token) >= 0)
87
- .sort((a, b) => content.indexOf(a.token) - content.indexOf(b.token));
88
63
  };
89
- const processModel = (model, marks) => {
90
- const comments = [];
91
- for (const field of highlightableFields) {
92
- const content = model[field];
93
- if (!content) {
94
- continue;
95
- }
96
- const results = processContent(model, content, getFieldMarks(content, marks));
97
- model[field] = results.content;
98
- comments.push(...results.comments);
99
- }
100
- return comments;
64
+ const createHighlightMarkerElement = (doc, id) => {
65
+ const highlightMarker = doc.createElement('highlight-marker');
66
+ highlightMarker.setAttribute('id', id);
67
+ highlightMarker.setAttribute('position', 'point');
68
+ return highlightMarker;
101
69
  };
102
- const processKeyword = (model, marks) => {
103
- const comments = [];
104
- const name = model.name;
105
- let content = name;
106
- for (const mark of getFieldMarks(name, marks)) {
107
- content = name.replace(mark.token, '');
108
- const target = model.containedGroup;
109
- if (!target) {
110
- continue;
111
- }
112
- const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
113
- const comment = buildComment(target, mark.comment.text, undefined, contributions);
114
- model.name = content;
115
- comments.push(comment);
116
- }
117
- return comments;
118
- };
119
- const processContent = (model, content, marks) => {
120
- const comments = [];
121
- let result = content;
122
- for (const mark of marks) {
123
- const token = mark.token;
124
- const index = result.indexOf(token);
125
- result = result.replace(token, '');
126
- const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
127
- const selector = {
128
- from: index,
129
- to: index,
130
- };
131
- const comment = buildComment(model._id, mark.comment.text, selector, contributions);
132
- comments.push(comment);
133
- }
134
- return {
135
- content: result,
136
- comments,
137
- };
138
- };
139
- export const createReferenceComments = (references) => {
140
- const comments = [];
141
- for (const item of references.getBibliographyItems()) {
142
- const id = item._id;
143
- for (const comment of references.getComments(id)) {
144
- const contributions = [buildContribution(DEFAULT_PROFILE_ID)];
145
- const c = buildComment(id, comment.text, undefined, contributions);
146
- comments.push(c);
147
- }
148
- }
149
- return comments;
70
+ const createCommentElement = (doc, comment) => {
71
+ const commentElement = doc.createElement('comment-annotation');
72
+ commentElement.setAttribute('id', comment.id);
73
+ commentElement.textContent = comment.text;
74
+ return commentElement;
150
75
  };