@manuscripts/transform 3.0.50 → 3.0.52
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 +61 -35
- package/dist/cjs/jats/importer/jats-dom-parser.js +1 -1
- package/dist/cjs/schema/nodes/pullquote_element.js +1 -1
- package/dist/cjs/schema/types.js +5 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/jats/exporter/jats-exporter.js +62 -36
- package/dist/es/jats/importer/jats-dom-parser.js +1 -1
- package/dist/es/schema/nodes/pullquote_element.js +1 -1
- package/dist/es/schema/types.js +3 -1
- package/dist/es/version.js +1 -1
- package/dist/types/jats/exporter/jats-exporter.d.ts +5 -1
- package/dist/types/schema/types.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -127,9 +127,20 @@ class JATSExporter {
|
|
|
127
127
|
};
|
|
128
128
|
};
|
|
129
129
|
};
|
|
130
|
+
this.nodesMap = new Map();
|
|
131
|
+
this.populateNodesMap = () => {
|
|
132
|
+
this.manuscriptNode.descendants((node) => {
|
|
133
|
+
var _a;
|
|
134
|
+
const type = node.type;
|
|
135
|
+
const nodes = (_a = this.nodesMap.get(type)) !== null && _a !== void 0 ? _a : [];
|
|
136
|
+
nodes.push(node);
|
|
137
|
+
this.nodesMap.set(type, nodes);
|
|
138
|
+
});
|
|
139
|
+
};
|
|
130
140
|
this.serializeToJATS = async (manuscriptNode, options) => {
|
|
131
141
|
var _a;
|
|
132
142
|
this.manuscriptNode = manuscriptNode;
|
|
143
|
+
this.populateNodesMap();
|
|
133
144
|
this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
|
|
134
145
|
this.createSerializer();
|
|
135
146
|
const versionIds = (0, jats_versions_1.selectVersionIds)((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
|
|
@@ -269,13 +280,13 @@ class JATSExporter {
|
|
|
269
280
|
articleMeta.appendChild(articleID);
|
|
270
281
|
}
|
|
271
282
|
const titleGroup = this.document.createElement('title-group');
|
|
272
|
-
const titleNode =
|
|
283
|
+
const titleNode = this.getFirstChildOfType(schema_1.schema.nodes.title);
|
|
273
284
|
if (titleNode) {
|
|
274
285
|
const element = this.document.createElement('article-title');
|
|
275
286
|
this.setTitleContent(element, titleNode.textContent);
|
|
276
287
|
titleGroup.appendChild(element);
|
|
277
288
|
}
|
|
278
|
-
const altTitlesNodes =
|
|
289
|
+
const altTitlesNodes = this.getChildrenOfType(schema_1.schema.nodes.alt_title);
|
|
279
290
|
altTitlesNodes.forEach((titleNode) => {
|
|
280
291
|
const element = this.document.createElement('alt-title');
|
|
281
292
|
element.setAttribute('alt-title-type', titleNode.attrs.type);
|
|
@@ -284,8 +295,8 @@ class JATSExporter {
|
|
|
284
295
|
});
|
|
285
296
|
articleMeta.appendChild(titleGroup);
|
|
286
297
|
this.buildContributors(articleMeta);
|
|
287
|
-
const supplementsNodes =
|
|
288
|
-
supplementsNodes.forEach((
|
|
298
|
+
const supplementsNodes = this.getChildrenOfType(schema_1.schema.nodes.supplement);
|
|
299
|
+
supplementsNodes.forEach((node) => {
|
|
289
300
|
var _a, _b, _c, _d;
|
|
290
301
|
const supplementaryMaterial = this.document.createElement('supplementary-material');
|
|
291
302
|
supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
|
|
@@ -330,13 +341,13 @@ class JATSExporter {
|
|
|
330
341
|
}
|
|
331
342
|
this.buildKeywords(articleMeta);
|
|
332
343
|
let countingElements = [];
|
|
333
|
-
const figureCount =
|
|
344
|
+
const figureCount = this.getChildrenOfType(schema_1.schema.nodes.figure).length;
|
|
334
345
|
countingElements.push(this.buildCountingElement('fig-count', figureCount));
|
|
335
|
-
const tableCount =
|
|
346
|
+
const tableCount = this.getChildrenOfType(schema_1.schema.nodes.table).length;
|
|
336
347
|
countingElements.push(this.buildCountingElement('table-count', tableCount));
|
|
337
|
-
const equationCount =
|
|
348
|
+
const equationCount = this.getChildrenOfType(schema_1.schema.nodes.equation_element).length;
|
|
338
349
|
countingElements.push(this.buildCountingElement('equation-count', equationCount));
|
|
339
|
-
const referencesCount =
|
|
350
|
+
const referencesCount = this.getChildrenOfType(schema_1.schema.nodes.bibliography_item).length;
|
|
340
351
|
countingElements.push(this.buildCountingElement('ref-count', referencesCount));
|
|
341
352
|
const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
|
|
342
353
|
countingElements.push(this.buildCountingElement('word-count', wordCount));
|
|
@@ -349,7 +360,7 @@ class JATSExporter {
|
|
|
349
360
|
if (!journalMeta.hasChildNodes()) {
|
|
350
361
|
journalMeta.remove();
|
|
351
362
|
}
|
|
352
|
-
const selfUriAttachments =
|
|
363
|
+
const selfUriAttachments = this.getChildrenOfType(schema_1.schema.nodes.attachment);
|
|
353
364
|
selfUriAttachments.forEach((attachment) => {
|
|
354
365
|
const selfUriElement = this.document.createElement('self-uri');
|
|
355
366
|
selfUriElement.setAttribute('content-type', attachment.attrs.type);
|
|
@@ -416,7 +427,7 @@ class JATSExporter {
|
|
|
416
427
|
refList = this.document.createElement('ref-list');
|
|
417
428
|
}
|
|
418
429
|
back.appendChild(refList);
|
|
419
|
-
const bibliographyItems =
|
|
430
|
+
const bibliographyItems = this.getChildrenOfType(schema_1.schema.nodes.bibliography_item);
|
|
420
431
|
const [meta] = this.citationProvider.makeBibliography();
|
|
421
432
|
for (const [id] of meta.entry_ids) {
|
|
422
433
|
const bibliographyItem = bibliographyItems.find((n) => n.attrs.id === id);
|
|
@@ -805,11 +816,14 @@ class JATSExporter {
|
|
|
805
816
|
placeholder_element: () => {
|
|
806
817
|
return this.document.createElement('boxed-text');
|
|
807
818
|
},
|
|
808
|
-
pullquote_element: () =>
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
0
|
|
812
|
-
|
|
819
|
+
pullquote_element: (node) => {
|
|
820
|
+
var _a;
|
|
821
|
+
let type = 'pullquote';
|
|
822
|
+
if (((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema_1.schema.nodes.figure) {
|
|
823
|
+
type = 'quote-with-image';
|
|
824
|
+
}
|
|
825
|
+
return ['disp-quote', { 'content-type': type }, 0];
|
|
826
|
+
},
|
|
813
827
|
graphical_abstract_section: (node) => {
|
|
814
828
|
const attrs = {
|
|
815
829
|
id: normalizeID(node.attrs.id),
|
|
@@ -913,16 +927,14 @@ class JATSExporter {
|
|
|
913
927
|
}
|
|
914
928
|
};
|
|
915
929
|
const appendChildNodeOfType = (element, node, type) => {
|
|
916
|
-
|
|
917
|
-
const childNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
930
|
+
const childNode = this.getFirstChildOfType(type, node);
|
|
918
931
|
if (childNode) {
|
|
919
932
|
element.appendChild(this.serializeNode(childNode));
|
|
920
933
|
}
|
|
921
934
|
};
|
|
922
935
|
const appendTable = (element, node) => {
|
|
923
|
-
|
|
924
|
-
const
|
|
925
|
-
const colGroupNode = (_b = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
|
|
936
|
+
const tableNode = this.getFirstChildOfType(schema_1.schema.nodes.table, node);
|
|
937
|
+
const colGroupNode = this.getFirstChildOfType(schema_1.schema.nodes.table_colgroup, node);
|
|
926
938
|
if (!tableNode) {
|
|
927
939
|
return;
|
|
928
940
|
}
|
|
@@ -947,6 +959,13 @@ class JATSExporter {
|
|
|
947
959
|
processChildNodes(element, node, node.type.schema.nodes.section);
|
|
948
960
|
return element;
|
|
949
961
|
};
|
|
962
|
+
const isChildOfNodeType = (targetID, type, descend = false) => {
|
|
963
|
+
const nodes = this.getChildrenOfType(type);
|
|
964
|
+
return nodes.some((node) => {
|
|
965
|
+
const result = (0, prosemirror_utils_1.findChildrenByAttr)(node, (attrs) => attrs.id === targetID, descend)[0];
|
|
966
|
+
return !!result;
|
|
967
|
+
});
|
|
968
|
+
};
|
|
950
969
|
const createImage = (node) => {
|
|
951
970
|
const graphicNode = node.content.firstChild;
|
|
952
971
|
if (graphicNode) {
|
|
@@ -957,18 +976,19 @@ class JATSExporter {
|
|
|
957
976
|
}
|
|
958
977
|
return '';
|
|
959
978
|
};
|
|
960
|
-
const createGraphic = (node
|
|
979
|
+
const createGraphic = (node) => {
|
|
961
980
|
const graphic = this.document.createElement('graphic');
|
|
962
981
|
graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', node.attrs.src);
|
|
963
|
-
if (!
|
|
982
|
+
if (!isChildOfNodeType(node.attrs.id, schema_1.schema.nodes.figure_element) &&
|
|
983
|
+
node.attrs.type) {
|
|
964
984
|
graphic.setAttribute('content-type', node.attrs.type);
|
|
965
985
|
}
|
|
966
986
|
return graphic;
|
|
967
987
|
};
|
|
968
988
|
const createFigureElement = (node, contentNodeType) => {
|
|
969
989
|
const element = createElement(node, 'fig');
|
|
970
|
-
const figNode =
|
|
971
|
-
const figType = figNode === null || figNode === void 0 ? void 0 : figNode.
|
|
990
|
+
const figNode = this.getFirstChildOfType(schema_1.schema.nodes.figure, node);
|
|
991
|
+
const figType = figNode === null || figNode === void 0 ? void 0 : figNode.attrs.type;
|
|
972
992
|
if (figType) {
|
|
973
993
|
element.setAttribute('fig-type', figType);
|
|
974
994
|
}
|
|
@@ -999,8 +1019,7 @@ class JATSExporter {
|
|
|
999
1019
|
return element;
|
|
1000
1020
|
};
|
|
1001
1021
|
const processExecutableNode = (node, element) => {
|
|
1002
|
-
|
|
1003
|
-
const listingNode = (_a = (0, prosemirror_utils_1.findChildrenByType)(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
1022
|
+
const listingNode = this.getFirstChildOfType(schema_1.schema.nodes.listing, node);
|
|
1004
1023
|
if (listingNode) {
|
|
1005
1024
|
const { contents, languageKey } = listingNode.attrs;
|
|
1006
1025
|
if (contents && languageKey) {
|
|
@@ -1029,7 +1048,7 @@ class JATSExporter {
|
|
|
1029
1048
|
}
|
|
1030
1049
|
};
|
|
1031
1050
|
this.buildContributors = (articleMeta) => {
|
|
1032
|
-
const contributorNodes =
|
|
1051
|
+
const contributorNodes = this.getChildrenOfType(schema_1.schema.nodes.contributor);
|
|
1033
1052
|
const authorContributorNodes = contributorNodes
|
|
1034
1053
|
.filter((n) => n.attrs.role === 'author')
|
|
1035
1054
|
.sort(sortContributors);
|
|
@@ -1163,8 +1182,8 @@ class JATSExporter {
|
|
|
1163
1182
|
affiliationRIDs.push(...contributor.attrs.affiliations);
|
|
1164
1183
|
}
|
|
1165
1184
|
}
|
|
1166
|
-
const affiliations =
|
|
1167
|
-
if (affiliations) {
|
|
1185
|
+
const affiliations = this.getChildrenOfType(schema_1.schema.nodes.affiliation);
|
|
1186
|
+
if (affiliations.length) {
|
|
1168
1187
|
const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
|
|
1169
1188
|
usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
|
|
1170
1189
|
affiliationRIDs.indexOf(b.attrs.id));
|
|
@@ -1230,9 +1249,8 @@ class JATSExporter {
|
|
|
1230
1249
|
}
|
|
1231
1250
|
};
|
|
1232
1251
|
this.createAuthorNotesElement = () => {
|
|
1233
|
-
var _a;
|
|
1234
1252
|
const authorNotesEl = this.document.createElement('author-notes');
|
|
1235
|
-
const authorNotesNode =
|
|
1253
|
+
const authorNotesNode = this.getFirstChildOfType(schema_1.schema.nodes.author_notes);
|
|
1236
1254
|
if (authorNotesNode) {
|
|
1237
1255
|
this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
|
|
1238
1256
|
}
|
|
@@ -1394,9 +1412,8 @@ class JATSExporter {
|
|
|
1394
1412
|
}
|
|
1395
1413
|
};
|
|
1396
1414
|
this.moveAbstracts = (front, body) => {
|
|
1397
|
-
var _a;
|
|
1398
1415
|
const container = body.querySelector(':scope > sec[sec-type="abstracts"]');
|
|
1399
|
-
const abstractsNode =
|
|
1416
|
+
const abstractsNode = this.getFirstChildOfType(schema_1.schema.nodes.abstracts);
|
|
1400
1417
|
const abstractCategories = this.getAbstractCategories(abstractsNode);
|
|
1401
1418
|
const abstractSections = this.getAbstractSections(container, body, abstractCategories);
|
|
1402
1419
|
if (abstractSections.length) {
|
|
@@ -1531,6 +1548,15 @@ class JATSExporter {
|
|
|
1531
1548
|
this.citationTexts.set(id, output);
|
|
1532
1549
|
});
|
|
1533
1550
|
}
|
|
1551
|
+
getFirstChildOfType(type, node) {
|
|
1552
|
+
return this.getChildrenOfType(type, node)[0];
|
|
1553
|
+
}
|
|
1554
|
+
getChildrenOfType(type, node) {
|
|
1555
|
+
const nodes = node
|
|
1556
|
+
? (0, prosemirror_utils_1.findChildrenByType)(node, type).map(({ node }) => node)
|
|
1557
|
+
: this.nodesMap.get(type);
|
|
1558
|
+
return (nodes !== null && nodes !== void 0 ? nodes : []).filter((n) => (0, schema_1.isNodeOfType)(n, type));
|
|
1559
|
+
}
|
|
1534
1560
|
createEquation(node, isInline = false) {
|
|
1535
1561
|
if (node.attrs.format === 'tex') {
|
|
1536
1562
|
const texMath = this.document.createElement('tex-math');
|
|
@@ -1554,7 +1580,7 @@ class JATSExporter {
|
|
|
1554
1580
|
}
|
|
1555
1581
|
}
|
|
1556
1582
|
appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
|
|
1557
|
-
const contributorsNodes =
|
|
1583
|
+
const contributorsNodes = this.getChildrenOfType(schema_1.schema.nodes.contributor);
|
|
1558
1584
|
const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
|
|
1559
1585
|
authorNotesNode.descendants((node) => {
|
|
1560
1586
|
switch (node.type) {
|
|
@@ -1583,7 +1609,7 @@ class JATSExporter {
|
|
|
1583
1609
|
.filter((corresp) => !!corresp);
|
|
1584
1610
|
}
|
|
1585
1611
|
buildKeywords(articleMeta) {
|
|
1586
|
-
const keywordGroups =
|
|
1612
|
+
const keywordGroups = this.getChildrenOfType(schema_1.schema.nodes.keyword_group);
|
|
1587
1613
|
keywordGroups.forEach((group) => {
|
|
1588
1614
|
const kwdGroup = this.document.createElement('kwd-group');
|
|
1589
1615
|
if (group.attrs.type) {
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.isPullquoteElement = exports.pullquoteElement = void 0;
|
|
19
19
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
20
|
exports.pullquoteElement = {
|
|
21
|
-
content: 'paragraph+ attribution',
|
|
21
|
+
content: 'figure? paragraph+ attribution',
|
|
22
22
|
attrs: {
|
|
23
23
|
id: { default: '' },
|
|
24
24
|
placeholder: { default: '' },
|
package/dist/cjs/schema/types.js
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -21,7 +21,7 @@ import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils';
|
|
|
21
21
|
import serializeToXML from 'w3c-xmlserializer';
|
|
22
22
|
import { generateFootnoteLabels } from '../../lib/footnotes';
|
|
23
23
|
import { nodeFromHTML, textFromHTML } from '../../lib/html';
|
|
24
|
-
import { isCitationNode, schema, } from '../../schema';
|
|
24
|
+
import { isCitationNode, isNodeOfType, schema, } from '../../schema';
|
|
25
25
|
import { isExecutableNodeType, isNodeType } from '../../transformer';
|
|
26
26
|
import { selectVersionIds } from './jats-versions';
|
|
27
27
|
import { buildTargets } from './labels';
|
|
@@ -119,9 +119,20 @@ export class JATSExporter {
|
|
|
119
119
|
};
|
|
120
120
|
};
|
|
121
121
|
};
|
|
122
|
+
this.nodesMap = new Map();
|
|
123
|
+
this.populateNodesMap = () => {
|
|
124
|
+
this.manuscriptNode.descendants((node) => {
|
|
125
|
+
var _a;
|
|
126
|
+
const type = node.type;
|
|
127
|
+
const nodes = (_a = this.nodesMap.get(type)) !== null && _a !== void 0 ? _a : [];
|
|
128
|
+
nodes.push(node);
|
|
129
|
+
this.nodesMap.set(type, nodes);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
122
132
|
this.serializeToJATS = async (manuscriptNode, options) => {
|
|
123
133
|
var _a;
|
|
124
134
|
this.manuscriptNode = manuscriptNode;
|
|
135
|
+
this.populateNodesMap();
|
|
125
136
|
this.generateCitationTexts(options.csl, manuscriptNode.attrs.id);
|
|
126
137
|
this.createSerializer();
|
|
127
138
|
const versionIds = selectVersionIds((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
|
|
@@ -261,13 +272,13 @@ export class JATSExporter {
|
|
|
261
272
|
articleMeta.appendChild(articleID);
|
|
262
273
|
}
|
|
263
274
|
const titleGroup = this.document.createElement('title-group');
|
|
264
|
-
const titleNode =
|
|
275
|
+
const titleNode = this.getFirstChildOfType(schema.nodes.title);
|
|
265
276
|
if (titleNode) {
|
|
266
277
|
const element = this.document.createElement('article-title');
|
|
267
278
|
this.setTitleContent(element, titleNode.textContent);
|
|
268
279
|
titleGroup.appendChild(element);
|
|
269
280
|
}
|
|
270
|
-
const altTitlesNodes =
|
|
281
|
+
const altTitlesNodes = this.getChildrenOfType(schema.nodes.alt_title);
|
|
271
282
|
altTitlesNodes.forEach((titleNode) => {
|
|
272
283
|
const element = this.document.createElement('alt-title');
|
|
273
284
|
element.setAttribute('alt-title-type', titleNode.attrs.type);
|
|
@@ -276,8 +287,8 @@ export class JATSExporter {
|
|
|
276
287
|
});
|
|
277
288
|
articleMeta.appendChild(titleGroup);
|
|
278
289
|
this.buildContributors(articleMeta);
|
|
279
|
-
const supplementsNodes =
|
|
280
|
-
supplementsNodes.forEach((
|
|
290
|
+
const supplementsNodes = this.getChildrenOfType(schema.nodes.supplement);
|
|
291
|
+
supplementsNodes.forEach((node) => {
|
|
281
292
|
var _a, _b, _c, _d;
|
|
282
293
|
const supplementaryMaterial = this.document.createElement('supplementary-material');
|
|
283
294
|
supplementaryMaterial.setAttribute('id', normalizeID(node.attrs.id));
|
|
@@ -322,13 +333,13 @@ export class JATSExporter {
|
|
|
322
333
|
}
|
|
323
334
|
this.buildKeywords(articleMeta);
|
|
324
335
|
let countingElements = [];
|
|
325
|
-
const figureCount =
|
|
336
|
+
const figureCount = this.getChildrenOfType(schema.nodes.figure).length;
|
|
326
337
|
countingElements.push(this.buildCountingElement('fig-count', figureCount));
|
|
327
|
-
const tableCount =
|
|
338
|
+
const tableCount = this.getChildrenOfType(schema.nodes.table).length;
|
|
328
339
|
countingElements.push(this.buildCountingElement('table-count', tableCount));
|
|
329
|
-
const equationCount =
|
|
340
|
+
const equationCount = this.getChildrenOfType(schema.nodes.equation_element).length;
|
|
330
341
|
countingElements.push(this.buildCountingElement('equation-count', equationCount));
|
|
331
|
-
const referencesCount =
|
|
342
|
+
const referencesCount = this.getChildrenOfType(schema.nodes.bibliography_item).length;
|
|
332
343
|
countingElements.push(this.buildCountingElement('ref-count', referencesCount));
|
|
333
344
|
const wordCount = this.manuscriptNode.textContent.split(/\s+/).length;
|
|
334
345
|
countingElements.push(this.buildCountingElement('word-count', wordCount));
|
|
@@ -341,7 +352,7 @@ export class JATSExporter {
|
|
|
341
352
|
if (!journalMeta.hasChildNodes()) {
|
|
342
353
|
journalMeta.remove();
|
|
343
354
|
}
|
|
344
|
-
const selfUriAttachments =
|
|
355
|
+
const selfUriAttachments = this.getChildrenOfType(schema.nodes.attachment);
|
|
345
356
|
selfUriAttachments.forEach((attachment) => {
|
|
346
357
|
const selfUriElement = this.document.createElement('self-uri');
|
|
347
358
|
selfUriElement.setAttribute('content-type', attachment.attrs.type);
|
|
@@ -408,7 +419,7 @@ export class JATSExporter {
|
|
|
408
419
|
refList = this.document.createElement('ref-list');
|
|
409
420
|
}
|
|
410
421
|
back.appendChild(refList);
|
|
411
|
-
const bibliographyItems =
|
|
422
|
+
const bibliographyItems = this.getChildrenOfType(schema.nodes.bibliography_item);
|
|
412
423
|
const [meta] = this.citationProvider.makeBibliography();
|
|
413
424
|
for (const [id] of meta.entry_ids) {
|
|
414
425
|
const bibliographyItem = bibliographyItems.find((n) => n.attrs.id === id);
|
|
@@ -797,11 +808,14 @@ export class JATSExporter {
|
|
|
797
808
|
placeholder_element: () => {
|
|
798
809
|
return this.document.createElement('boxed-text');
|
|
799
810
|
},
|
|
800
|
-
pullquote_element: () =>
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
0
|
|
804
|
-
|
|
811
|
+
pullquote_element: (node) => {
|
|
812
|
+
var _a;
|
|
813
|
+
let type = 'pullquote';
|
|
814
|
+
if (((_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.type) === schema.nodes.figure) {
|
|
815
|
+
type = 'quote-with-image';
|
|
816
|
+
}
|
|
817
|
+
return ['disp-quote', { 'content-type': type }, 0];
|
|
818
|
+
},
|
|
805
819
|
graphical_abstract_section: (node) => {
|
|
806
820
|
const attrs = {
|
|
807
821
|
id: normalizeID(node.attrs.id),
|
|
@@ -905,16 +919,14 @@ export class JATSExporter {
|
|
|
905
919
|
}
|
|
906
920
|
};
|
|
907
921
|
const appendChildNodeOfType = (element, node, type) => {
|
|
908
|
-
|
|
909
|
-
const childNode = (_a = findChildrenByType(node, type)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
922
|
+
const childNode = this.getFirstChildOfType(type, node);
|
|
910
923
|
if (childNode) {
|
|
911
924
|
element.appendChild(this.serializeNode(childNode));
|
|
912
925
|
}
|
|
913
926
|
};
|
|
914
927
|
const appendTable = (element, node) => {
|
|
915
|
-
|
|
916
|
-
const
|
|
917
|
-
const colGroupNode = (_b = findChildrenByType(node, node.type.schema.nodes.table_colgroup)[0]) === null || _b === void 0 ? void 0 : _b.node;
|
|
928
|
+
const tableNode = this.getFirstChildOfType(schema.nodes.table, node);
|
|
929
|
+
const colGroupNode = this.getFirstChildOfType(schema.nodes.table_colgroup, node);
|
|
918
930
|
if (!tableNode) {
|
|
919
931
|
return;
|
|
920
932
|
}
|
|
@@ -939,6 +951,13 @@ export class JATSExporter {
|
|
|
939
951
|
processChildNodes(element, node, node.type.schema.nodes.section);
|
|
940
952
|
return element;
|
|
941
953
|
};
|
|
954
|
+
const isChildOfNodeType = (targetID, type, descend = false) => {
|
|
955
|
+
const nodes = this.getChildrenOfType(type);
|
|
956
|
+
return nodes.some((node) => {
|
|
957
|
+
const result = findChildrenByAttr(node, (attrs) => attrs.id === targetID, descend)[0];
|
|
958
|
+
return !!result;
|
|
959
|
+
});
|
|
960
|
+
};
|
|
942
961
|
const createImage = (node) => {
|
|
943
962
|
const graphicNode = node.content.firstChild;
|
|
944
963
|
if (graphicNode) {
|
|
@@ -949,18 +968,19 @@ export class JATSExporter {
|
|
|
949
968
|
}
|
|
950
969
|
return '';
|
|
951
970
|
};
|
|
952
|
-
const createGraphic = (node
|
|
971
|
+
const createGraphic = (node) => {
|
|
953
972
|
const graphic = this.document.createElement('graphic');
|
|
954
973
|
graphic.setAttributeNS(XLINK_NAMESPACE, 'xlink:href', node.attrs.src);
|
|
955
|
-
if (!
|
|
974
|
+
if (!isChildOfNodeType(node.attrs.id, schema.nodes.figure_element) &&
|
|
975
|
+
node.attrs.type) {
|
|
956
976
|
graphic.setAttribute('content-type', node.attrs.type);
|
|
957
977
|
}
|
|
958
978
|
return graphic;
|
|
959
979
|
};
|
|
960
980
|
const createFigureElement = (node, contentNodeType) => {
|
|
961
981
|
const element = createElement(node, 'fig');
|
|
962
|
-
const figNode =
|
|
963
|
-
const figType = figNode === null || figNode === void 0 ? void 0 : figNode.
|
|
982
|
+
const figNode = this.getFirstChildOfType(schema.nodes.figure, node);
|
|
983
|
+
const figType = figNode === null || figNode === void 0 ? void 0 : figNode.attrs.type;
|
|
964
984
|
if (figType) {
|
|
965
985
|
element.setAttribute('fig-type', figType);
|
|
966
986
|
}
|
|
@@ -991,8 +1011,7 @@ export class JATSExporter {
|
|
|
991
1011
|
return element;
|
|
992
1012
|
};
|
|
993
1013
|
const processExecutableNode = (node, element) => {
|
|
994
|
-
|
|
995
|
-
const listingNode = (_a = findChildrenByType(node, node.type.schema.nodes.listing)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
1014
|
+
const listingNode = this.getFirstChildOfType(schema.nodes.listing, node);
|
|
996
1015
|
if (listingNode) {
|
|
997
1016
|
const { contents, languageKey } = listingNode.attrs;
|
|
998
1017
|
if (contents && languageKey) {
|
|
@@ -1021,7 +1040,7 @@ export class JATSExporter {
|
|
|
1021
1040
|
}
|
|
1022
1041
|
};
|
|
1023
1042
|
this.buildContributors = (articleMeta) => {
|
|
1024
|
-
const contributorNodes =
|
|
1043
|
+
const contributorNodes = this.getChildrenOfType(schema.nodes.contributor);
|
|
1025
1044
|
const authorContributorNodes = contributorNodes
|
|
1026
1045
|
.filter((n) => n.attrs.role === 'author')
|
|
1027
1046
|
.sort(sortContributors);
|
|
@@ -1155,8 +1174,8 @@ export class JATSExporter {
|
|
|
1155
1174
|
affiliationRIDs.push(...contributor.attrs.affiliations);
|
|
1156
1175
|
}
|
|
1157
1176
|
}
|
|
1158
|
-
const affiliations =
|
|
1159
|
-
if (affiliations) {
|
|
1177
|
+
const affiliations = this.getChildrenOfType(schema.nodes.affiliation);
|
|
1178
|
+
if (affiliations.length) {
|
|
1160
1179
|
const usedAffiliations = affiliations.filter((affiliation) => affiliationRIDs.includes(affiliation.attrs.id));
|
|
1161
1180
|
usedAffiliations.sort((a, b) => affiliationRIDs.indexOf(a.attrs.id) -
|
|
1162
1181
|
affiliationRIDs.indexOf(b.attrs.id));
|
|
@@ -1222,9 +1241,8 @@ export class JATSExporter {
|
|
|
1222
1241
|
}
|
|
1223
1242
|
};
|
|
1224
1243
|
this.createAuthorNotesElement = () => {
|
|
1225
|
-
var _a;
|
|
1226
1244
|
const authorNotesEl = this.document.createElement('author-notes');
|
|
1227
|
-
const authorNotesNode =
|
|
1245
|
+
const authorNotesNode = this.getFirstChildOfType(schema.nodes.author_notes);
|
|
1228
1246
|
if (authorNotesNode) {
|
|
1229
1247
|
this.appendModelsToAuthorNotes(authorNotesEl, authorNotesNode);
|
|
1230
1248
|
}
|
|
@@ -1386,9 +1404,8 @@ export class JATSExporter {
|
|
|
1386
1404
|
}
|
|
1387
1405
|
};
|
|
1388
1406
|
this.moveAbstracts = (front, body) => {
|
|
1389
|
-
var _a;
|
|
1390
1407
|
const container = body.querySelector(':scope > sec[sec-type="abstracts"]');
|
|
1391
|
-
const abstractsNode =
|
|
1408
|
+
const abstractsNode = this.getFirstChildOfType(schema.nodes.abstracts);
|
|
1392
1409
|
const abstractCategories = this.getAbstractCategories(abstractsNode);
|
|
1393
1410
|
const abstractSections = this.getAbstractSections(container, body, abstractCategories);
|
|
1394
1411
|
if (abstractSections.length) {
|
|
@@ -1523,6 +1540,15 @@ export class JATSExporter {
|
|
|
1523
1540
|
this.citationTexts.set(id, output);
|
|
1524
1541
|
});
|
|
1525
1542
|
}
|
|
1543
|
+
getFirstChildOfType(type, node) {
|
|
1544
|
+
return this.getChildrenOfType(type, node)[0];
|
|
1545
|
+
}
|
|
1546
|
+
getChildrenOfType(type, node) {
|
|
1547
|
+
const nodes = node
|
|
1548
|
+
? findChildrenByType(node, type).map(({ node }) => node)
|
|
1549
|
+
: this.nodesMap.get(type);
|
|
1550
|
+
return (nodes !== null && nodes !== void 0 ? nodes : []).filter((n) => isNodeOfType(n, type));
|
|
1551
|
+
}
|
|
1526
1552
|
createEquation(node, isInline = false) {
|
|
1527
1553
|
if (node.attrs.format === 'tex') {
|
|
1528
1554
|
const texMath = this.document.createElement('tex-math');
|
|
@@ -1546,7 +1572,7 @@ export class JATSExporter {
|
|
|
1546
1572
|
}
|
|
1547
1573
|
}
|
|
1548
1574
|
appendModelsToAuthorNotes(authorNotesEl, authorNotesNode) {
|
|
1549
|
-
const contributorsNodes =
|
|
1575
|
+
const contributorsNodes = this.getChildrenOfType(schema.nodes.contributor);
|
|
1550
1576
|
const usedCorrespondings = this.getUsedCorrespondings(contributorsNodes);
|
|
1551
1577
|
authorNotesNode.descendants((node) => {
|
|
1552
1578
|
switch (node.type) {
|
|
@@ -1575,7 +1601,7 @@ export class JATSExporter {
|
|
|
1575
1601
|
.filter((corresp) => !!corresp);
|
|
1576
1602
|
}
|
|
1577
1603
|
buildKeywords(articleMeta) {
|
|
1578
|
-
const keywordGroups =
|
|
1604
|
+
const keywordGroups = this.getChildrenOfType(schema.nodes.keyword_group);
|
|
1579
1605
|
keywordGroups.forEach((group) => {
|
|
1580
1606
|
const kwdGroup = this.document.createElement('kwd-group');
|
|
1581
1607
|
if (group.attrs.type) {
|
package/dist/es/schema/types.js
CHANGED
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0.
|
|
1
|
+
export const VERSION = "3.0.52";
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { BibliographyItem, Journal } from '@manuscripts/json-schema';
|
|
17
17
|
import { CitationProvider } from '@manuscripts/library';
|
|
18
|
-
import { DOMSerializer } from 'prosemirror-model';
|
|
18
|
+
import { type NodeType, DOMSerializer } from 'prosemirror-model';
|
|
19
19
|
import { CitationNode, ManuscriptNode } from '../../schema';
|
|
20
20
|
import { IDGenerator } from '../types';
|
|
21
21
|
import { Version } from './jats-versions';
|
|
@@ -60,6 +60,10 @@ export declare class JATSExporter {
|
|
|
60
60
|
}[];
|
|
61
61
|
protected getLibraryItem: (manuscriptID: string) => (id: string) => BibliographyItem | undefined;
|
|
62
62
|
protected generateCitationTexts(csl: CSLOptions, manuscriptID: string): void;
|
|
63
|
+
private nodesMap;
|
|
64
|
+
private populateNodesMap;
|
|
65
|
+
protected getFirstChildOfType<T extends ManuscriptNode>(type: NodeType, node?: ManuscriptNode): T | undefined;
|
|
66
|
+
protected getChildrenOfType<T extends ManuscriptNode>(type: NodeType, node?: ManuscriptNode): T[];
|
|
63
67
|
serializeToJATS: (manuscriptNode: ManuscriptNode, options: ExportOptions) => Promise<string>;
|
|
64
68
|
private nodeFromJATS;
|
|
65
69
|
protected rewriteIDs: (generator?: IDGenerator) => Promise<void>;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "3.0.
|
|
1
|
+
export declare const VERSION = "3.0.52";
|
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.
|
|
4
|
+
"version": "3.0.52",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|