@manuscripts/transform 2.3.32 → 2.3.34-LEAN-3911.2

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 (115) 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 +251 -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/nodes/footnotes_section.js +1 -1
  17. package/dist/cjs/transformer/id.js +6 -6
  18. package/dist/cjs/transformer/index.js +0 -18
  19. package/dist/cjs/version.js +1 -1
  20. package/dist/{cjs/transformer/serializer.js → es/jats/importer/create-article-node.js} +12 -8
  21. package/dist/es/jats/importer/index.js +2 -1
  22. package/dist/es/jats/importer/jats-body-transformations.js +70 -0
  23. package/dist/es/jats/importer/jats-comments.js +26 -101
  24. package/dist/es/jats/importer/{jats-body-dom-parser.js → jats-dom-parser.js} +230 -10
  25. package/dist/es/jats/importer/jats-front-transformations.js +259 -0
  26. package/dist/es/jats/importer/jats-journal-meta-parser.js +6 -0
  27. package/dist/es/jats/importer/jats-parser-utils.js +40 -6
  28. package/dist/es/jats/importer/jats-reference-parser.js +16 -27
  29. package/dist/es/jats/importer/jats-references.js +18 -18
  30. package/dist/es/jats/importer/parse-jats-article.js +43 -77
  31. package/dist/es/jats/index.js +3 -1
  32. package/dist/es/jats/jats-exporter.js +253 -356
  33. package/dist/es/{transformer → jats}/labels.js +3 -3
  34. package/dist/es/lib/utils.js +7 -0
  35. package/dist/es/schema/nodes/footnotes_section.js +1 -1
  36. package/dist/es/transformer/id.js +5 -4
  37. package/dist/es/transformer/index.js +0 -16
  38. package/dist/es/version.js +1 -1
  39. package/dist/{cjs/transformer/models.js → types/jats/importer/create-article-node.d.ts} +3 -3
  40. package/dist/types/jats/importer/index.d.ts +2 -1
  41. package/dist/types/jats/importer/jats-body-transformations.d.ts +5 -0
  42. package/dist/types/jats/importer/jats-comments.d.ts +4 -10
  43. package/dist/types/jats/importer/{jats-body-dom-parser.d.ts → jats-dom-parser.d.ts} +1 -1
  44. package/dist/types/jats/importer/jats-front-transformations.d.ts +38 -0
  45. package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +10 -0
  46. package/dist/types/jats/importer/jats-references.d.ts +19 -8
  47. package/dist/types/jats/importer/parse-jats-article.d.ts +12 -5
  48. package/dist/types/jats/index.d.ts +3 -1
  49. package/dist/types/jats/jats-exporter.d.ts +10 -29
  50. package/dist/types/{transformer → jats}/labels.d.ts +2 -1
  51. package/dist/types/lib/utils.d.ts +3 -0
  52. package/dist/types/schema/nodes/bibliography_item.d.ts +16 -6
  53. package/dist/types/schema/nodes/contributor.d.ts +10 -0
  54. package/dist/types/schema/nodes/keyword_group.d.ts +1 -0
  55. package/dist/types/transformer/id.d.ts +4 -3
  56. package/dist/types/transformer/index.d.ts +0 -16
  57. package/dist/types/version.d.ts +1 -1
  58. package/package.json +3 -2
  59. package/dist/cjs/__tests__/data/project-dump.json +0 -825
  60. package/dist/cjs/jats/importer/jats-front-parser.js +0 -321
  61. package/dist/cjs/transformer/__tests__/__helpers__/doc.js +0 -37
  62. package/dist/cjs/transformer/builders.js +0 -219
  63. package/dist/cjs/transformer/decode.js +0 -874
  64. package/dist/cjs/transformer/document-object-types.js +0 -31
  65. package/dist/cjs/transformer/encode.js +0 -664
  66. package/dist/cjs/transformer/footnote-category.js +0 -20
  67. package/dist/cjs/transformer/footnotes-order.js +0 -60
  68. package/dist/cjs/transformer/highlight-markers.js +0 -138
  69. package/dist/cjs/transformer/html.js +0 -400
  70. package/dist/cjs/transformer/manuscript-dependencies.js +0 -21
  71. package/dist/cjs/transformer/model-map.js +0 -26
  72. package/dist/cjs/transformer/object-types.js +0 -57
  73. package/dist/cjs/transformer/project-bundle.js +0 -94
  74. package/dist/cjs/transformer/update-identifiers.js +0 -93
  75. package/dist/es/__tests__/data/project-dump.json +0 -825
  76. package/dist/es/jats/importer/jats-front-parser.js +0 -315
  77. package/dist/es/transformer/__tests__/__helpers__/doc.js +0 -29
  78. package/dist/es/transformer/builders.js +0 -186
  79. package/dist/es/transformer/decode.js +0 -864
  80. package/dist/es/transformer/document-object-types.js +0 -28
  81. package/dist/es/transformer/encode.js +0 -654
  82. package/dist/es/transformer/footnote-category.js +0 -16
  83. package/dist/es/transformer/footnotes-order.js +0 -55
  84. package/dist/es/transformer/highlight-markers.js +0 -132
  85. package/dist/es/transformer/html.js +0 -393
  86. package/dist/es/transformer/manuscript-dependencies.js +0 -17
  87. package/dist/es/transformer/model-map.js +0 -22
  88. package/dist/es/transformer/models.js +0 -16
  89. package/dist/es/transformer/object-types.js +0 -52
  90. package/dist/es/transformer/project-bundle.js +0 -85
  91. package/dist/es/transformer/serializer.js +0 -17
  92. package/dist/es/transformer/update-identifiers.js +0 -87
  93. package/dist/types/jats/importer/jats-front-parser.d.ts +0 -84
  94. package/dist/types/transformer/__tests__/__helpers__/doc.d.ts +0 -18
  95. package/dist/types/transformer/builders.d.ts +0 -61
  96. package/dist/types/transformer/decode.d.ts +0 -51
  97. package/dist/types/transformer/document-object-types.d.ts +0 -17
  98. package/dist/types/transformer/encode.d.ts +0 -29
  99. package/dist/types/transformer/footnote-category.d.ts +0 -17
  100. package/dist/types/transformer/footnotes-order.d.ts +0 -22
  101. package/dist/types/transformer/highlight-markers.d.ts +0 -31
  102. package/dist/types/transformer/html.d.ts +0 -36
  103. package/dist/types/transformer/manuscript-dependencies.d.ts +0 -4
  104. package/dist/types/transformer/model-map.d.ts +0 -19
  105. package/dist/types/transformer/models.d.ts +0 -48
  106. package/dist/types/transformer/object-types.d.ts +0 -30
  107. package/dist/types/transformer/project-bundle.d.ts +0 -30
  108. package/dist/types/transformer/serializer.d.ts +0 -19
  109. package/dist/types/transformer/update-identifiers.d.ts +0 -23
  110. /package/dist/cjs/{transformer → jats}/filename.js +0 -0
  111. /package/dist/cjs/{transformer → jats}/timestamp.js +0 -0
  112. /package/dist/es/{transformer → jats}/filename.js +0 -0
  113. /package/dist/es/{transformer → jats}/timestamp.js +0 -0
  114. /package/dist/types/{transformer → jats}/filename.d.ts +0 -0
  115. /package/dist/types/{transformer → jats}/timestamp.d.ts +0 -0
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ /*!
3
+ * © 2024 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.jatsFrontTransformations = exports.defaultTitle = void 0;
19
+ const json_schema_1 = require("@manuscripts/json-schema");
20
+ const utils_1 = require("../../lib/utils");
21
+ const transformer_1 = require("../../transformer");
22
+ const jats_parser_utils_1 = require("./jats-parser-utils");
23
+ exports.defaultTitle = 'Untitled Manuscript';
24
+ exports.jatsFrontTransformations = {
25
+ setArticleAttrs(doc, template) {
26
+ var _a;
27
+ const doi = (_a = doc.querySelector('article-meta > article-id[pub-id-type="doi"]')) === null || _a === void 0 ? void 0 : _a.textContent;
28
+ const Attrs = {
29
+ DOI: doi !== null && doi !== void 0 ? doi : '',
30
+ prototype: template !== null && template !== void 0 ? template : '',
31
+ id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.Manuscript),
32
+ };
33
+ Object.entries(Attrs).forEach(([key, value]) => {
34
+ var _a;
35
+ if (value) {
36
+ (_a = doc.querySelector('article')) === null || _a === void 0 ? void 0 : _a.setAttribute(key, value);
37
+ }
38
+ });
39
+ },
40
+ createTitle(front, createElement) {
41
+ var _a;
42
+ let title = front.querySelector('article-meta > title-group > article-title');
43
+ if (title) {
44
+ title.innerHTML = (_a = (0, jats_parser_utils_1.htmlFromJatsNode)(title, createElement)) !== null && _a !== void 0 ? _a : exports.defaultTitle;
45
+ }
46
+ else {
47
+ title = createElement('article-title');
48
+ title.textContent = exports.defaultTitle;
49
+ }
50
+ return title;
51
+ },
52
+ createAuthorNotes(document, createElement) {
53
+ const authornotes = document.querySelector('article-meta > author-notes');
54
+ if (!authornotes) {
55
+ return;
56
+ }
57
+ const authorNotesEl = createElement('author-notes');
58
+ authornotes
59
+ .querySelectorAll('fn:not([fn-type]), :scope > p, corresp')
60
+ .forEach((node) => {
61
+ switch (node.nodeName) {
62
+ case 'fn': {
63
+ this.appendFootnote(node, authorNotesEl, createElement);
64
+ break;
65
+ }
66
+ case 'p': {
67
+ this.appendParagraph(document, node, authorNotesEl);
68
+ break;
69
+ }
70
+ case 'corresp': {
71
+ this.appendCorresp(node, authorNotesEl, createElement);
72
+ break;
73
+ }
74
+ }
75
+ });
76
+ return authorNotesEl;
77
+ },
78
+ appendFootnote(node, element, createElement) {
79
+ const fnEl = createElement('fn-author');
80
+ fnEl.innerHTML = node.innerHTML;
81
+ fnEl.setAttribute('kind', 'footnote');
82
+ const id = node.getAttribute('id');
83
+ if (id) {
84
+ fnEl.setAttribute('id', id);
85
+ }
86
+ element.append(fnEl);
87
+ },
88
+ appendParagraph(document, node, element) {
89
+ const pEl = document.createElementNS(null, 'p');
90
+ pEl.innerHTML = node.innerHTML;
91
+ element.append(pEl);
92
+ },
93
+ appendCorresp(node, element, createElement) {
94
+ var _a, _b;
95
+ const correspEl = createElement('corresp');
96
+ const label = node.querySelector('label');
97
+ if (label) {
98
+ label.remove();
99
+ }
100
+ correspEl.textContent = ((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
101
+ correspEl.setAttribute('label', ((_b = label === null || label === void 0 ? void 0 : label.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '');
102
+ const id = node.getAttribute('id');
103
+ if (id) {
104
+ correspEl.setAttribute('id', id);
105
+ }
106
+ element.append(correspEl);
107
+ },
108
+ createContributors(front, createElement) {
109
+ const contribs = front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]');
110
+ const contributors = createElement('contributors');
111
+ contribs.forEach((element, priority) => {
112
+ const contributor = this.createContributorElement(priority, createElement);
113
+ this.setNameAttrs(element, contributor);
114
+ this.setOrcidAttribute(element, contributor);
115
+ this.setIsCorrespondingAttribute(element, contributor);
116
+ this.setContributorReferences(element, contributor, createElement);
117
+ contributors.append(contributor);
118
+ });
119
+ return contributors;
120
+ },
121
+ createContributorElement(priority, createElement) {
122
+ const contributor = createElement('contributor');
123
+ contributor.setAttribute('priority', priority.toString());
124
+ contributor.setAttribute('role', 'author');
125
+ return contributor;
126
+ },
127
+ setNameAttrs(node, element) {
128
+ const given = (0, utils_1.getTrimmedTextContent)(node, 'name > given-names');
129
+ if (given) {
130
+ element.setAttribute('given', given);
131
+ }
132
+ const surname = (0, utils_1.getTrimmedTextContent)(node, 'name > surname');
133
+ if (surname) {
134
+ element.setAttribute('family', surname);
135
+ }
136
+ },
137
+ setOrcidAttribute(node, element) {
138
+ const orcid = (0, utils_1.getTrimmedTextContent)(node, 'contrib-id[contrib-id-type="orcid"]');
139
+ if (orcid) {
140
+ element.setAttribute('ORCIDIdentifier', orcid);
141
+ }
142
+ },
143
+ setIsCorrespondingAttribute(node, element) {
144
+ const isCorresponding = node.getAttribute('corresp') === 'yes';
145
+ if (isCorresponding) {
146
+ element.setAttribute('isCorresponding', isCorresponding.toString());
147
+ }
148
+ },
149
+ setContributorReferences(node, element, createElement) {
150
+ const xrefs = node.querySelectorAll('xref');
151
+ const footnotes = createElement('fns');
152
+ const corresps = createElement('corresps');
153
+ const affs = createElement('affs');
154
+ xrefs.forEach((xref) => {
155
+ const rid = xref.getAttribute('rid');
156
+ const type = xref.getAttribute('ref-type');
157
+ if (rid) {
158
+ switch (type) {
159
+ case 'fn':
160
+ this.appendFootnoteID(xref, footnotes, rid, createElement);
161
+ break;
162
+ case 'corresp':
163
+ this.appendCorrespID(xref, corresps, rid, createElement);
164
+ break;
165
+ case 'aff':
166
+ this.appendAffiliationID(affs, rid, createElement);
167
+ break;
168
+ }
169
+ }
170
+ });
171
+ element.append(footnotes, corresps, affs);
172
+ },
173
+ appendFootnoteID(xref, footnotes, rid, createElement) {
174
+ var _a;
175
+ const fn = createElement('fn');
176
+ fn.setAttribute('noteID', rid);
177
+ fn.setAttribute('noteLabel', ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
178
+ footnotes.append(fn);
179
+ },
180
+ appendCorrespID(xref, corresps, rid, createElement) {
181
+ var _a;
182
+ const corresp = createElement('corresp');
183
+ corresp.setAttribute('correspID', rid);
184
+ corresp.setAttribute('correspLabel', ((_a = xref.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
185
+ corresps.append(corresp);
186
+ },
187
+ appendAffiliationID(affs, rid, createElement) {
188
+ const rids = rid.split(/\s+/).filter(Boolean);
189
+ if (rids.length) {
190
+ rids.forEach((affID) => {
191
+ const aff = createElement('aff');
192
+ aff.setAttribute('affiliationID', affID);
193
+ affs.append(aff);
194
+ });
195
+ }
196
+ },
197
+ createAffiliations(front, createElement) {
198
+ const affiliations = front.querySelectorAll('article-meta > contrib-group > aff');
199
+ const affiliationGroup = createElement('affiliations');
200
+ affiliations.forEach((element, priority) => {
201
+ const affiliation = this.createAffiliationElement(element, priority, createElement);
202
+ this.setInstitutionAttrs(element, affiliation);
203
+ this.setAddressAttrs(element, affiliation);
204
+ this.appendEmail(element, affiliation);
205
+ affiliationGroup.append(affiliation);
206
+ });
207
+ return affiliationGroup;
208
+ },
209
+ createAffiliationElement(element, priority, createElement) {
210
+ const affiliation = createElement('affiliation');
211
+ affiliation.setAttribute('priority', priority.toString());
212
+ const id = element.getAttribute('id');
213
+ if (id) {
214
+ affiliation.setAttribute('id', id);
215
+ }
216
+ return affiliation;
217
+ },
218
+ appendEmail(element, affiliation) {
219
+ const emailEl = element.querySelector('email');
220
+ if (emailEl) {
221
+ affiliation.appendChild(emailEl);
222
+ }
223
+ },
224
+ setInstitutionAttrs(element, affiliation) {
225
+ var _a;
226
+ for (const node of element.querySelectorAll('institution')) {
227
+ const content = (_a = node.textContent) === null || _a === void 0 ? void 0 : _a.trim();
228
+ if (!content) {
229
+ continue;
230
+ }
231
+ const type = node.getAttribute('content-type');
232
+ if (type === 'dept') {
233
+ affiliation.setAttribute('department', content);
234
+ }
235
+ else {
236
+ affiliation.setAttribute('institution', content);
237
+ }
238
+ }
239
+ },
240
+ setAddressAttrs(element, affiliation) {
241
+ const addressLine1 = (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(1)');
242
+ const addressLine2 = (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(2)');
243
+ const addressLine3 = (0, utils_1.getTrimmedTextContent)(element, 'addr-line:nth-of-type(3)');
244
+ const postCode = (0, utils_1.getTrimmedTextContent)(element, 'postal-code');
245
+ const country = (0, utils_1.getTrimmedTextContent)(element, 'country');
246
+ if (addressLine1) {
247
+ affiliation.setAttribute('addressLine1', addressLine1);
248
+ }
249
+ if (addressLine2) {
250
+ affiliation.setAttribute('addressLine2', addressLine2);
251
+ }
252
+ if (addressLine3) {
253
+ affiliation.setAttribute('addressLine3', addressLine3);
254
+ }
255
+ if (postCode) {
256
+ affiliation.setAttribute('postCode', postCode);
257
+ }
258
+ if (country) {
259
+ affiliation.setAttribute('country', country);
260
+ }
261
+ },
262
+ };
@@ -15,8 +15,10 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.parseJournalMeta = exports.parseJournalISSNs = exports.parseJournalAbbreviatedTitles = exports.parseJournalIdentifiers = void 0;
18
+ exports.parseJournal = exports.parseJournalMeta = exports.parseJournalISSNs = exports.parseJournalAbbreviatedTitles = exports.parseJournalIdentifiers = void 0;
19
+ const json_schema_1 = require("@manuscripts/json-schema");
19
20
  const utils_1 = require("../../lib/utils");
21
+ const transformer_1 = require("../../transformer");
20
22
  const parseJournalIdentifiers = (element) => {
21
23
  var _a;
22
24
  if (!element) {
@@ -91,3 +93,8 @@ const parseJournalMeta = (element) => {
91
93
  };
92
94
  };
93
95
  exports.parseJournalMeta = parseJournalMeta;
96
+ const parseJournal = (element) => {
97
+ const meta = (0, exports.parseJournalMeta)(element);
98
+ return Object.assign(Object.assign({}, meta), { _id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.Journal), objectType: json_schema_1.ObjectTypes.Journal });
99
+ };
100
+ exports.parseJournal = parseJournal;
@@ -21,21 +21,35 @@ const schema_1 = require("../../schema");
21
21
  const transformer_1 = require("../../transformer");
22
22
  const updateDocumentIDs = (node, replacements) => {
23
23
  const warnings = [];
24
- recurseDoc(node, (n) => updateNodeID(n, replacements, warnings));
24
+ const highlightNodes = [];
25
+ recurseDoc(node, (n, parent) => updateNodeID(n, parent, replacements, warnings, highlightNodes));
25
26
  recurseDoc(node, (n) => updateNodeRID(n, replacements, warnings));
26
27
  recurseDoc(node, (n) => updateNodeRIDS(n, replacements, warnings));
28
+ recurseDoc(node, (n) => updateContributorNodesIDS(n, replacements, warnings));
27
29
  return warnings;
28
30
  };
29
31
  exports.updateDocumentIDs = updateDocumentIDs;
30
- function recurseDoc(node, fn) {
31
- fn(node);
32
- node.descendants((n) => fn(n));
32
+ function recurseDoc(node, fn, parent = null) {
33
+ fn(node, parent);
34
+ node.descendants((n, pos, parent) => fn(n, parent));
33
35
  }
34
- const updateNodeID = (node, replacements, warnings) => {
36
+ const updateNodeID = (node, parent, replacements, warnings, highlightNodes) => {
35
37
  if (node.type === schema_1.schema.nodes.inline_equation) {
36
38
  node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${(0, uuid_1.v4)()}` });
37
39
  return;
38
40
  }
41
+ if (node.type === schema_1.schema.nodes.highlight_marker) {
42
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { tid: parent === null || parent === void 0 ? void 0 : parent.attrs.id });
43
+ highlightNodes.push(node);
44
+ return;
45
+ }
46
+ if (node.type === schema_1.schema.nodes.comment) {
47
+ const highlightNode = highlightNodes.find((n) => n.attrs.id === node.attrs.id);
48
+ if (highlightNode) {
49
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { target: highlightNode.attrs.tid });
50
+ }
51
+ return;
52
+ }
39
53
  if (node.type === schema_1.schema.nodes.general_table_footnote) {
40
54
  node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `GeneralTableFootnote:${(0, uuid_1.v4)()}` });
41
55
  return;
@@ -78,6 +92,26 @@ const updateNodeRIDS = (node, replacements, warnings) => {
78
92
  }
79
93
  node.attrs = Object.assign(Object.assign({}, node.attrs), { rids: previousRIDs.map((r) => replacements.get(r) || r) });
80
94
  };
95
+ const updateContributorNodesIDS = (node, replacements, warnings) => {
96
+ var _a, _b;
97
+ if (node.type === schema_1.schema.nodes.contributor) {
98
+ const footnote = (_a = node.attrs.footnote) === null || _a === void 0 ? void 0 : _a.map((fn) => {
99
+ return Object.assign(Object.assign({}, fn), { noteID: replacements.get(fn.noteID) });
100
+ });
101
+ const corresp = (_b = node.attrs.corresp) === null || _b === void 0 ? void 0 : _b.map((corresp) => {
102
+ return Object.assign(Object.assign({}, corresp), { correspID: replacements.get(corresp.correspID) });
103
+ });
104
+ const affiliations = node.attrs.affiliations.map((affiliation) => {
105
+ return replacements.get(affiliation);
106
+ });
107
+ node.attrs = Object.assign(Object.assign({}, node.attrs), { footnote,
108
+ corresp,
109
+ affiliations });
110
+ }
111
+ if (node.type !== schema_1.schema.nodes.contributors) {
112
+ return false;
113
+ }
114
+ };
81
115
  const JATS_TO_HTML_MAPPING = new Map([
82
116
  ['bold', 'b'],
83
117
  ['italic', 'i'],
@@ -16,9 +16,9 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.jatsReferenceParser = void 0;
19
+ const json_schema_1 = require("@manuscripts/json-schema");
19
20
  const utils_1 = require("../../lib/utils");
20
- const builders_1 = require("../../transformer/builders");
21
- const jats_comments_1 = require("./jats-comments");
21
+ const transformer_1 = require("../../transformer");
22
22
  const jats_parser_utils_1 = require("./jats-parser-utils");
23
23
  const jats_references_1 = require("./jats-references");
24
24
  const chooseBibliographyItemType = (publicationType) => {
@@ -40,23 +40,15 @@ exports.jatsReferenceParser = {
40
40
  const authorNodes = [
41
41
  ...element.querySelectorAll('person-group[person-group-type="author"] > *'),
42
42
  ];
43
- const bibliographyItem = (0, builders_1.buildBibliographyItem)({
43
+ const bibliographyItem = {
44
+ id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.BibliographyItem),
44
45
  type: chooseBibliographyItemType(publicationType),
45
- });
46
+ };
46
47
  const titleNode = element.querySelector('article-title');
47
48
  if (titleNode) {
48
49
  bibliographyItem.title = (_a = (0, jats_parser_utils_1.htmlFromJatsNode)(titleNode, createElement)) === null || _a === void 0 ? void 0 : _a.trim();
49
50
  }
50
- const comments = [];
51
51
  const mixedCitation = element.querySelector('mixed-citation');
52
- mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
53
- if ((0, jats_comments_1.isJATSComment)(item)) {
54
- const comment = (0, jats_comments_1.parseJATSComment)(item);
55
- if (comment) {
56
- comments.push(comment);
57
- }
58
- }
59
- });
60
52
  if (authorNodes.length <= 0) {
61
53
  mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes.forEach((item) => {
62
54
  var _a, _b, _c;
@@ -69,7 +61,7 @@ exports.jatsReferenceParser = {
69
61
  }
70
62
  const source = (0, utils_1.getTrimmedTextContent)(element, 'source');
71
63
  if (source) {
72
- bibliographyItem['container-title'] = source;
64
+ bibliographyItem.containerTitle = source;
73
65
  }
74
66
  const volume = (0, utils_1.getTrimmedTextContent)(element, 'volume');
75
67
  if (volume) {
@@ -90,18 +82,22 @@ exports.jatsReferenceParser = {
90
82
  }
91
83
  const year = (0, utils_1.getTrimmedTextContent)(element, 'year');
92
84
  if (year) {
93
- bibliographyItem.issued = (0, builders_1.buildBibliographicDate)({
85
+ bibliographyItem.issued = {
94
86
  'date-parts': [[year]],
95
- });
87
+ _id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.BibliographicDate),
88
+ objectType: json_schema_1.ObjectTypes.BibliographicDate,
89
+ };
96
90
  }
97
91
  const doi = (0, utils_1.getTrimmedTextContent)(element, 'pub-id[pub-id-type="doi"]');
98
92
  if (doi) {
99
- bibliographyItem.DOI = doi;
93
+ bibliographyItem.doi = doi;
100
94
  }
101
95
  const authors = [];
102
96
  authorNodes.forEach((authorNode) => {
103
- var _a;
104
- const name = (0, builders_1.buildBibliographicName)({});
97
+ const name = {
98
+ _id: (0, transformer_1.generateID)(json_schema_1.ObjectTypes.BibliographicName),
99
+ objectType: json_schema_1.ObjectTypes.BibliographicName,
100
+ };
105
101
  const given = (0, utils_1.getTrimmedTextContent)(authorNode, 'given-names');
106
102
  if (given) {
107
103
  name.given = given;
@@ -110,20 +106,13 @@ exports.jatsReferenceParser = {
110
106
  if (family) {
111
107
  name.family = family;
112
108
  }
113
- const suffix = (0, utils_1.getTrimmedTextContent)(authorNode, 'suffix');
114
- if (suffix) {
115
- name.suffix = suffix;
116
- }
117
- if (authorNode.nodeName === 'collab') {
118
- name.literal = (_a = authorNode.textContent) === null || _a === void 0 ? void 0 : _a.trim();
119
- }
120
109
  authors.push(name);
121
110
  });
122
111
  if (authors.length) {
123
112
  bibliographyItem.author = authors;
124
113
  }
125
114
  const id = element.getAttribute('id');
126
- references.add(bibliographyItem, id, comments);
115
+ references.add(bibliographyItem, id);
127
116
  });
128
117
  return references;
129
118
  },
@@ -1,34 +1,34 @@
1
1
  "use strict";
2
+ /*!
3
+ * © 2023 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
+ */
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.References = void 0;
4
19
  class References {
5
20
  constructor() {
6
21
  this.items = new Map();
7
22
  this.IDs = new Map();
8
- this.comments = new Map();
9
23
  }
10
- add(item, id, comments) {
11
- this.items.set(item._id, item);
12
- this.comments.set(item._id, comments);
24
+ add(item, id) {
25
+ this.items.set(item.id, item);
13
26
  if (id) {
14
- this.IDs.set(id, item._id);
27
+ this.IDs.set(id, item.id);
15
28
  }
16
29
  }
17
30
  getBibliographyItems() {
18
31
  return [...this.items.values()];
19
32
  }
20
- getComments(id) {
21
- return this.getValue(id, this.comments) || [];
22
- }
23
- getValue(id, map) {
24
- const value = map.get(id);
25
- if (value) {
26
- return value;
27
- }
28
- const id2 = this.IDs.get(id);
29
- if (id2) {
30
- return map.get(id2);
31
- }
32
- }
33
33
  }
34
34
  exports.References = References;
@@ -15,46 +15,15 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.parseJATSArticle = exports.parseJATSBody = exports.parseJATSFront = void 0;
18
+ exports.parseJATSArticle = void 0;
19
19
  const errors_1 = require("../../errors");
20
- const transformer_1 = require("../../transformer");
21
- const builders_1 = require("../../transformer/builders");
22
- const id_1 = require("../../transformer/id");
23
- const project_bundle_1 = require("../../transformer/project-bundle");
24
- const jats_body_dom_parser_1 = require("./jats-body-dom-parser");
25
20
  const jats_body_transformations_1 = require("./jats-body-transformations");
26
21
  const jats_comments_1 = require("./jats-comments");
27
- const jats_front_parser_1 = require("./jats-front-parser");
22
+ const jats_dom_parser_1 = require("./jats-dom-parser");
23
+ const jats_front_transformations_1 = require("./jats-front-transformations");
24
+ const jats_journal_meta_parser_1 = require("./jats-journal-meta-parser");
28
25
  const jats_parser_utils_1 = require("./jats-parser-utils");
29
26
  const jats_reference_parser_1 = require("./jats-reference-parser");
30
- const parseJATSFront = (doc, front) => {
31
- const createElement = createElementFn(doc);
32
- const journal = jats_front_parser_1.jatsFrontParser.parseJournal(front.querySelector('journal-meta'));
33
- const titles = jats_front_parser_1.jatsFrontParser.parseTitles(front.querySelector('article-meta > title-group'), createElement);
34
- const DOI = jats_front_parser_1.jatsFrontParser.parseDOI(front);
35
- const { affiliations, affiliationIDs } = jats_front_parser_1.jatsFrontParser.parseAffiliations([
36
- ...front.querySelectorAll('article-meta > contrib-group > aff'),
37
- ]);
38
- const { footnotes, footnoteIDs, authorNotes, authorNotesParagraphs, correspondingIDs, correspondingList, } = jats_front_parser_1.jatsFrontParser.parseAuthorNotes(front.querySelector('article-meta > author-notes'));
39
- const authors = jats_front_parser_1.jatsFrontParser.parseContributors([
40
- ...front.querySelectorAll('article-meta > contrib-group > contrib[contrib-type="author"]'),
41
- ], affiliationIDs, footnoteIDs, correspondingIDs);
42
- const history = jats_front_parser_1.jatsFrontParser.parseDates(front.querySelector('article-meta > history'));
43
- const counts = jats_front_parser_1.jatsFrontParser.parseCounts(front.querySelector('article-meta counts'));
44
- const manuscript = Object.assign(Object.assign(Object.assign(Object.assign({}, (0, builders_1.buildManuscript)()), counts), history), { DOI });
45
- return generateIDs([
46
- manuscript,
47
- titles,
48
- journal,
49
- ...authorNotesParagraphs,
50
- ...authorNotes,
51
- ...footnotes,
52
- ...authors,
53
- ...affiliations,
54
- ...correspondingList,
55
- ]);
56
- };
57
- exports.parseJATSFront = parseJATSFront;
58
27
  const parseJATSBody = (doc, body, references) => {
59
28
  const createElement = createElementFn(doc);
60
29
  jats_body_transformations_1.jatsBodyTransformations.ensureSection(body, createElement);
@@ -66,64 +35,59 @@ const parseJATSBody = (doc, body, references) => {
66
35
  jats_body_transformations_1.jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
67
36
  jats_body_transformations_1.jatsBodyTransformations.createKeywords(doc, body, createElement);
68
37
  jats_body_transformations_1.jatsBodyTransformations.orderTableFootnote(doc, body);
69
- const node = jats_body_dom_parser_1.jatsBodyDOMParser.parse(body).firstChild;
70
- if (!node) {
71
- throw new Error('No content was parsed from the JATS article body');
72
- }
73
- const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
74
- (0, jats_parser_utils_1.updateDocumentIDs)(node, replacements);
75
- return (0, transformer_1.encode)(node).values();
38
+ jats_body_transformations_1.jatsBodyTransformations.moveReferencesToBackmatter(body, references, createElement);
76
39
  };
77
- exports.parseJATSBody = parseJATSBody;
78
- const createBibliographyModels = (references) => {
79
- const models = [];
80
- const bibliographyItems = references.getBibliographyItems();
81
- const bibliographyElement = (0, transformer_1.buildBibliographyElement)(bibliographyItems);
82
- const bibliographySection = Object.assign(Object.assign({}, (0, transformer_1.buildSection)(99)), { category: 'MPSectionCategory:bibliography', elementIDs: [bibliographyElement._id], title: 'References' });
83
- const comments = (0, jats_comments_1.createReferenceComments)(references);
84
- models.push(bibliographySection);
85
- models.push(bibliographyElement);
86
- models.push(...bibliographyItems);
87
- models.push(...comments);
88
- return models;
40
+ const parseJATSFront = (doc, front, template) => {
41
+ var _a;
42
+ const createElement = createElementFn(doc);
43
+ jats_front_transformations_1.jatsFrontTransformations.setArticleAttrs(doc, template);
44
+ const authorNotes = jats_front_transformations_1.jatsFrontTransformations.createAuthorNotes(doc, createElement);
45
+ if (authorNotes) {
46
+ doc.documentElement.prepend(authorNotes);
47
+ }
48
+ const affiliations = jats_front_transformations_1.jatsFrontTransformations.createAffiliations(front, createElement);
49
+ if (affiliations) {
50
+ doc.documentElement.prepend(affiliations);
51
+ }
52
+ const contributors = jats_front_transformations_1.jatsFrontTransformations.createContributors(front, createElement);
53
+ if (contributors) {
54
+ doc.documentElement.prepend(contributors);
55
+ }
56
+ const title = jats_front_transformations_1.jatsFrontTransformations.createTitle(front, createElement);
57
+ if (title) {
58
+ doc.documentElement.prepend(title);
59
+ }
60
+ (_a = doc.querySelector('front')) === null || _a === void 0 ? void 0 : _a.remove();
89
61
  };
90
62
  const createElementFn = (doc) => (tagName) => doc.createElement(tagName);
91
- const generateIDs = (models) => models.map((m) => m._id ? m : Object.assign(Object.assign({}, m), { _id: (0, id_1.generateID)(m.objectType) }));
92
- const parseJATSArticle = (doc) => {
63
+ const parseJATSArticle = (doc, template) => {
93
64
  const article = doc.querySelector('article');
94
65
  const front = doc.querySelector('front');
95
66
  const body = doc.querySelector('body');
96
67
  const back = doc.querySelector('back');
97
- if (!front) {
98
- throw new errors_1.InvalidInput('Invalid JATS format! Missing front element');
99
- }
100
- if (!article) {
101
- throw new errors_1.InvalidInput('Invalid JATS format! Missing article element');
68
+ if (!article || !front) {
69
+ throw new errors_1.InvalidInput('invalid JATS format');
102
70
  }
103
- const marks = (0, jats_comments_1.markComments)(doc);
71
+ (0, jats_comments_1.markComments)(doc);
72
+ const journal = (0, jats_journal_meta_parser_1.parseJournal)(front.querySelector('journal-meta'));
104
73
  const createElement = createElementFn(doc);
105
- const models = [];
106
74
  let references;
107
75
  if (back) {
108
76
  references = jats_reference_parser_1.jatsReferenceParser.parseReferences([...back.querySelectorAll('ref-list > ref')], createElement);
109
77
  }
110
- models.push(...(0, exports.parseJATSFront)(doc, front));
78
+ const replacements = new Map(references === null || references === void 0 ? void 0 : references.IDs);
79
+ parseJATSFront(doc, front, template);
111
80
  if (body) {
112
- models.push(...(0, exports.parseJATSBody)(doc, body, references));
113
- }
114
- const modelMap = new Map(models.map((model) => [model._id, model]));
115
- const manuscript = (0, project_bundle_1.findManuscript)(modelMap);
116
- if (manuscript) {
117
- const type = article.getAttribute('article-type');
118
- manuscript.articleType = type || 'other';
81
+ parseJATSBody(doc, body, references);
119
82
  }
120
- if (references && references.items.size) {
121
- models.push(...createBibliographyModels(references));
122
- }
123
- if (marks.length) {
124
- const comments = (0, jats_comments_1.createComments)(models, marks);
125
- models.push(...comments);
83
+ const node = jats_dom_parser_1.jatsDOMParser.parse(doc).firstChild;
84
+ if (!node) {
85
+ throw new Error('No content was parsed from the JATS article body');
126
86
  }
127
- return models;
87
+ (0, jats_parser_utils_1.updateDocumentIDs)(node, replacements);
88
+ return {
89
+ node: node,
90
+ journal,
91
+ };
128
92
  };
129
93
  exports.parseJATSArticle = parseJATSArticle;