@manuscripts/transform 3.0.5-LEAN-3958.0 → 3.0.5
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/dist/cjs/jats/exporter/jats-exporter.js +29 -0
- package/dist/cjs/jats/importer/jats-dom-parser.js +43 -5
- package/dist/cjs/lib/utils.js +14 -1
- package/dist/cjs/schema/nodes/inline_footnote.js +1 -0
- package/dist/cjs/schema/nodes/manuscript.js +6 -0
- package/dist/cjs/transformer/node-names.js +3 -18
- package/dist/cjs/version.js +1 -1
- package/dist/es/jats/exporter/jats-exporter.js +29 -0
- package/dist/es/jats/importer/jats-dom-parser.js +44 -6
- package/dist/es/lib/utils.js +12 -0
- package/dist/es/schema/nodes/inline_footnote.js +1 -0
- package/dist/es/schema/nodes/manuscript.js +6 -0
- package/dist/es/transformer/node-names.js +3 -18
- package/dist/es/version.js +1 -1
- package/dist/types/lib/table-cell-styles.d.ts +1 -1
- package/dist/types/lib/utils.d.ts +1 -0
- package/dist/types/schema/nodes/manuscript.d.ts +6 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/dist/cjs/jats/importer/jats-body-transformations.js +0 -326
- package/dist/es/jats/importer/jats-body-transformations.js +0 -323
- package/dist/types/jats/importer/jats-body-transformations.d.ts +0 -40
|
@@ -291,6 +291,35 @@ class JATSExporter {
|
|
|
291
291
|
supplementaryMaterial.append(caption);
|
|
292
292
|
articleMeta.append(supplementaryMaterial);
|
|
293
293
|
});
|
|
294
|
+
const history = articleMeta.querySelector('history') ||
|
|
295
|
+
this.document.createElement('history');
|
|
296
|
+
if (this.manuscriptNode.attrs.acceptanceDate) {
|
|
297
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.acceptanceDate, 'accepted');
|
|
298
|
+
history.appendChild(date);
|
|
299
|
+
}
|
|
300
|
+
if (this.manuscriptNode.attrs.correctionDate) {
|
|
301
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.correctionDate, 'corrected');
|
|
302
|
+
history.appendChild(date);
|
|
303
|
+
}
|
|
304
|
+
if (this.manuscriptNode.attrs.retractionDate) {
|
|
305
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.retractionDate, 'retracted');
|
|
306
|
+
history.appendChild(date);
|
|
307
|
+
}
|
|
308
|
+
if (this.manuscriptNode.attrs.receiveDate) {
|
|
309
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.receiveDate, 'received');
|
|
310
|
+
history.appendChild(date);
|
|
311
|
+
}
|
|
312
|
+
if (this.manuscriptNode.attrs.revisionReceiveDate) {
|
|
313
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.revisionReceiveDate, 'rev-recd');
|
|
314
|
+
history.appendChild(date);
|
|
315
|
+
}
|
|
316
|
+
if (this.manuscriptNode.attrs.revisionRequestDate) {
|
|
317
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.revisionRequestDate, 'rev-request');
|
|
318
|
+
history.appendChild(date);
|
|
319
|
+
}
|
|
320
|
+
if (history.childElementCount) {
|
|
321
|
+
articleMeta.appendChild(history);
|
|
322
|
+
}
|
|
294
323
|
this.buildKeywords(articleMeta);
|
|
295
324
|
let countingElements = [];
|
|
296
325
|
const figureCount = (0, prosemirror_utils_1.findChildrenByType)(this.manuscriptNode, schema_1.schema.nodes.figure).length;
|
|
@@ -69,6 +69,42 @@ const getEquationContent = (p) => {
|
|
|
69
69
|
}
|
|
70
70
|
return { id, format, contents };
|
|
71
71
|
};
|
|
72
|
+
const parseDates = (historyNode) => {
|
|
73
|
+
if (!historyNode) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const history = {};
|
|
77
|
+
for (const date of historyNode.children) {
|
|
78
|
+
const dateType = date.getAttribute('date-type');
|
|
79
|
+
switch (dateType) {
|
|
80
|
+
case 'received': {
|
|
81
|
+
history.receiveDate = (0, utils_1.dateToTimestamp)(date);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'rev-recd': {
|
|
85
|
+
history.revisionReceiveDate = (0, utils_1.dateToTimestamp)(date);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'accepted': {
|
|
89
|
+
history.acceptanceDate = (0, utils_1.dateToTimestamp)(date);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case 'rev-request': {
|
|
93
|
+
history.revisionRequestDate = (0, utils_1.dateToTimestamp)(date);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'retracted': {
|
|
97
|
+
history.retractionDate = (0, utils_1.dateToTimestamp)(date);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case 'corrected': {
|
|
101
|
+
history.correctionDate = (0, utils_1.dateToTimestamp)(date);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return history;
|
|
107
|
+
};
|
|
72
108
|
const getEmail = (element) => {
|
|
73
109
|
var _a, _b, _c;
|
|
74
110
|
const email = element.querySelector('email');
|
|
@@ -241,11 +277,9 @@ const nodes = [
|
|
|
241
277
|
var _a, _b;
|
|
242
278
|
const element = node;
|
|
243
279
|
const doi = element.querySelector('front > article-meta > article-id[pub-id-type="doi"]');
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
primaryLanguageCode: (_b = element.getAttribute('lang')) !== null && _b !== void 0 ? _b : '',
|
|
248
|
-
};
|
|
280
|
+
const history = element.querySelector('history');
|
|
281
|
+
const dates = parseDates(history);
|
|
282
|
+
return Object.assign({ doi: doi === null || doi === void 0 ? void 0 : doi.textContent, articleType: (_a = element.getAttribute('article-type')) !== null && _a !== void 0 ? _a : '', primaryLanguageCode: (_b = element.getAttribute('lang')) !== null && _b !== void 0 ? _b : '' }, dates);
|
|
249
283
|
},
|
|
250
284
|
},
|
|
251
285
|
{
|
|
@@ -438,6 +472,10 @@ const nodes = [
|
|
|
438
472
|
tag: 'back',
|
|
439
473
|
ignore: true,
|
|
440
474
|
},
|
|
475
|
+
{
|
|
476
|
+
tag: 'history',
|
|
477
|
+
ignore: true,
|
|
478
|
+
},
|
|
441
479
|
{
|
|
442
480
|
tag: 'break',
|
|
443
481
|
node: 'hard_break',
|
package/dist/cjs/lib/utils.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.timestamp = exports.getTrimmedTextContent = exports.findParentNodeClosestToPos = exports.isInBibliographySection = exports.isInGraphicalAbstractSection = exports.findNodePositions = exports.iterateChildren = void 0;
|
|
18
|
+
exports.dateToTimestamp = exports.timestamp = 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) {
|
|
@@ -85,3 +85,16 @@ const getTrimmedTextContent = (node, querySelector) => {
|
|
|
85
85
|
exports.getTrimmedTextContent = getTrimmedTextContent;
|
|
86
86
|
const timestamp = () => Math.floor(Date.now() / 1000);
|
|
87
87
|
exports.timestamp = timestamp;
|
|
88
|
+
const dateToTimestamp = (dateElement) => {
|
|
89
|
+
const selectors = ['year', 'month', 'day'];
|
|
90
|
+
const values = [];
|
|
91
|
+
for (const selector of selectors) {
|
|
92
|
+
const value = (0, exports.getTrimmedTextContent)(dateElement, selector);
|
|
93
|
+
if (!value || isNaN(+value)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
values.push(+value);
|
|
97
|
+
}
|
|
98
|
+
return Date.UTC(values[0], values[1], values[2]) / 1000;
|
|
99
|
+
};
|
|
100
|
+
exports.dateToTimestamp = dateToTimestamp;
|
|
@@ -24,6 +24,12 @@ exports.manuscript = {
|
|
|
24
24
|
prototype: { default: '' },
|
|
25
25
|
primaryLanguageCode: { default: '' },
|
|
26
26
|
articleType: { default: '' },
|
|
27
|
+
acceptanceDate: { default: undefined },
|
|
28
|
+
correctionDate: { default: undefined },
|
|
29
|
+
retractionDate: { default: undefined },
|
|
30
|
+
revisionRequestDate: { default: undefined },
|
|
31
|
+
revisionReceiveDate: { default: undefined },
|
|
32
|
+
receiveDate: { default: undefined },
|
|
27
33
|
},
|
|
28
34
|
group: 'block',
|
|
29
35
|
parseDOM: [
|
|
@@ -18,41 +18,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.nodeNames = void 0;
|
|
19
19
|
const schema_1 = require("../schema");
|
|
20
20
|
exports.nodeNames = new Map([
|
|
21
|
-
[schema_1.schema.nodes.title, 'Title'],
|
|
22
|
-
[schema_1.schema.nodes.contributor, 'Author'],
|
|
23
|
-
[schema_1.schema.nodes.keywords, 'Keywords'],
|
|
24
|
-
[schema_1.schema.nodes.keyword, 'Keyword'],
|
|
25
21
|
[schema_1.schema.nodes.bibliography_element, 'Bibliography'],
|
|
26
|
-
[schema_1.schema.nodes.bibliography_item, 'Reference'],
|
|
27
22
|
[schema_1.schema.nodes.bibliography_section, 'Section'],
|
|
28
23
|
[schema_1.schema.nodes.citation, 'Citation'],
|
|
29
24
|
[schema_1.schema.nodes.listing_element, 'Listing'],
|
|
30
25
|
[schema_1.schema.nodes.cross_reference, 'Cross Reference'],
|
|
31
26
|
[schema_1.schema.nodes.equation_element, 'Equation'],
|
|
32
27
|
[schema_1.schema.nodes.figure_element, 'Figure'],
|
|
33
|
-
[schema_1.schema.nodes.table_element, 'Table'],
|
|
34
|
-
[schema_1.schema.nodes.table_cell, 'Table Cell'],
|
|
35
|
-
[schema_1.schema.nodes.table_col, 'Table Column'],
|
|
36
|
-
[schema_1.schema.nodes.table_row, 'Table Row'],
|
|
37
|
-
[schema_1.schema.nodes.table_header, 'Table Header'],
|
|
38
|
-
[schema_1.schema.nodes.general_table_footnote, 'General Table note'],
|
|
39
|
-
[schema_1.schema.nodes.table_element_footer, 'Table Footer'],
|
|
40
|
-
[schema_1.schema.nodes.equation, 'Equation'],
|
|
41
|
-
[schema_1.schema.nodes.inline_equation, 'Inline Equation'],
|
|
42
|
-
[schema_1.schema.nodes.inline_footnote, 'Footnote Reference'],
|
|
43
28
|
[schema_1.schema.nodes.footnote, 'Footnote'],
|
|
44
29
|
[schema_1.schema.nodes.footnotes_element, 'Notes'],
|
|
45
30
|
[schema_1.schema.nodes.list, 'List'],
|
|
46
|
-
[schema_1.schema.nodes.list_item, 'List Item'],
|
|
47
31
|
[schema_1.schema.nodes.manuscript, 'Manuscript'],
|
|
48
32
|
[schema_1.schema.nodes.paragraph, 'Paragraph'],
|
|
49
33
|
[schema_1.schema.nodes.section, 'Section'],
|
|
50
|
-
[schema_1.schema.nodes.section_title, 'Section
|
|
51
|
-
[schema_1.schema.nodes.section_title_plain, 'Section
|
|
34
|
+
[schema_1.schema.nodes.section_title, 'Section'],
|
|
35
|
+
[schema_1.schema.nodes.section_title_plain, 'Section'],
|
|
52
36
|
[schema_1.schema.nodes.table, 'Table'],
|
|
53
37
|
[schema_1.schema.nodes.table_element, 'Table'],
|
|
54
38
|
[schema_1.schema.nodes.blockquote_element, 'Block Quote'],
|
|
55
39
|
[schema_1.schema.nodes.pullquote_element, 'Pull Quote'],
|
|
40
|
+
[schema_1.schema.nodes.keywords, 'Section'],
|
|
56
41
|
[schema_1.schema.nodes.toc_section, 'Section'],
|
|
57
42
|
[schema_1.schema.nodes.box_element, 'Box'],
|
|
58
43
|
]);
|
package/dist/cjs/version.js
CHANGED
|
@@ -283,6 +283,35 @@ export class JATSExporter {
|
|
|
283
283
|
supplementaryMaterial.append(caption);
|
|
284
284
|
articleMeta.append(supplementaryMaterial);
|
|
285
285
|
});
|
|
286
|
+
const history = articleMeta.querySelector('history') ||
|
|
287
|
+
this.document.createElement('history');
|
|
288
|
+
if (this.manuscriptNode.attrs.acceptanceDate) {
|
|
289
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.acceptanceDate, 'accepted');
|
|
290
|
+
history.appendChild(date);
|
|
291
|
+
}
|
|
292
|
+
if (this.manuscriptNode.attrs.correctionDate) {
|
|
293
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.correctionDate, 'corrected');
|
|
294
|
+
history.appendChild(date);
|
|
295
|
+
}
|
|
296
|
+
if (this.manuscriptNode.attrs.retractionDate) {
|
|
297
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.retractionDate, 'retracted');
|
|
298
|
+
history.appendChild(date);
|
|
299
|
+
}
|
|
300
|
+
if (this.manuscriptNode.attrs.receiveDate) {
|
|
301
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.receiveDate, 'received');
|
|
302
|
+
history.appendChild(date);
|
|
303
|
+
}
|
|
304
|
+
if (this.manuscriptNode.attrs.revisionReceiveDate) {
|
|
305
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.revisionReceiveDate, 'rev-recd');
|
|
306
|
+
history.appendChild(date);
|
|
307
|
+
}
|
|
308
|
+
if (this.manuscriptNode.attrs.revisionRequestDate) {
|
|
309
|
+
const date = this.buildDateElement(this.manuscriptNode.attrs.revisionRequestDate, 'rev-request');
|
|
310
|
+
history.appendChild(date);
|
|
311
|
+
}
|
|
312
|
+
if (history.childElementCount) {
|
|
313
|
+
articleMeta.appendChild(history);
|
|
314
|
+
}
|
|
286
315
|
this.buildKeywords(articleMeta);
|
|
287
316
|
let countingElements = [];
|
|
288
317
|
const figureCount = findChildrenByType(this.manuscriptNode, schema.nodes.figure).length;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { buildBibliographicDate, buildBibliographicName, buildContribution, ObjectTypes, } from '@manuscripts/json-schema';
|
|
17
17
|
import mime from 'mime';
|
|
18
18
|
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
19
|
-
import { getTrimmedTextContent } from '../../lib/utils';
|
|
19
|
+
import { dateToTimestamp, getTrimmedTextContent } from '../../lib/utils';
|
|
20
20
|
import { schema, } from '../../schema';
|
|
21
21
|
import { chooseSectionCategory } from '../../transformer';
|
|
22
22
|
import { DEFAULT_PROFILE_ID } from './jats-comments';
|
|
@@ -63,6 +63,42 @@ const getEquationContent = (p) => {
|
|
|
63
63
|
}
|
|
64
64
|
return { id, format, contents };
|
|
65
65
|
};
|
|
66
|
+
const parseDates = (historyNode) => {
|
|
67
|
+
if (!historyNode) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const history = {};
|
|
71
|
+
for (const date of historyNode.children) {
|
|
72
|
+
const dateType = date.getAttribute('date-type');
|
|
73
|
+
switch (dateType) {
|
|
74
|
+
case 'received': {
|
|
75
|
+
history.receiveDate = dateToTimestamp(date);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case 'rev-recd': {
|
|
79
|
+
history.revisionReceiveDate = dateToTimestamp(date);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 'accepted': {
|
|
83
|
+
history.acceptanceDate = dateToTimestamp(date);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'rev-request': {
|
|
87
|
+
history.revisionRequestDate = dateToTimestamp(date);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case 'retracted': {
|
|
91
|
+
history.retractionDate = dateToTimestamp(date);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'corrected': {
|
|
95
|
+
history.correctionDate = dateToTimestamp(date);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return history;
|
|
101
|
+
};
|
|
66
102
|
const getEmail = (element) => {
|
|
67
103
|
var _a, _b, _c;
|
|
68
104
|
const email = element.querySelector('email');
|
|
@@ -235,11 +271,9 @@ const nodes = [
|
|
|
235
271
|
var _a, _b;
|
|
236
272
|
const element = node;
|
|
237
273
|
const doi = element.querySelector('front > article-meta > article-id[pub-id-type="doi"]');
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
primaryLanguageCode: (_b = element.getAttribute('lang')) !== null && _b !== void 0 ? _b : '',
|
|
242
|
-
};
|
|
274
|
+
const history = element.querySelector('history');
|
|
275
|
+
const dates = parseDates(history);
|
|
276
|
+
return Object.assign({ doi: doi === null || doi === void 0 ? void 0 : doi.textContent, articleType: (_a = element.getAttribute('article-type')) !== null && _a !== void 0 ? _a : '', primaryLanguageCode: (_b = element.getAttribute('lang')) !== null && _b !== void 0 ? _b : '' }, dates);
|
|
243
277
|
},
|
|
244
278
|
},
|
|
245
279
|
{
|
|
@@ -432,6 +466,10 @@ const nodes = [
|
|
|
432
466
|
tag: 'back',
|
|
433
467
|
ignore: true,
|
|
434
468
|
},
|
|
469
|
+
{
|
|
470
|
+
tag: 'history',
|
|
471
|
+
ignore: true,
|
|
472
|
+
},
|
|
435
473
|
{
|
|
436
474
|
tag: 'break',
|
|
437
475
|
node: 'hard_break',
|
package/dist/es/lib/utils.js
CHANGED
|
@@ -75,3 +75,15 @@ export const getTrimmedTextContent = (node, querySelector) => {
|
|
|
75
75
|
return (_b = (_a = node.querySelector(querySelector)) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim();
|
|
76
76
|
};
|
|
77
77
|
export const timestamp = () => Math.floor(Date.now() / 1000);
|
|
78
|
+
export const dateToTimestamp = (dateElement) => {
|
|
79
|
+
const selectors = ['year', 'month', 'day'];
|
|
80
|
+
const values = [];
|
|
81
|
+
for (const selector of selectors) {
|
|
82
|
+
const value = getTrimmedTextContent(dateElement, selector);
|
|
83
|
+
if (!value || isNaN(+value)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
values.push(+value);
|
|
87
|
+
}
|
|
88
|
+
return Date.UTC(values[0], values[1], values[2]) / 1000;
|
|
89
|
+
};
|
|
@@ -21,6 +21,12 @@ export const manuscript = {
|
|
|
21
21
|
prototype: { default: '' },
|
|
22
22
|
primaryLanguageCode: { default: '' },
|
|
23
23
|
articleType: { default: '' },
|
|
24
|
+
acceptanceDate: { default: undefined },
|
|
25
|
+
correctionDate: { default: undefined },
|
|
26
|
+
retractionDate: { default: undefined },
|
|
27
|
+
revisionRequestDate: { default: undefined },
|
|
28
|
+
revisionReceiveDate: { default: undefined },
|
|
29
|
+
receiveDate: { default: undefined },
|
|
24
30
|
},
|
|
25
31
|
group: 'block',
|
|
26
32
|
parseDOM: [
|
|
@@ -15,41 +15,26 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { schema } from '../schema';
|
|
17
17
|
export const nodeNames = new Map([
|
|
18
|
-
[schema.nodes.title, 'Title'],
|
|
19
|
-
[schema.nodes.contributor, 'Author'],
|
|
20
|
-
[schema.nodes.keywords, 'Keywords'],
|
|
21
|
-
[schema.nodes.keyword, 'Keyword'],
|
|
22
18
|
[schema.nodes.bibliography_element, 'Bibliography'],
|
|
23
|
-
[schema.nodes.bibliography_item, 'Reference'],
|
|
24
19
|
[schema.nodes.bibliography_section, 'Section'],
|
|
25
20
|
[schema.nodes.citation, 'Citation'],
|
|
26
21
|
[schema.nodes.listing_element, 'Listing'],
|
|
27
22
|
[schema.nodes.cross_reference, 'Cross Reference'],
|
|
28
23
|
[schema.nodes.equation_element, 'Equation'],
|
|
29
24
|
[schema.nodes.figure_element, 'Figure'],
|
|
30
|
-
[schema.nodes.table_element, 'Table'],
|
|
31
|
-
[schema.nodes.table_cell, 'Table Cell'],
|
|
32
|
-
[schema.nodes.table_col, 'Table Column'],
|
|
33
|
-
[schema.nodes.table_row, 'Table Row'],
|
|
34
|
-
[schema.nodes.table_header, 'Table Header'],
|
|
35
|
-
[schema.nodes.general_table_footnote, 'General Table note'],
|
|
36
|
-
[schema.nodes.table_element_footer, 'Table Footer'],
|
|
37
|
-
[schema.nodes.equation, 'Equation'],
|
|
38
|
-
[schema.nodes.inline_equation, 'Inline Equation'],
|
|
39
|
-
[schema.nodes.inline_footnote, 'Footnote Reference'],
|
|
40
25
|
[schema.nodes.footnote, 'Footnote'],
|
|
41
26
|
[schema.nodes.footnotes_element, 'Notes'],
|
|
42
27
|
[schema.nodes.list, 'List'],
|
|
43
|
-
[schema.nodes.list_item, 'List Item'],
|
|
44
28
|
[schema.nodes.manuscript, 'Manuscript'],
|
|
45
29
|
[schema.nodes.paragraph, 'Paragraph'],
|
|
46
30
|
[schema.nodes.section, 'Section'],
|
|
47
|
-
[schema.nodes.section_title, 'Section
|
|
48
|
-
[schema.nodes.section_title_plain, 'Section
|
|
31
|
+
[schema.nodes.section_title, 'Section'],
|
|
32
|
+
[schema.nodes.section_title_plain, 'Section'],
|
|
49
33
|
[schema.nodes.table, 'Table'],
|
|
50
34
|
[schema.nodes.table_element, 'Table'],
|
|
51
35
|
[schema.nodes.blockquote_element, 'Block Quote'],
|
|
52
36
|
[schema.nodes.pullquote_element, 'Pull Quote'],
|
|
37
|
+
[schema.nodes.keywords, 'Section'],
|
|
53
38
|
[schema.nodes.toc_section, 'Section'],
|
|
54
39
|
[schema.nodes.box_element, 'Box'],
|
|
55
40
|
]);
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.5
|
|
1
|
+
export const VERSION = "3.0.5";
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export declare const TABLE_CELL_STYLES: readonly ["backgroundColor", "border-top", "border-right", "border-bottom", "border-left", "verticalAlign", "textAlign"];
|
|
17
|
-
export type TableCellStyleKey =
|
|
17
|
+
export type TableCellStyleKey = typeof TABLE_CELL_STYLES[number];
|
|
18
18
|
export declare const serializeTableCellStyles: (styles: {
|
|
19
19
|
backgroundColor?: string | null | undefined;
|
|
20
20
|
"border-top"?: string | null | undefined;
|
|
@@ -27,3 +27,4 @@ export declare const findParentNodeClosestToPos: ($pos: ResolvedPos, predicate:
|
|
|
27
27
|
} | undefined;
|
|
28
28
|
export declare const getTrimmedTextContent: (node: Element | Document | null, querySelector: string) => string | null | undefined;
|
|
29
29
|
export declare const timestamp: () => number;
|
|
30
|
+
export declare const dateToTimestamp: (dateElement: Element) => number | undefined;
|
|
@@ -24,6 +24,12 @@ export interface ManuscriptAttrs {
|
|
|
24
24
|
articleType: string;
|
|
25
25
|
prototype: string;
|
|
26
26
|
primaryLanguageCode: string;
|
|
27
|
+
acceptanceDate?: number;
|
|
28
|
+
correctionDate?: number;
|
|
29
|
+
retractionDate?: number;
|
|
30
|
+
revisionRequestDate?: number;
|
|
31
|
+
revisionReceiveDate?: number;
|
|
32
|
+
receiveDate?: number;
|
|
27
33
|
}
|
|
28
34
|
export declare const manuscript: NodeSpec;
|
|
29
35
|
export declare const isManuscriptNode: (node: ManuscriptNode) => node is import("prosemirror-model").Node;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.0.5
|
|
1
|
+
export declare const VERSION = "3.0.5";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "3.0.5
|
|
4
|
+
"version": "3.0.5",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -83,4 +83,4 @@
|
|
|
83
83
|
"rimraf": "^3.0.2",
|
|
84
84
|
"typescript": "^4.0.5"
|
|
85
85
|
}
|
|
86
|
-
}
|
|
86
|
+
}
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*!
|
|
3
|
-
* © 2020 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.jatsBodyTransformations = void 0;
|
|
19
|
-
const section_group_type_1 = require("../../lib/section-group-type");
|
|
20
|
-
const transformer_1 = require("../../transformer");
|
|
21
|
-
const removeNodeFromParent = (node) => node.parentNode && node.parentNode.removeChild(node);
|
|
22
|
-
const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
23
|
-
const createSectionGroup = (type, createElement) => {
|
|
24
|
-
const sec = createElement('sec');
|
|
25
|
-
sec.setAttribute('sec-type', type._id);
|
|
26
|
-
const title = createElement('title');
|
|
27
|
-
title.textContent = type.title;
|
|
28
|
-
sec.appendChild(title);
|
|
29
|
-
return sec;
|
|
30
|
-
};
|
|
31
|
-
exports.jatsBodyTransformations = {
|
|
32
|
-
ensureSection(body, createElement) {
|
|
33
|
-
let section;
|
|
34
|
-
const element = body.firstElementChild;
|
|
35
|
-
if (element && element.tagName === 'sec') {
|
|
36
|
-
section = element;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
section = createElement('sec');
|
|
40
|
-
body.insertBefore(section, body.firstChild);
|
|
41
|
-
}
|
|
42
|
-
body.childNodes.forEach((child) => {
|
|
43
|
-
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
44
|
-
const element = child;
|
|
45
|
-
if (element.tagName !== 'sec') {
|
|
46
|
-
section.appendChild(element);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
section = element;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
},
|
|
54
|
-
createAbstractSection(abstractNode, createElement) {
|
|
55
|
-
const abstractType = abstractNode.getAttribute('abstract-type');
|
|
56
|
-
const section = createElement('sec');
|
|
57
|
-
const sectionType = abstractType ? `abstract-${abstractType}` : 'abstract';
|
|
58
|
-
section.setAttribute('sec-type', sectionType);
|
|
59
|
-
if (!abstractNode.querySelector('abstract > title')) {
|
|
60
|
-
const title = createElement('title');
|
|
61
|
-
title.textContent = abstractType
|
|
62
|
-
? `${capitalizeFirstLetter(abstractType)} Abstract`
|
|
63
|
-
: 'Abstract';
|
|
64
|
-
section.appendChild(title);
|
|
65
|
-
}
|
|
66
|
-
while (abstractNode.firstChild) {
|
|
67
|
-
section.appendChild(abstractNode.firstChild);
|
|
68
|
-
}
|
|
69
|
-
return section;
|
|
70
|
-
},
|
|
71
|
-
createAcknowledgmentsSection(ackNode, createElement) {
|
|
72
|
-
const section = createElement('sec');
|
|
73
|
-
section.setAttribute('sec-type', 'acknowledgments');
|
|
74
|
-
const titleNode = ackNode.querySelector('title');
|
|
75
|
-
if (titleNode) {
|
|
76
|
-
section.appendChild(titleNode);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const title = createElement('title');
|
|
80
|
-
title.textContent = 'Acknowledgements';
|
|
81
|
-
section.appendChild(title);
|
|
82
|
-
}
|
|
83
|
-
while (ackNode.firstChild) {
|
|
84
|
-
section.appendChild(ackNode.firstChild);
|
|
85
|
-
}
|
|
86
|
-
return section;
|
|
87
|
-
},
|
|
88
|
-
createFootnotesSection(footnoteGroups, createElement) {
|
|
89
|
-
const section = createElement('sec');
|
|
90
|
-
section.setAttribute('sec-type', 'endnotes');
|
|
91
|
-
const titleNode = footnoteGroups
|
|
92
|
-
.map((g) => g.querySelector('title'))
|
|
93
|
-
.filter((t) => t !== null)[0];
|
|
94
|
-
if (titleNode) {
|
|
95
|
-
section.appendChild(titleNode);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
const title = createElement('title');
|
|
99
|
-
title.textContent = 'Footnotes';
|
|
100
|
-
section.appendChild(title);
|
|
101
|
-
}
|
|
102
|
-
for (const footnoteGroup of footnoteGroups) {
|
|
103
|
-
section.appendChild(footnoteGroup);
|
|
104
|
-
}
|
|
105
|
-
return section;
|
|
106
|
-
},
|
|
107
|
-
createAppendixSection(app, createElement) {
|
|
108
|
-
const section = createElement('sec');
|
|
109
|
-
section.setAttribute('sec-type', 'appendices');
|
|
110
|
-
section.append(...app.children);
|
|
111
|
-
return section;
|
|
112
|
-
},
|
|
113
|
-
createFloatsGroupSection(group, createElement) {
|
|
114
|
-
const section = createElement('sec');
|
|
115
|
-
section.setAttribute('sec-type', 'floating-element');
|
|
116
|
-
const title = createElement('title');
|
|
117
|
-
title.textContent = 'Floating Group';
|
|
118
|
-
section.appendChild(title);
|
|
119
|
-
section.append(...group.children);
|
|
120
|
-
return section;
|
|
121
|
-
},
|
|
122
|
-
moveAbstracts(doc, group, createElement) {
|
|
123
|
-
const abstracts = doc.querySelectorAll('front > article-meta > abstract');
|
|
124
|
-
abstracts.forEach((abstract) => {
|
|
125
|
-
const sec = this.createAbstractSection(abstract, createElement);
|
|
126
|
-
removeNodeFromParent(abstract);
|
|
127
|
-
group.appendChild(sec);
|
|
128
|
-
});
|
|
129
|
-
},
|
|
130
|
-
wrapBodySections(doc, group) {
|
|
131
|
-
const bodySections = doc.querySelectorAll('body > sec:not([sec-type="backmatter"]), body > sec:not([sec-type])');
|
|
132
|
-
bodySections.forEach((section) => {
|
|
133
|
-
removeNodeFromParent(section);
|
|
134
|
-
group.appendChild(section);
|
|
135
|
-
});
|
|
136
|
-
},
|
|
137
|
-
moveBackSections(doc, group) {
|
|
138
|
-
for (const section of doc.querySelectorAll('back > sec')) {
|
|
139
|
-
removeNodeFromParent(section);
|
|
140
|
-
group.appendChild(section);
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
moveAcknowledgments(doc, group, createElement) {
|
|
144
|
-
const ack = doc.querySelector('back > ack');
|
|
145
|
-
if (ack) {
|
|
146
|
-
const sec = this.createAcknowledgmentsSection(ack, createElement);
|
|
147
|
-
removeNodeFromParent(ack);
|
|
148
|
-
group.appendChild(sec);
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
moveAppendices(doc, group, createElement) {
|
|
152
|
-
const apps = doc.querySelectorAll('back > app-group > app');
|
|
153
|
-
for (const app of apps) {
|
|
154
|
-
const sec = this.createAppendixSection(app, createElement);
|
|
155
|
-
removeNodeFromParent(app);
|
|
156
|
-
group.appendChild(sec);
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
createBoxedElementSection(doc, body, createElement) {
|
|
160
|
-
const boxedTexts = body.querySelectorAll('boxed-text');
|
|
161
|
-
for (const boxedText of boxedTexts) {
|
|
162
|
-
const boxElementSec = createElement('sec');
|
|
163
|
-
boxElementSec.setAttribute('sec-type', 'box-element');
|
|
164
|
-
const title = createElement('title');
|
|
165
|
-
title.textContent = 'BoxElement';
|
|
166
|
-
boxElementSec.append(title);
|
|
167
|
-
for (const element of [...boxedText.children]) {
|
|
168
|
-
if ((element === null || element === void 0 ? void 0 : element.tagName) === 'label' || (element === null || element === void 0 ? void 0 : element.tagName) === 'caption') {
|
|
169
|
-
boxElementSec.append(element);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
const containerSection = createElement('sec');
|
|
173
|
-
containerSection.append(...boxedText.children);
|
|
174
|
-
boxElementSec.append(containerSection);
|
|
175
|
-
boxedText.replaceWith(boxElementSec);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
createBody(doc, body, createElement) {
|
|
179
|
-
const group = createSectionGroup(section_group_type_1.bodyType, createElement);
|
|
180
|
-
this.wrapBodySections(doc, group);
|
|
181
|
-
this.moveFloatsGroupToBody(doc, group, createElement);
|
|
182
|
-
body.append(group);
|
|
183
|
-
},
|
|
184
|
-
createAbstracts(doc, body, createElement) {
|
|
185
|
-
const group = createSectionGroup(section_group_type_1.abstractsType, createElement);
|
|
186
|
-
this.moveAbstracts(doc, group, createElement);
|
|
187
|
-
body.insertBefore(group, body.lastElementChild);
|
|
188
|
-
},
|
|
189
|
-
createBackmatter(doc, body, createElement) {
|
|
190
|
-
const group = createSectionGroup(section_group_type_1.backmatterType, createElement);
|
|
191
|
-
this.moveBackSections(doc, group);
|
|
192
|
-
this.moveAppendices(doc, group, createElement);
|
|
193
|
-
this.moveSpecialFootnotes(doc, group, createElement);
|
|
194
|
-
this.moveFootnotes(doc, group, createElement);
|
|
195
|
-
this.moveAcknowledgments(doc, group, createElement);
|
|
196
|
-
body.append(group);
|
|
197
|
-
},
|
|
198
|
-
moveSpecialFootnotes(doc, group, createElement) {
|
|
199
|
-
var _a;
|
|
200
|
-
const fns = [...doc.querySelectorAll('fn[fn-type]')];
|
|
201
|
-
for (const fn of fns) {
|
|
202
|
-
const type = fn.getAttribute('fn-type') || '';
|
|
203
|
-
const category = (0, transformer_1.chooseSectionCategoryByType)(type);
|
|
204
|
-
if (category) {
|
|
205
|
-
const section = createElement('sec');
|
|
206
|
-
const title = fn.querySelector('p[content-type="fn-title"]');
|
|
207
|
-
if (title) {
|
|
208
|
-
const sectionTitleElement = createElement('title');
|
|
209
|
-
const titleTextContent = (_a = title.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
210
|
-
if (titleTextContent) {
|
|
211
|
-
sectionTitleElement.textContent = titleTextContent;
|
|
212
|
-
}
|
|
213
|
-
removeNodeFromParent(title);
|
|
214
|
-
section.append(sectionTitleElement);
|
|
215
|
-
}
|
|
216
|
-
section.append(...fn.children);
|
|
217
|
-
removeNodeFromParent(fn);
|
|
218
|
-
section.setAttribute('sec-type', (0, transformer_1.chooseSecType)(category));
|
|
219
|
-
group.append(section);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
moveFootnotes(doc, group, createElement) {
|
|
224
|
-
var _a;
|
|
225
|
-
const footnotes = Array.from(doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'));
|
|
226
|
-
let footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
|
|
227
|
-
const containingGroup = (footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group')) || createElement('fn-group');
|
|
228
|
-
footnotes.forEach((footnote) => {
|
|
229
|
-
if (!footnote.getAttribute('fn-type')) {
|
|
230
|
-
containingGroup.appendChild(footnote);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
if (!footnotesSection && containingGroup.innerHTML) {
|
|
234
|
-
footnotesSection = this.createFootnotesSection([containingGroup], createElement);
|
|
235
|
-
}
|
|
236
|
-
if (footnotesSection) {
|
|
237
|
-
group.insertBefore(footnotesSection, ((_a = group.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling) || group.firstChild);
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
moveCaptionsToEnd(body) {
|
|
241
|
-
const captions = body.querySelectorAll('caption');
|
|
242
|
-
for (const caption of captions) {
|
|
243
|
-
if (caption.parentNode &&
|
|
244
|
-
caption.parentNode.nodeName !== 'table-wrap' &&
|
|
245
|
-
caption.parentNode.nodeName !== 'boxed-text') {
|
|
246
|
-
caption.parentNode.appendChild(caption);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
fixTables(body, createElement) {
|
|
251
|
-
const tableWraps = body.querySelectorAll('table-wrap');
|
|
252
|
-
tableWraps.forEach((tableWrap) => {
|
|
253
|
-
const table = tableWrap.querySelector('table');
|
|
254
|
-
if (!table) {
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
const colgroup = table.querySelector('colgroup');
|
|
258
|
-
const cols = table.querySelectorAll('col');
|
|
259
|
-
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
260
|
-
const colgroup = createElement('colgroup');
|
|
261
|
-
for (const col of cols) {
|
|
262
|
-
colgroup.appendChild(col);
|
|
263
|
-
}
|
|
264
|
-
tableWrap.insertBefore(colgroup, table.nextSibling);
|
|
265
|
-
}
|
|
266
|
-
const tableFootWrap = tableWrap.querySelector('table-wrap-foot');
|
|
267
|
-
if (tableFootWrap) {
|
|
268
|
-
const paragraphs = tableFootWrap.querySelectorAll(':scope > p');
|
|
269
|
-
if (paragraphs.length) {
|
|
270
|
-
const generalTableFootnote = createElement('general-table-footnote');
|
|
271
|
-
for (const paragraph of paragraphs) {
|
|
272
|
-
removeNodeFromParent(paragraph);
|
|
273
|
-
generalTableFootnote.append(paragraph);
|
|
274
|
-
}
|
|
275
|
-
tableFootWrap.prepend(generalTableFootnote);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
},
|
|
280
|
-
orderTableFootnote(doc, body) {
|
|
281
|
-
const tableInlineFootnotesIds = new Set(Array.from(body.querySelectorAll('tbody > tr > td > xref[ref-type="fn"]').values()).map((inlineFootnote) => inlineFootnote.getAttribute('rid')));
|
|
282
|
-
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
283
|
-
fnGroups.forEach((fnGroup) => {
|
|
284
|
-
const orderedFootnotes = Array.from(fnGroup.querySelectorAll('fn')).sort((fn) => tableInlineFootnotesIds.has(fn.getAttribute('id'))
|
|
285
|
-
? -1
|
|
286
|
-
: 0);
|
|
287
|
-
fnGroup.replaceChildren(...orderedFootnotes);
|
|
288
|
-
});
|
|
289
|
-
},
|
|
290
|
-
moveFloatsGroupToBody(doc, body, createElement) {
|
|
291
|
-
const group = doc.querySelector('floats-group');
|
|
292
|
-
if (group) {
|
|
293
|
-
const sec = this.createFloatsGroupSection(group, createElement);
|
|
294
|
-
removeNodeFromParent(group);
|
|
295
|
-
body.appendChild(sec);
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
createKeywords(document, body, createElement) {
|
|
299
|
-
const keywordGroups = [...document.querySelectorAll('kwd-group')];
|
|
300
|
-
if (keywordGroups.length > 0) {
|
|
301
|
-
const section = createElement('sec');
|
|
302
|
-
section.setAttribute('sec-type', 'keywords');
|
|
303
|
-
const title = createElement('title');
|
|
304
|
-
title.textContent = 'Keywords';
|
|
305
|
-
section.append(title);
|
|
306
|
-
const keywordsElement = createElement('kwd-group-list');
|
|
307
|
-
keywordsElement.append(keywordGroups[0]);
|
|
308
|
-
section.append(keywordsElement);
|
|
309
|
-
body.prepend(section);
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
createSuppleMaterials(document, body, createElement) {
|
|
313
|
-
const suppleMaterials = [
|
|
314
|
-
...document.querySelectorAll('article-meta > supplementary-material'),
|
|
315
|
-
];
|
|
316
|
-
if (suppleMaterials.length > 0) {
|
|
317
|
-
const section = createElement('sec');
|
|
318
|
-
section.setAttribute('sec-type', 'supplementary-material');
|
|
319
|
-
const title = createElement('title');
|
|
320
|
-
title.textContent = 'supplementary-material';
|
|
321
|
-
section.append(title);
|
|
322
|
-
section.append(...suppleMaterials);
|
|
323
|
-
body.prepend(section);
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
};
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2020 Atypon Systems LLC
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { abstractsType, backmatterType, bodyType, } from '../../lib/section-group-type';
|
|
17
|
-
import { chooseSectionCategoryByType, chooseSecType } from '../../transformer';
|
|
18
|
-
const removeNodeFromParent = (node) => node.parentNode && node.parentNode.removeChild(node);
|
|
19
|
-
const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
|
|
20
|
-
const createSectionGroup = (type, createElement) => {
|
|
21
|
-
const sec = createElement('sec');
|
|
22
|
-
sec.setAttribute('sec-type', type._id);
|
|
23
|
-
const title = createElement('title');
|
|
24
|
-
title.textContent = type.title;
|
|
25
|
-
sec.appendChild(title);
|
|
26
|
-
return sec;
|
|
27
|
-
};
|
|
28
|
-
export const jatsBodyTransformations = {
|
|
29
|
-
ensureSection(body, createElement) {
|
|
30
|
-
let section;
|
|
31
|
-
const element = body.firstElementChild;
|
|
32
|
-
if (element && element.tagName === 'sec') {
|
|
33
|
-
section = element;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
section = createElement('sec');
|
|
37
|
-
body.insertBefore(section, body.firstChild);
|
|
38
|
-
}
|
|
39
|
-
body.childNodes.forEach((child) => {
|
|
40
|
-
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
41
|
-
const element = child;
|
|
42
|
-
if (element.tagName !== 'sec') {
|
|
43
|
-
section.appendChild(element);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
section = element;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
createAbstractSection(abstractNode, createElement) {
|
|
52
|
-
const abstractType = abstractNode.getAttribute('abstract-type');
|
|
53
|
-
const section = createElement('sec');
|
|
54
|
-
const sectionType = abstractType ? `abstract-${abstractType}` : 'abstract';
|
|
55
|
-
section.setAttribute('sec-type', sectionType);
|
|
56
|
-
if (!abstractNode.querySelector('abstract > title')) {
|
|
57
|
-
const title = createElement('title');
|
|
58
|
-
title.textContent = abstractType
|
|
59
|
-
? `${capitalizeFirstLetter(abstractType)} Abstract`
|
|
60
|
-
: 'Abstract';
|
|
61
|
-
section.appendChild(title);
|
|
62
|
-
}
|
|
63
|
-
while (abstractNode.firstChild) {
|
|
64
|
-
section.appendChild(abstractNode.firstChild);
|
|
65
|
-
}
|
|
66
|
-
return section;
|
|
67
|
-
},
|
|
68
|
-
createAcknowledgmentsSection(ackNode, createElement) {
|
|
69
|
-
const section = createElement('sec');
|
|
70
|
-
section.setAttribute('sec-type', 'acknowledgments');
|
|
71
|
-
const titleNode = ackNode.querySelector('title');
|
|
72
|
-
if (titleNode) {
|
|
73
|
-
section.appendChild(titleNode);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
const title = createElement('title');
|
|
77
|
-
title.textContent = 'Acknowledgements';
|
|
78
|
-
section.appendChild(title);
|
|
79
|
-
}
|
|
80
|
-
while (ackNode.firstChild) {
|
|
81
|
-
section.appendChild(ackNode.firstChild);
|
|
82
|
-
}
|
|
83
|
-
return section;
|
|
84
|
-
},
|
|
85
|
-
createFootnotesSection(footnoteGroups, createElement) {
|
|
86
|
-
const section = createElement('sec');
|
|
87
|
-
section.setAttribute('sec-type', 'endnotes');
|
|
88
|
-
const titleNode = footnoteGroups
|
|
89
|
-
.map((g) => g.querySelector('title'))
|
|
90
|
-
.filter((t) => t !== null)[0];
|
|
91
|
-
if (titleNode) {
|
|
92
|
-
section.appendChild(titleNode);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const title = createElement('title');
|
|
96
|
-
title.textContent = 'Footnotes';
|
|
97
|
-
section.appendChild(title);
|
|
98
|
-
}
|
|
99
|
-
for (const footnoteGroup of footnoteGroups) {
|
|
100
|
-
section.appendChild(footnoteGroup);
|
|
101
|
-
}
|
|
102
|
-
return section;
|
|
103
|
-
},
|
|
104
|
-
createAppendixSection(app, createElement) {
|
|
105
|
-
const section = createElement('sec');
|
|
106
|
-
section.setAttribute('sec-type', 'appendices');
|
|
107
|
-
section.append(...app.children);
|
|
108
|
-
return section;
|
|
109
|
-
},
|
|
110
|
-
createFloatsGroupSection(group, createElement) {
|
|
111
|
-
const section = createElement('sec');
|
|
112
|
-
section.setAttribute('sec-type', 'floating-element');
|
|
113
|
-
const title = createElement('title');
|
|
114
|
-
title.textContent = 'Floating Group';
|
|
115
|
-
section.appendChild(title);
|
|
116
|
-
section.append(...group.children);
|
|
117
|
-
return section;
|
|
118
|
-
},
|
|
119
|
-
moveAbstracts(doc, group, createElement) {
|
|
120
|
-
const abstracts = doc.querySelectorAll('front > article-meta > abstract');
|
|
121
|
-
abstracts.forEach((abstract) => {
|
|
122
|
-
const sec = this.createAbstractSection(abstract, createElement);
|
|
123
|
-
removeNodeFromParent(abstract);
|
|
124
|
-
group.appendChild(sec);
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
wrapBodySections(doc, group) {
|
|
128
|
-
const bodySections = doc.querySelectorAll('body > sec:not([sec-type="backmatter"]), body > sec:not([sec-type])');
|
|
129
|
-
bodySections.forEach((section) => {
|
|
130
|
-
removeNodeFromParent(section);
|
|
131
|
-
group.appendChild(section);
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
moveBackSections(doc, group) {
|
|
135
|
-
for (const section of doc.querySelectorAll('back > sec')) {
|
|
136
|
-
removeNodeFromParent(section);
|
|
137
|
-
group.appendChild(section);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
moveAcknowledgments(doc, group, createElement) {
|
|
141
|
-
const ack = doc.querySelector('back > ack');
|
|
142
|
-
if (ack) {
|
|
143
|
-
const sec = this.createAcknowledgmentsSection(ack, createElement);
|
|
144
|
-
removeNodeFromParent(ack);
|
|
145
|
-
group.appendChild(sec);
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
moveAppendices(doc, group, createElement) {
|
|
149
|
-
const apps = doc.querySelectorAll('back > app-group > app');
|
|
150
|
-
for (const app of apps) {
|
|
151
|
-
const sec = this.createAppendixSection(app, createElement);
|
|
152
|
-
removeNodeFromParent(app);
|
|
153
|
-
group.appendChild(sec);
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
createBoxedElementSection(doc, body, createElement) {
|
|
157
|
-
const boxedTexts = body.querySelectorAll('boxed-text');
|
|
158
|
-
for (const boxedText of boxedTexts) {
|
|
159
|
-
const boxElementSec = createElement('sec');
|
|
160
|
-
boxElementSec.setAttribute('sec-type', 'box-element');
|
|
161
|
-
const title = createElement('title');
|
|
162
|
-
title.textContent = 'BoxElement';
|
|
163
|
-
boxElementSec.append(title);
|
|
164
|
-
for (const element of [...boxedText.children]) {
|
|
165
|
-
if ((element === null || element === void 0 ? void 0 : element.tagName) === 'label' || (element === null || element === void 0 ? void 0 : element.tagName) === 'caption') {
|
|
166
|
-
boxElementSec.append(element);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
const containerSection = createElement('sec');
|
|
170
|
-
containerSection.append(...boxedText.children);
|
|
171
|
-
boxElementSec.append(containerSection);
|
|
172
|
-
boxedText.replaceWith(boxElementSec);
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
createBody(doc, body, createElement) {
|
|
176
|
-
const group = createSectionGroup(bodyType, createElement);
|
|
177
|
-
this.wrapBodySections(doc, group);
|
|
178
|
-
this.moveFloatsGroupToBody(doc, group, createElement);
|
|
179
|
-
body.append(group);
|
|
180
|
-
},
|
|
181
|
-
createAbstracts(doc, body, createElement) {
|
|
182
|
-
const group = createSectionGroup(abstractsType, createElement);
|
|
183
|
-
this.moveAbstracts(doc, group, createElement);
|
|
184
|
-
body.insertBefore(group, body.lastElementChild);
|
|
185
|
-
},
|
|
186
|
-
createBackmatter(doc, body, createElement) {
|
|
187
|
-
const group = createSectionGroup(backmatterType, createElement);
|
|
188
|
-
this.moveBackSections(doc, group);
|
|
189
|
-
this.moveAppendices(doc, group, createElement);
|
|
190
|
-
this.moveSpecialFootnotes(doc, group, createElement);
|
|
191
|
-
this.moveFootnotes(doc, group, createElement);
|
|
192
|
-
this.moveAcknowledgments(doc, group, createElement);
|
|
193
|
-
body.append(group);
|
|
194
|
-
},
|
|
195
|
-
moveSpecialFootnotes(doc, group, createElement) {
|
|
196
|
-
var _a;
|
|
197
|
-
const fns = [...doc.querySelectorAll('fn[fn-type]')];
|
|
198
|
-
for (const fn of fns) {
|
|
199
|
-
const type = fn.getAttribute('fn-type') || '';
|
|
200
|
-
const category = chooseSectionCategoryByType(type);
|
|
201
|
-
if (category) {
|
|
202
|
-
const section = createElement('sec');
|
|
203
|
-
const title = fn.querySelector('p[content-type="fn-title"]');
|
|
204
|
-
if (title) {
|
|
205
|
-
const sectionTitleElement = createElement('title');
|
|
206
|
-
const titleTextContent = (_a = title.textContent) === null || _a === void 0 ? void 0 : _a.trim();
|
|
207
|
-
if (titleTextContent) {
|
|
208
|
-
sectionTitleElement.textContent = titleTextContent;
|
|
209
|
-
}
|
|
210
|
-
removeNodeFromParent(title);
|
|
211
|
-
section.append(sectionTitleElement);
|
|
212
|
-
}
|
|
213
|
-
section.append(...fn.children);
|
|
214
|
-
removeNodeFromParent(fn);
|
|
215
|
-
section.setAttribute('sec-type', chooseSecType(category));
|
|
216
|
-
group.append(section);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
moveFootnotes(doc, group, createElement) {
|
|
221
|
-
var _a;
|
|
222
|
-
const footnotes = Array.from(doc.querySelectorAll('fn:not(table-wrap-foot fn, author-notes fn)'));
|
|
223
|
-
let footnotesSection = doc.querySelector('sec[sec-type="endnotes"]');
|
|
224
|
-
const containingGroup = (footnotesSection === null || footnotesSection === void 0 ? void 0 : footnotesSection.querySelector('fn-group')) || createElement('fn-group');
|
|
225
|
-
footnotes.forEach((footnote) => {
|
|
226
|
-
if (!footnote.getAttribute('fn-type')) {
|
|
227
|
-
containingGroup.appendChild(footnote);
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
if (!footnotesSection && containingGroup.innerHTML) {
|
|
231
|
-
footnotesSection = this.createFootnotesSection([containingGroup], createElement);
|
|
232
|
-
}
|
|
233
|
-
if (footnotesSection) {
|
|
234
|
-
group.insertBefore(footnotesSection, ((_a = group.firstChild) === null || _a === void 0 ? void 0 : _a.nextSibling) || group.firstChild);
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
moveCaptionsToEnd(body) {
|
|
238
|
-
const captions = body.querySelectorAll('caption');
|
|
239
|
-
for (const caption of captions) {
|
|
240
|
-
if (caption.parentNode &&
|
|
241
|
-
caption.parentNode.nodeName !== 'table-wrap' &&
|
|
242
|
-
caption.parentNode.nodeName !== 'boxed-text') {
|
|
243
|
-
caption.parentNode.appendChild(caption);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
},
|
|
247
|
-
fixTables(body, createElement) {
|
|
248
|
-
const tableWraps = body.querySelectorAll('table-wrap');
|
|
249
|
-
tableWraps.forEach((tableWrap) => {
|
|
250
|
-
const table = tableWrap.querySelector('table');
|
|
251
|
-
if (!table) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
const colgroup = table.querySelector('colgroup');
|
|
255
|
-
const cols = table.querySelectorAll('col');
|
|
256
|
-
if (!colgroup && table.firstChild && cols.length > 0) {
|
|
257
|
-
const colgroup = createElement('colgroup');
|
|
258
|
-
for (const col of cols) {
|
|
259
|
-
colgroup.appendChild(col);
|
|
260
|
-
}
|
|
261
|
-
tableWrap.insertBefore(colgroup, table.nextSibling);
|
|
262
|
-
}
|
|
263
|
-
const tableFootWrap = tableWrap.querySelector('table-wrap-foot');
|
|
264
|
-
if (tableFootWrap) {
|
|
265
|
-
const paragraphs = tableFootWrap.querySelectorAll(':scope > p');
|
|
266
|
-
if (paragraphs.length) {
|
|
267
|
-
const generalTableFootnote = createElement('general-table-footnote');
|
|
268
|
-
for (const paragraph of paragraphs) {
|
|
269
|
-
removeNodeFromParent(paragraph);
|
|
270
|
-
generalTableFootnote.append(paragraph);
|
|
271
|
-
}
|
|
272
|
-
tableFootWrap.prepend(generalTableFootnote);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
},
|
|
277
|
-
orderTableFootnote(doc, body) {
|
|
278
|
-
const tableInlineFootnotesIds = new Set(Array.from(body.querySelectorAll('tbody > tr > td > xref[ref-type="fn"]').values()).map((inlineFootnote) => inlineFootnote.getAttribute('rid')));
|
|
279
|
-
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
280
|
-
fnGroups.forEach((fnGroup) => {
|
|
281
|
-
const orderedFootnotes = Array.from(fnGroup.querySelectorAll('fn')).sort((fn) => tableInlineFootnotesIds.has(fn.getAttribute('id'))
|
|
282
|
-
? -1
|
|
283
|
-
: 0);
|
|
284
|
-
fnGroup.replaceChildren(...orderedFootnotes);
|
|
285
|
-
});
|
|
286
|
-
},
|
|
287
|
-
moveFloatsGroupToBody(doc, body, createElement) {
|
|
288
|
-
const group = doc.querySelector('floats-group');
|
|
289
|
-
if (group) {
|
|
290
|
-
const sec = this.createFloatsGroupSection(group, createElement);
|
|
291
|
-
removeNodeFromParent(group);
|
|
292
|
-
body.appendChild(sec);
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
createKeywords(document, body, createElement) {
|
|
296
|
-
const keywordGroups = [...document.querySelectorAll('kwd-group')];
|
|
297
|
-
if (keywordGroups.length > 0) {
|
|
298
|
-
const section = createElement('sec');
|
|
299
|
-
section.setAttribute('sec-type', 'keywords');
|
|
300
|
-
const title = createElement('title');
|
|
301
|
-
title.textContent = 'Keywords';
|
|
302
|
-
section.append(title);
|
|
303
|
-
const keywordsElement = createElement('kwd-group-list');
|
|
304
|
-
keywordsElement.append(keywordGroups[0]);
|
|
305
|
-
section.append(keywordsElement);
|
|
306
|
-
body.prepend(section);
|
|
307
|
-
}
|
|
308
|
-
},
|
|
309
|
-
createSuppleMaterials(document, body, createElement) {
|
|
310
|
-
const suppleMaterials = [
|
|
311
|
-
...document.querySelectorAll('article-meta > supplementary-material'),
|
|
312
|
-
];
|
|
313
|
-
if (suppleMaterials.length > 0) {
|
|
314
|
-
const section = createElement('sec');
|
|
315
|
-
section.setAttribute('sec-type', 'supplementary-material');
|
|
316
|
-
const title = createElement('title');
|
|
317
|
-
title.textContent = 'supplementary-material';
|
|
318
|
-
section.append(title);
|
|
319
|
-
section.append(...suppleMaterials);
|
|
320
|
-
body.prepend(section);
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* © 2020 Atypon Systems LLC
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
export declare const jatsBodyTransformations: {
|
|
17
|
-
ensureSection(body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
18
|
-
createAbstractSection(abstractNode: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
19
|
-
createAcknowledgmentsSection(ackNode: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
20
|
-
createFootnotesSection(footnoteGroups: Element[], createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
21
|
-
createAppendixSection(app: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
22
|
-
createFloatsGroupSection(group: Element, createElement: (tagName: string) => HTMLElement): HTMLElement;
|
|
23
|
-
moveAbstracts(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
24
|
-
wrapBodySections(doc: Document, group: Element): void;
|
|
25
|
-
moveBackSections(doc: Document, group: Element): void;
|
|
26
|
-
moveAcknowledgments(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
27
|
-
moveAppendices(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
28
|
-
createBoxedElementSection(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
29
|
-
createBody(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
30
|
-
createAbstracts(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
31
|
-
createBackmatter(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
32
|
-
moveSpecialFootnotes(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
33
|
-
moveFootnotes(doc: Document, group: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
34
|
-
moveCaptionsToEnd(body: Element): void;
|
|
35
|
-
fixTables(body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
36
|
-
orderTableFootnote(doc: Document, body: Element): void;
|
|
37
|
-
moveFloatsGroupToBody(doc: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
38
|
-
createKeywords(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
39
|
-
createSuppleMaterials(document: Document, body: Element, createElement: (tagName: string) => HTMLElement): void;
|
|
40
|
-
};
|