@manuscripts/transform 4.3.22 → 4.3.24
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.
- package/README.md +2 -2
- package/dist/cjs/jats/__tests__/jats-exporter.test.js +11 -45
- package/dist/cjs/jats/__tests__/jats-importer.test.js +54 -76
- package/dist/cjs/jats/__tests__/jats-roundtrip.test.js +1 -2
- package/dist/cjs/jats/__tests__/utils.js +4 -17
- package/dist/cjs/jats/exporter/jats-exporter.js +190 -279
- package/dist/cjs/jats/importer/jats-dom-parser.js +16 -42
- package/dist/cjs/jats/importer/jats-parser-utils.js +5 -29
- package/dist/cjs/jats/importer/jats-transformations.js +10 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +1 -6
- package/dist/cjs/schema/__tests__/docs.js +1830 -0
- package/dist/cjs/schema/__tests__/migration.test.js +3 -37
- package/dist/cjs/schema/migration/migration-scripts/4.3.12.js +39 -0
- package/dist/cjs/schema/migration/migration-scripts/index.js +2 -0
- package/dist/cjs/schema/nodes/blockquote_element.js +0 -2
- package/dist/cjs/schema/nodes/comment.js +2 -1
- package/dist/cjs/schema/nodes/contributor.js +11 -11
- package/dist/cjs/schema/nodes/equation.js +1 -3
- package/dist/cjs/schema/nodes/list.js +0 -2
- package/dist/cjs/schema/nodes/listing.js +1 -3
- package/dist/cjs/schema/nodes/paragraph.js +0 -2
- package/dist/cjs/schema/nodes/pullquote_element.js +0 -2
- package/dist/cjs/transformer/id.js +2 -14
- package/dist/cjs/transformer/node-names.js +6 -1
- package/dist/cjs/transformer/node-types.js +1 -47
- package/dist/cjs/version.js +1 -1
- package/dist/es/jats/__tests__/jats-exporter.test.js +11 -45
- package/dist/es/jats/__tests__/jats-importer.test.js +54 -76
- package/dist/es/jats/__tests__/jats-roundtrip.test.js +1 -2
- package/dist/es/jats/__tests__/utils.js +4 -17
- package/dist/es/jats/exporter/jats-exporter.js +190 -279
- package/dist/es/jats/importer/jats-dom-parser.js +16 -42
- package/dist/es/jats/importer/jats-parser-utils.js +6 -30
- package/dist/es/jats/importer/jats-transformations.js +10 -0
- package/dist/es/jats/importer/parse-jats-article.js +1 -6
- package/dist/es/schema/__tests__/docs.js +1827 -0
- package/dist/es/schema/__tests__/migration.test.js +3 -4
- package/dist/es/schema/migration/migration-scripts/4.3.12.js +37 -0
- package/dist/es/schema/migration/migration-scripts/index.js +2 -0
- package/dist/es/schema/nodes/blockquote_element.js +0 -2
- package/dist/es/schema/nodes/comment.js +2 -1
- package/dist/es/schema/nodes/contributor.js +11 -11
- package/dist/es/schema/nodes/equation.js +1 -3
- package/dist/es/schema/nodes/list.js +0 -2
- package/dist/es/schema/nodes/listing.js +1 -3
- package/dist/es/schema/nodes/paragraph.js +0 -2
- package/dist/es/schema/nodes/pullquote_element.js +0 -2
- package/dist/es/transformer/id.js +2 -14
- package/dist/es/transformer/node-names.js +4 -0
- package/dist/es/transformer/node-types.js +1 -47
- package/dist/es/version.js +1 -1
- package/dist/types/jats/__tests__/utils.d.ts +1 -11
- package/dist/types/jats/exporter/jats-exporter.d.ts +5 -10
- package/dist/types/jats/importer/jats-dom-parser.d.ts +0 -15
- package/dist/types/jats/importer/parse-jats-article.d.ts +1 -11
- package/dist/types/schema/__tests__/docs.d.ts +2 -0
- package/dist/types/schema/migration/migration-scripts/4.3.12.d.ts +8 -0
- package/dist/types/schema/migration/migration-scripts/index.d.ts +2 -1
- package/dist/types/schema/nodes/comment.d.ts +2 -2
- package/dist/types/schema/nodes/contributor.d.ts +11 -21
- package/dist/types/schema/types.d.ts +22 -0
- package/dist/types/transformer/node-names.d.ts +1 -0
- package/dist/types/transformer/node-types.d.ts +0 -2
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/dist/cjs/jats/importer/jats-journal-meta-parser.js +0 -103
- package/dist/cjs/lib/styled-content.js +0 -28
- package/dist/es/jats/importer/jats-journal-meta-parser.js +0 -95
- package/dist/es/lib/styled-content.js +0 -23
- package/dist/types/jats/importer/jats-journal-meta-parser.d.ts +0 -46
- package/dist/types/lib/styled-content.d.ts +0 -22
|
@@ -22,7 +22,7 @@ describe('JATS importer', () => {
|
|
|
22
22
|
describe('title node', () => {
|
|
23
23
|
it('should have title node with content if title element exists', async () => {
|
|
24
24
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
25
|
-
const
|
|
25
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
26
26
|
const titleNode = findNodeByType(node, schema.nodes.title);
|
|
27
27
|
expect(titleNode).toBeDefined();
|
|
28
28
|
updateNodeID(titleNode);
|
|
@@ -32,7 +32,7 @@ describe('JATS importer', () => {
|
|
|
32
32
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
33
33
|
const titleEl = jats.querySelector('article-meta > title-group > article-title');
|
|
34
34
|
titleEl?.remove();
|
|
35
|
-
const
|
|
35
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
36
36
|
const titleNode = findNodeByType(node, schema.nodes.title);
|
|
37
37
|
updateNodeID(titleNode);
|
|
38
38
|
expect(titleNode).toMatchSnapshot();
|
|
@@ -41,39 +41,17 @@ describe('JATS importer', () => {
|
|
|
41
41
|
describe('contributors node', () => {
|
|
42
42
|
it('should have contributors node with content if contributors element exists', async () => {
|
|
43
43
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
expect(node).toBeDefined();
|
|
47
|
-
expect(contributorsNode).toBeDefined();
|
|
48
|
-
expect(findNodesByType(contributorsNode, schema.nodes.contributor)).toHaveLength(2);
|
|
49
|
-
});
|
|
50
|
-
it('should correctly parse contributor nodes', async () => {
|
|
51
|
-
const jats = await readAndParseFixture('jats-import.xml');
|
|
52
|
-
const contributorsEl = jats.querySelector('article-meta > contrib-group');
|
|
53
|
-
if (!contributorsEl) {
|
|
54
|
-
throw new Error('Contributors element not found');
|
|
55
|
-
}
|
|
56
|
-
const contributors = contributorsEl.querySelectorAll('contrib[contrib-type="author"]');
|
|
57
|
-
const { node } = parseJATSArticle(jats, sectionCategories);
|
|
44
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
45
|
+
changeIDs(node);
|
|
58
46
|
const contributorNodes = findNodesByType(node, schema.nodes.contributor);
|
|
59
|
-
expect(contributorNodes).toHaveLength(
|
|
60
|
-
contributorNodes.forEach((node) => {
|
|
61
|
-
updateNodeID(node);
|
|
62
|
-
node.attrs.affiliations = node.attrs.affiliations.map(() => 'MPAffiliation:test');
|
|
63
|
-
node.attrs.footnote = node.attrs.footnote.map((footnote) => {
|
|
64
|
-
return { ...footnote, noteID: 'MPFootnote:test' };
|
|
65
|
-
});
|
|
66
|
-
node.attrs.corresp = node.attrs.corresp.map((corresp) => {
|
|
67
|
-
return { ...corresp, correspID: 'MPCorrespondance:test' };
|
|
68
|
-
});
|
|
69
|
-
});
|
|
47
|
+
expect(contributorNodes).toHaveLength(2);
|
|
70
48
|
expect(contributorNodes).toMatchSnapshot();
|
|
71
49
|
});
|
|
72
50
|
it('should not have contributors node if contributors element does not exist', async () => {
|
|
73
51
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
const
|
|
52
|
+
const $contribGroup = jats.querySelector('article-meta > contrib-group');
|
|
53
|
+
$contribGroup.remove();
|
|
54
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
77
55
|
const contributorsNode = findNodesByType(node, schema.nodes.contributors);
|
|
78
56
|
const contributorNodes = findNodesByType(node, schema.nodes.contributor);
|
|
79
57
|
expect(contributorNodes).toHaveLength(0);
|
|
@@ -83,7 +61,7 @@ describe('JATS importer', () => {
|
|
|
83
61
|
describe('affiliations', () => {
|
|
84
62
|
it('should correctly parse affiliation nodes', async () => {
|
|
85
63
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
86
|
-
const
|
|
64
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
87
65
|
const affiliationNodes = findNodesByType(node, schema.nodes.affiliation);
|
|
88
66
|
affiliationNodes.forEach(updateNodeID);
|
|
89
67
|
expect(affiliationNodes).toMatchSnapshot();
|
|
@@ -94,7 +72,7 @@ describe('JATS importer', () => {
|
|
|
94
72
|
affiliationsElements.forEach((aff) => {
|
|
95
73
|
aff.remove();
|
|
96
74
|
});
|
|
97
|
-
const
|
|
75
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
98
76
|
const affiliationsNode = findNodeByType(node, schema.nodes.affiliations);
|
|
99
77
|
const affiliationNodes = findNodesByType(node, schema.nodes.affiliation);
|
|
100
78
|
expect(affiliationNodes).toHaveLength(0);
|
|
@@ -104,7 +82,7 @@ describe('JATS importer', () => {
|
|
|
104
82
|
describe('author-notes', () => {
|
|
105
83
|
it('should have author notes node with content if author notes element exists', async () => {
|
|
106
84
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
107
|
-
const
|
|
85
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
108
86
|
const authorNotesNode = findNodeByType(node, schema.nodes.author_notes);
|
|
109
87
|
expect(authorNotesNode).toBeDefined();
|
|
110
88
|
expect(findNodesByType(authorNotesNode, schema.nodes.footnote)).toHaveLength(2);
|
|
@@ -116,7 +94,7 @@ describe('JATS importer', () => {
|
|
|
116
94
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
117
95
|
const authorNotesEl = jats.querySelector('article-meta > author-notes');
|
|
118
96
|
authorNotesEl?.remove();
|
|
119
|
-
const
|
|
97
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
120
98
|
const authorNotesNode = findNodeByType(node, schema.nodes.authorNotes);
|
|
121
99
|
expect(authorNotesNode).toBeUndefined();
|
|
122
100
|
});
|
|
@@ -124,14 +102,14 @@ describe('JATS importer', () => {
|
|
|
124
102
|
describe('awards', () => {
|
|
125
103
|
it('should have awards node if awards element exists', async () => {
|
|
126
104
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
127
|
-
const
|
|
105
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
128
106
|
const awardsNode = findNodeByType(node, schema.nodes.awards);
|
|
129
107
|
expect(awardsNode).toBeDefined();
|
|
130
108
|
expect(findNodesByType(awardsNode, schema.nodes.award).length).toBeGreaterThan(0);
|
|
131
109
|
});
|
|
132
110
|
it('should correctly parse award nodes', async () => {
|
|
133
111
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
134
|
-
const
|
|
112
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
135
113
|
const awardsNode = findNodeByType(node, schema.nodes.awards);
|
|
136
114
|
changeIDs(awardsNode);
|
|
137
115
|
expect(awardsNode).toMatchSnapshot();
|
|
@@ -140,7 +118,7 @@ describe('JATS importer', () => {
|
|
|
140
118
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
141
119
|
const awardsEl = jats.querySelector('article-meta > funding-group');
|
|
142
120
|
awardsEl?.remove();
|
|
143
|
-
const
|
|
121
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
144
122
|
const awardsNode = findNodeByType(node, schema.nodes.awards);
|
|
145
123
|
expect(awardsNode).toBeUndefined();
|
|
146
124
|
});
|
|
@@ -148,7 +126,7 @@ describe('JATS importer', () => {
|
|
|
148
126
|
describe('keywords', () => {
|
|
149
127
|
it('should have keywords node with content if keywords element exists', async () => {
|
|
150
128
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
151
|
-
const
|
|
129
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
152
130
|
const keywords = findNodeByType(node, schema.nodes.keywords);
|
|
153
131
|
expect(keywords).toBeDefined();
|
|
154
132
|
const keywordsNodes = findNodesByType(keywords, schema.nodes.keyword);
|
|
@@ -162,7 +140,7 @@ describe('JATS importer', () => {
|
|
|
162
140
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
163
141
|
const keywordGroup = jats.querySelector('kwd-group');
|
|
164
142
|
keywordGroup?.remove();
|
|
165
|
-
const
|
|
143
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
166
144
|
const keywords = findNodeByType(node, schema.nodes.keywords);
|
|
167
145
|
expect(keywords).toBeUndefined();
|
|
168
146
|
});
|
|
@@ -170,7 +148,7 @@ describe('JATS importer', () => {
|
|
|
170
148
|
describe('supplements', () => {
|
|
171
149
|
it('should have supplements node with content if supplementary-material elements exist', async () => {
|
|
172
150
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
173
|
-
const
|
|
151
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
174
152
|
const supplementsNode = findNodeByType(node, schema.nodes.supplement);
|
|
175
153
|
changeIDs(supplementsNode);
|
|
176
154
|
expect(supplementsNode).toMatchSnapshot();
|
|
@@ -181,7 +159,7 @@ describe('JATS importer', () => {
|
|
|
181
159
|
supplementryMaterial.forEach((supplement) => {
|
|
182
160
|
supplement.remove();
|
|
183
161
|
});
|
|
184
|
-
const
|
|
162
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
185
163
|
const supplementsNode = findNodeByType(node, schema.nodes.supplements);
|
|
186
164
|
expect(supplementsNode).toBeUndefined();
|
|
187
165
|
});
|
|
@@ -189,7 +167,7 @@ describe('JATS importer', () => {
|
|
|
189
167
|
describe('comments', () => {
|
|
190
168
|
it('should parse keyword comment', async () => {
|
|
191
169
|
const jats = await readAndParseFixture('jats-comments.xml');
|
|
192
|
-
const
|
|
170
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
193
171
|
const group = findNodeByType(node, schema.nodes.keyword_group);
|
|
194
172
|
const markers = findNodesByType(group, schema.nodes.highlight_marker);
|
|
195
173
|
expect(markers.length).toBe(0);
|
|
@@ -200,7 +178,7 @@ describe('JATS importer', () => {
|
|
|
200
178
|
});
|
|
201
179
|
it('should parse abstract comment', async () => {
|
|
202
180
|
const jats = await readAndParseFixture('jats-comments.xml');
|
|
203
|
-
const
|
|
181
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
204
182
|
const abstracts = findNodeByType(node, schema.nodes.abstracts);
|
|
205
183
|
const paragraph = findNodeByType(abstracts, schema.nodes.paragraph);
|
|
206
184
|
const marker = findNodeByType(paragraph, schema.nodes.highlight_marker);
|
|
@@ -213,7 +191,7 @@ describe('JATS importer', () => {
|
|
|
213
191
|
});
|
|
214
192
|
it('should parse body comment', async () => {
|
|
215
193
|
const jats = await readAndParseFixture('jats-comments.xml');
|
|
216
|
-
const
|
|
194
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
217
195
|
const body = findNodeByType(node, schema.nodes.body);
|
|
218
196
|
const paragraph = findNodeByType(body, schema.nodes.paragraph);
|
|
219
197
|
const marker = findNodeByType(paragraph, schema.nodes.highlight_marker);
|
|
@@ -226,7 +204,7 @@ describe('JATS importer', () => {
|
|
|
226
204
|
});
|
|
227
205
|
it('should parse back comment', async () => {
|
|
228
206
|
const jats = await readAndParseFixture('jats-comments.xml');
|
|
229
|
-
const
|
|
207
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
230
208
|
const back = findNodeByType(node, schema.nodes.backmatter);
|
|
231
209
|
const paragraph = findNodeByType(back, schema.nodes.paragraph);
|
|
232
210
|
const marker = findNodeByType(paragraph, schema.nodes.highlight_marker);
|
|
@@ -239,7 +217,7 @@ describe('JATS importer', () => {
|
|
|
239
217
|
});
|
|
240
218
|
it('should parse ref-list comment', async () => {
|
|
241
219
|
const jats = await readAndParseFixture('jats-comments.xml');
|
|
242
|
-
const
|
|
220
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
243
221
|
const element = findNodeByType(node, schema.nodes.bibliography_element);
|
|
244
222
|
const markers = findNodesByType(element, schema.nodes.highlight_marker);
|
|
245
223
|
expect(markers.length).toBe(0);
|
|
@@ -253,14 +231,14 @@ describe('JATS importer', () => {
|
|
|
253
231
|
describe('attachments', () => {
|
|
254
232
|
it('should have attachment node if attachment exists', async () => {
|
|
255
233
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
256
|
-
const
|
|
234
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
257
235
|
const attachmentsNode = findNodeByType(node, schema.nodes.attachments);
|
|
258
236
|
expect(attachmentsNode).toBeDefined();
|
|
259
237
|
expect(findNodesByType(attachmentsNode, schema.nodes.attachment).length).toBeGreaterThan(0);
|
|
260
238
|
});
|
|
261
239
|
it('should correctly parse self-uri element', async () => {
|
|
262
240
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
263
|
-
const
|
|
241
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
264
242
|
const attachmentNodes = findNodesByType(node, schema.nodes.attachment);
|
|
265
243
|
changeIDs(attachmentNodes[0]);
|
|
266
244
|
expect(attachmentNodes[0].attrs.type).toBe('document');
|
|
@@ -268,7 +246,7 @@ describe('JATS importer', () => {
|
|
|
268
246
|
});
|
|
269
247
|
it('should correctly parse multiple self-uri element', async () => {
|
|
270
248
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
271
|
-
const
|
|
249
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
272
250
|
const attachmentNodes = findNodesByType(node, schema.nodes.attachment);
|
|
273
251
|
expect(attachmentNodes.length).toBe(2);
|
|
274
252
|
changeIDs(attachmentNodes[0]);
|
|
@@ -279,7 +257,7 @@ describe('JATS importer', () => {
|
|
|
279
257
|
});
|
|
280
258
|
it('should not have attachments node if no attachment element does not exist', async () => {
|
|
281
259
|
const jats = await readAndParseFixture('jats-example.xml');
|
|
282
|
-
const
|
|
260
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
283
261
|
const attachmentsNode = findNodeByType(node, schema.nodes.attachments);
|
|
284
262
|
expect(attachmentsNode).toBeUndefined();
|
|
285
263
|
});
|
|
@@ -291,7 +269,7 @@ describe('JATS importer', () => {
|
|
|
291
269
|
if (!abstractsEl) {
|
|
292
270
|
throw new Error('Abstract element not found');
|
|
293
271
|
}
|
|
294
|
-
const
|
|
272
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
295
273
|
const abstractsNode = findNodeByType(node, schema.nodes.abstracts);
|
|
296
274
|
expect(abstractsNode).toBeDefined();
|
|
297
275
|
});
|
|
@@ -299,7 +277,7 @@ describe('JATS importer', () => {
|
|
|
299
277
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
300
278
|
const abstractsEl = jats.querySelector('front > article-meta > abstract');
|
|
301
279
|
abstractsEl?.remove();
|
|
302
|
-
const
|
|
280
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
303
281
|
const abstractsNode = findNodeByType(node, schema.nodes.abstracts);
|
|
304
282
|
expect(abstractsNode).toBeDefined();
|
|
305
283
|
});
|
|
@@ -309,7 +287,7 @@ describe('JATS importer', () => {
|
|
|
309
287
|
if (!abstractEl) {
|
|
310
288
|
throw new Error('Abstract element not found');
|
|
311
289
|
}
|
|
312
|
-
const
|
|
290
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
313
291
|
const abstractsNode = findNodeByType(node, schema.nodes.abstracts);
|
|
314
292
|
const sections = findNodesByType(abstractsNode, schema.nodes.section);
|
|
315
293
|
expect(sections).toHaveLength(6);
|
|
@@ -320,7 +298,7 @@ describe('JATS importer', () => {
|
|
|
320
298
|
if (!abstractEl) {
|
|
321
299
|
throw new Error('Abstract element not found');
|
|
322
300
|
}
|
|
323
|
-
const
|
|
301
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
324
302
|
const abstractsNode = findNodeByType(node, schema.nodes.abstracts);
|
|
325
303
|
const sections = findNodesByType(abstractsNode, schema.nodes.section);
|
|
326
304
|
const firstSection = sections[0];
|
|
@@ -335,13 +313,13 @@ describe('JATS importer', () => {
|
|
|
335
313
|
if (!bodyEl) {
|
|
336
314
|
throw new Error('Body element not found');
|
|
337
315
|
}
|
|
338
|
-
const
|
|
316
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
339
317
|
const bodyNode = findNodeByType(node, schema.nodes.body);
|
|
340
318
|
expect(bodyNode).toBeDefined();
|
|
341
319
|
});
|
|
342
320
|
it('should have the correct number of sections', async () => {
|
|
343
321
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
344
|
-
const
|
|
322
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
345
323
|
const bodyNode = findNodeByType(node, schema.nodes.body);
|
|
346
324
|
const sections = findNodesByType(bodyNode, schema.nodes.section, false);
|
|
347
325
|
expect(sections).toHaveLength(5);
|
|
@@ -350,19 +328,19 @@ describe('JATS importer', () => {
|
|
|
350
328
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
351
329
|
const bodyEl = jats.querySelector('body');
|
|
352
330
|
bodyEl?.remove();
|
|
353
|
-
const
|
|
331
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
354
332
|
const bodyNode = findNodeByType(node, schema.nodes.body);
|
|
355
333
|
expect(bodyNode).toBeDefined();
|
|
356
334
|
});
|
|
357
335
|
it('should create body element and append to article when body is missing', async () => {
|
|
358
336
|
const jats = await readAndParseFixture('jats-abstract-no-body.xml');
|
|
359
|
-
const
|
|
337
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
360
338
|
const bodyNode = findNodeByType(node, schema.nodes.body);
|
|
361
339
|
expect(bodyNode).toBeDefined();
|
|
362
340
|
});
|
|
363
341
|
it('should have abstracts node even when no body element exists in JATS', async () => {
|
|
364
342
|
const jats = await readAndParseFixture('jats-abstract-no-body.xml');
|
|
365
|
-
const
|
|
343
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
366
344
|
const abstractNode = findNodeByType(node, schema.nodes.abstracts);
|
|
367
345
|
expect(abstractNode).toBeDefined();
|
|
368
346
|
});
|
|
@@ -374,7 +352,7 @@ describe('JATS importer', () => {
|
|
|
374
352
|
if (!backEl) {
|
|
375
353
|
throw new Error('Back element not found');
|
|
376
354
|
}
|
|
377
|
-
const
|
|
355
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
378
356
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
379
357
|
expect(backNode).toBeDefined();
|
|
380
358
|
});
|
|
@@ -384,7 +362,7 @@ describe('JATS importer', () => {
|
|
|
384
362
|
if (!appGroup) {
|
|
385
363
|
throw new Error('App group element not found');
|
|
386
364
|
}
|
|
387
|
-
const
|
|
365
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
388
366
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
389
367
|
const appNode = findNodesByType(backNode, schema.nodes.section, false).filter((node) => node.attrs.category === 'appendices');
|
|
390
368
|
expect(appNode).toHaveLength(1);
|
|
@@ -395,14 +373,14 @@ describe('JATS importer', () => {
|
|
|
395
373
|
if (!backEl) {
|
|
396
374
|
throw new Error('Back element not found');
|
|
397
375
|
}
|
|
398
|
-
const
|
|
376
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
399
377
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
400
378
|
const availabilitySection = findNodesByType(backNode, schema.nodes.section, false).filter((node) => node.attrs.category === 'availability');
|
|
401
379
|
expect(availabilitySection).toHaveLength(1);
|
|
402
380
|
});
|
|
403
381
|
it('should create sections for special footnotes', async () => {
|
|
404
382
|
const jats = await readAndParseFixture('jats-example-full.xml');
|
|
405
|
-
const
|
|
383
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
406
384
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
407
385
|
const con = findNodesByType(backNode, schema.nodes.section, false).filter((node) => node.attrs.category === 'con');
|
|
408
386
|
const financialDisclosure = findNodesByType(backNode, schema.nodes.section, false).filter((node) => node.attrs.category === 'financial-disclosure');
|
|
@@ -413,7 +391,7 @@ describe('JATS importer', () => {
|
|
|
413
391
|
});
|
|
414
392
|
it('should have an endnotes section if either an endnotes section exists or there are footnotes', async () => {
|
|
415
393
|
const jats = await readAndParseFixture('jats-example-full.xml');
|
|
416
|
-
const
|
|
394
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
417
395
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
418
396
|
const endNotesSection = findNodesByType(backNode, schema.nodes.footnotes_section, false);
|
|
419
397
|
expect(endNotesSection).toHaveLength(1);
|
|
@@ -424,7 +402,7 @@ describe('JATS importer', () => {
|
|
|
424
402
|
if (!refList) {
|
|
425
403
|
throw new Error('Ref list element not found');
|
|
426
404
|
}
|
|
427
|
-
const
|
|
405
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
428
406
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
429
407
|
const refSection = findNodesByType(backNode, schema.nodes.bibliography_section, false);
|
|
430
408
|
expect(refSection).toHaveLength(1);
|
|
@@ -435,7 +413,7 @@ describe('JATS importer', () => {
|
|
|
435
413
|
if (!ack) {
|
|
436
414
|
throw new Error('Ack element not found');
|
|
437
415
|
}
|
|
438
|
-
const
|
|
416
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
439
417
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
440
418
|
const ackSection = findNodesByType(backNode, schema.nodes.section, false).filter((node) => node.attrs.category === 'acknowledgements');
|
|
441
419
|
expect(ackSection).toHaveLength(1);
|
|
@@ -446,7 +424,7 @@ describe('JATS importer', () => {
|
|
|
446
424
|
if (!refList) {
|
|
447
425
|
throw new Error('Ref list element not found');
|
|
448
426
|
}
|
|
449
|
-
const
|
|
427
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
450
428
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
451
429
|
const refSection = findNodeByType(backNode, schema.nodes.bibliography_section);
|
|
452
430
|
const bibliographyItems = findNodesByType(refSection, schema.nodes.bibliography_item);
|
|
@@ -460,7 +438,7 @@ describe('JATS importer', () => {
|
|
|
460
438
|
});
|
|
461
439
|
it('should have the correct number of sections', async () => {
|
|
462
440
|
const jats = await readAndParseFixture('jats-example-full.xml');
|
|
463
|
-
const
|
|
441
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
464
442
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
465
443
|
expect(backNode.childCount).toBe(8);
|
|
466
444
|
});
|
|
@@ -468,43 +446,43 @@ describe('JATS importer', () => {
|
|
|
468
446
|
const jats = await readAndParseFixture('jats-import.xml');
|
|
469
447
|
const backEl = jats.querySelector('back');
|
|
470
448
|
backEl?.remove();
|
|
471
|
-
const
|
|
449
|
+
const node = parseJATSArticle(jats, sectionCategories);
|
|
472
450
|
const backNode = findNodeByType(node, schema.nodes.backmatter);
|
|
473
451
|
expect(backNode).toBeDefined();
|
|
474
452
|
});
|
|
475
453
|
});
|
|
476
454
|
test('parses JATS to Manuscripts document', async () => {
|
|
477
|
-
const
|
|
455
|
+
const node = await createNodeFromJATS('jats-import.xml');
|
|
478
456
|
changeIDs(node);
|
|
479
457
|
expect(node).toMatchSnapshot();
|
|
480
458
|
});
|
|
481
459
|
test('parses JATS AuthorQueries example to Manuscripts document', async () => {
|
|
482
|
-
const
|
|
460
|
+
const node = await createNodeFromJATS('jats-document.xml');
|
|
483
461
|
changeIDs(node);
|
|
484
462
|
expect(node).toMatchSnapshot();
|
|
485
463
|
});
|
|
486
464
|
test('parses full JATS example to Manuscripts document', async () => {
|
|
487
|
-
const
|
|
465
|
+
const node = await createNodeFromJATS('jats-example-doc.xml');
|
|
488
466
|
changeIDs(node);
|
|
489
467
|
expect(node).toMatchSnapshot();
|
|
490
468
|
});
|
|
491
469
|
test("parses JATS article without references and doesn't create empty references section", async () => {
|
|
492
|
-
const
|
|
470
|
+
const node = await createNodeFromJATS('jats-import-no-refs.xml');
|
|
493
471
|
changeIDs(node);
|
|
494
472
|
expect(node).toMatchSnapshot();
|
|
495
473
|
});
|
|
496
474
|
test('parses JATS article to Manuscripts document', async () => {
|
|
497
|
-
const
|
|
475
|
+
const node = await createNodeFromJATS('jats-example.xml');
|
|
498
476
|
changeIDs(node);
|
|
499
477
|
expect(node).toMatchSnapshot();
|
|
500
478
|
});
|
|
501
479
|
test('parses JATS article with tables and table footnotes', async () => {
|
|
502
|
-
const
|
|
480
|
+
const node = await createNodeFromJATS('jats-tables-example.xml');
|
|
503
481
|
changeIDs(node);
|
|
504
482
|
expect(node).toMatchSnapshot();
|
|
505
483
|
});
|
|
506
484
|
test('parses JATS example full', async () => {
|
|
507
|
-
const
|
|
485
|
+
const node = await createNodeFromJATS('jats-example-full.xml');
|
|
508
486
|
changeIDs(node);
|
|
509
487
|
expect(node).toMatchSnapshot();
|
|
510
488
|
});
|
|
@@ -27,10 +27,9 @@ const parseXMLWithDTD = (data) => parseXml(data, {
|
|
|
27
27
|
const roundtrip = async (filename) => {
|
|
28
28
|
const input = await readFixture(filename);
|
|
29
29
|
const doc = new DOMParser().parseFromString(input, 'application/xml');
|
|
30
|
-
const
|
|
30
|
+
const node = parseJATSArticle(doc, sectionCategories);
|
|
31
31
|
const exporter = new JATSExporter();
|
|
32
32
|
return await exporter.serializeToJATS(node, {
|
|
33
|
-
journal: journal,
|
|
34
33
|
csl: DEFAULT_CSL_OPTIONS,
|
|
35
34
|
});
|
|
36
35
|
};
|
|
@@ -26,28 +26,15 @@ const uuidRegex = /[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[
|
|
|
26
26
|
const replaceUUIDWithTest = (input) => input.replace(uuidRegex, 'test');
|
|
27
27
|
const updateContributorNodeIDs = (node) => {
|
|
28
28
|
if (isContributorNode(node)) {
|
|
29
|
-
node.attrs.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
node.attrs.corresp = node.attrs.corresp.map((corresp) => {
|
|
33
|
-
return { ...corresp, correspID: replaceUUIDWithTest(corresp.correspID) };
|
|
34
|
-
});
|
|
35
|
-
node.attrs.affiliations = node.attrs.affiliations.map((aff) => replaceUUIDWithTest(aff));
|
|
36
|
-
if (node.attrs.bibliographicName._id) {
|
|
37
|
-
node.attrs.bibliographicName._id = replaceUUIDWithTest(node.attrs.bibliographicName._id);
|
|
38
|
-
}
|
|
29
|
+
node.attrs.footnoteIDs = node.attrs.footnoteIDs?.map((id) => replaceUUIDWithTest(id));
|
|
30
|
+
node.attrs.correspIDs = node.attrs.correspIDs?.map((id) => replaceUUIDWithTest(id));
|
|
31
|
+
node.attrs.affiliationIDs = node.attrs.affiliationIDs?.map((id) => replaceUUIDWithTest(id));
|
|
39
32
|
}
|
|
40
33
|
};
|
|
41
34
|
const updateCommentNodeIDs = (node) => {
|
|
42
35
|
if (isCommentNode(node)) {
|
|
43
36
|
node.attrs.target = replaceUUIDWithTest(node.attrs.target);
|
|
44
|
-
node.attrs.
|
|
45
|
-
return {
|
|
46
|
-
...contribution,
|
|
47
|
-
_id: replaceUUIDWithTest(contribution._id),
|
|
48
|
-
timestamp: 1234,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
37
|
+
node.attrs.timestamp = 1234;
|
|
51
38
|
}
|
|
52
39
|
};
|
|
53
40
|
const updateNodeRID = (node) => {
|