@manuscripts/transform 3.0.69 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/jats/exporter/citeproc.js +164 -0
- package/dist/cjs/jats/exporter/jats-exporter.js +70 -196
- package/dist/cjs/jats/importer/jats-dom-parser.js +48 -62
- package/dist/cjs/lib/citeproc.js +13 -0
- package/dist/cjs/schema/index.js +1 -0
- package/dist/cjs/schema/nodes/bibliography_element.js +3 -1
- package/dist/cjs/schema/nodes/bibliography_item.js +3 -7
- package/dist/cjs/schema/nodes/comment.js +3 -1
- package/dist/cjs/schema/nodes/list.js +3 -45
- package/dist/cjs/version.js +1 -1
- package/dist/es/index.js +1 -1
- package/dist/es/jats/exporter/citeproc.js +156 -0
- package/dist/es/jats/exporter/jats-exporter.js +48 -196
- package/dist/es/jats/importer/jats-dom-parser.js +49 -63
- package/dist/es/lib/citeproc.js +9 -0
- package/dist/es/schema/index.js +1 -0
- package/dist/es/schema/nodes/bibliography_element.js +1 -0
- package/dist/es/schema/nodes/bibliography_item.js +1 -6
- package/dist/es/schema/nodes/comment.js +1 -0
- package/dist/es/schema/nodes/list.js +2 -42
- package/dist/es/version.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jats/exporter/citeproc.d.ts +18 -0
- package/dist/types/jats/exporter/jats-exporter.d.ts +5 -29
- package/dist/types/jats/importer/jats-dom-parser.d.ts +2 -2
- package/dist/types/lib/citeproc.d.ts +3 -0
- package/dist/types/schema/index.d.ts +1 -0
- package/dist/types/schema/nodes/bibliography_element.d.ts +1 -0
- package/dist/types/schema/nodes/bibliography_item.d.ts +9 -9
- package/dist/types/schema/nodes/citation.d.ts +3 -4
- package/dist/types/schema/nodes/comment.d.ts +3 -3
- package/dist/types/schema/nodes/list.d.ts +5 -11
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -6
|
@@ -13,26 +13,19 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import
|
|
17
|
-
import { CitationProvider } from '@manuscripts/library';
|
|
18
|
-
import debug from 'debug';
|
|
16
|
+
import * as Citeproc from 'citeproc';
|
|
19
17
|
import { DOMParser as ProsemirrorDOMParser, DOMSerializer, } from 'prosemirror-model';
|
|
20
18
|
import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils';
|
|
21
19
|
import serializeToXML from 'w3c-xmlserializer';
|
|
20
|
+
import { buildCiteprocCitation } from '../../lib/citeproc';
|
|
22
21
|
import { CRediTRoleUrls } from '../../lib/credit-roles';
|
|
23
22
|
import { generateFootnoteLabels } from '../../lib/footnotes';
|
|
24
|
-
import { nodeFromHTML
|
|
25
|
-
import { isCitationNode, isNodeOfType, schema, } from '../../schema';
|
|
23
|
+
import { nodeFromHTML } from '../../lib/html';
|
|
24
|
+
import { isBibliographyItemNode, isCitationNode, isNodeOfType, schema, } from '../../schema';
|
|
26
25
|
import { isExecutableNodeType, isNodeType } from '../../transformer';
|
|
26
|
+
import { initJats, jatsVariableWrapper } from './citeproc';
|
|
27
27
|
import { selectVersionIds } from './jats-versions';
|
|
28
28
|
import { buildTargets } from './labels';
|
|
29
|
-
const publicationTypeToJats = {
|
|
30
|
-
article: 'journal',
|
|
31
|
-
'article-journal': 'journal',
|
|
32
|
-
webpage: 'web',
|
|
33
|
-
dataset: 'data',
|
|
34
|
-
};
|
|
35
|
-
const warn = debug('manuscripts-transform');
|
|
36
29
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
37
30
|
const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
38
31
|
const normalizeID = (id) => id.replace(/:/g, '_');
|
|
@@ -86,27 +79,8 @@ const chooseRefType = (type) => {
|
|
|
86
79
|
}
|
|
87
80
|
};
|
|
88
81
|
const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
|
|
89
|
-
export const buildCitations = (citations) => citations.map((citation) => ({
|
|
90
|
-
citationID: citation.attrs.id,
|
|
91
|
-
citationItems: citation.attrs.rids.map((rid) => ({
|
|
92
|
-
id: rid,
|
|
93
|
-
})),
|
|
94
|
-
properties: {
|
|
95
|
-
noteIndex: 0,
|
|
96
|
-
},
|
|
97
|
-
}));
|
|
98
82
|
export class JATSExporter {
|
|
99
83
|
constructor() {
|
|
100
|
-
this.getLibraryItem = (manuscriptID) => {
|
|
101
|
-
return (id) => {
|
|
102
|
-
var _a;
|
|
103
|
-
const node = (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
104
|
-
if (!node) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
return Object.assign(Object.assign({}, node.attrs), { _id: node.attrs.id, manuscriptID, objectType: ObjectTypes.BibliographyItem });
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
84
|
this.nodesMap = new Map();
|
|
111
85
|
this.populateNodesMap = () => {
|
|
112
86
|
this.manuscriptNode.descendants((node) => {
|
|
@@ -121,7 +95,7 @@ export class JATSExporter {
|
|
|
121
95
|
var _a;
|
|
122
96
|
this.manuscriptNode = manuscriptNode;
|
|
123
97
|
this.populateNodesMap();
|
|
124
|
-
this.
|
|
98
|
+
this.initCiteprocEngine(options.csl);
|
|
125
99
|
this.createSerializer();
|
|
126
100
|
const versionIds = selectVersionIds((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
|
|
127
101
|
this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
|
|
@@ -148,6 +122,34 @@ export class JATSExporter {
|
|
|
148
122
|
await this.rewriteIDs();
|
|
149
123
|
return serializeToXML(this.document);
|
|
150
124
|
};
|
|
125
|
+
this.initCiteprocEngine = (csl) => {
|
|
126
|
+
const bibitems = new Map();
|
|
127
|
+
const citations = new Map();
|
|
128
|
+
this.manuscriptNode.descendants((n) => {
|
|
129
|
+
if (isBibliographyItemNode(n)) {
|
|
130
|
+
bibitems.set(n.attrs.id, n.attrs);
|
|
131
|
+
}
|
|
132
|
+
if (isCitationNode(n)) {
|
|
133
|
+
citations.set(n.attrs.id, buildCiteprocCitation(n.attrs));
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
initJats();
|
|
137
|
+
const engine = new Citeproc.Engine({
|
|
138
|
+
retrieveLocale: () => csl.locale,
|
|
139
|
+
retrieveItem: (id) => {
|
|
140
|
+
const item = bibitems.get(id);
|
|
141
|
+
if (!item) {
|
|
142
|
+
throw Error(`Missing bibliography item with id ${id}`);
|
|
143
|
+
}
|
|
144
|
+
return item;
|
|
145
|
+
},
|
|
146
|
+
variableWrapper: jatsVariableWrapper,
|
|
147
|
+
}, csl.style);
|
|
148
|
+
engine.setOutputFormat('jats');
|
|
149
|
+
const output = engine.rebuildProcessorState([...citations.values()]);
|
|
150
|
+
this.engine = engine;
|
|
151
|
+
this.renderedCitations = new Map(output.map((i) => [i[0], i[2]]));
|
|
152
|
+
};
|
|
151
153
|
this.nodeFromJATS = (JATSFragment) => {
|
|
152
154
|
JATSFragment = JATSFragment.trim();
|
|
153
155
|
JATSFragment = JATSFragment.replace(' ', ' ');
|
|
@@ -402,139 +404,20 @@ export class JATSExporter {
|
|
|
402
404
|
}
|
|
403
405
|
let refList = this.document.querySelector('ref-list');
|
|
404
406
|
if (!refList) {
|
|
405
|
-
warn('No bibliography element, creating a ref-list anyway');
|
|
406
407
|
refList = this.createElement('ref-list');
|
|
407
408
|
}
|
|
408
409
|
back.appendChild(refList);
|
|
409
|
-
const
|
|
410
|
-
const [
|
|
411
|
-
for (
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
410
|
+
const parser = new DOMParser();
|
|
411
|
+
const [_, bibliography] = this.engine.makeBibliography();
|
|
412
|
+
for (let i = 0; i < bibliography.length; i++) {
|
|
413
|
+
const item = `<template xmlns:xlink="${XLINK_NAMESPACE}">${bibliography[i]}</template>`;
|
|
414
|
+
const ref = parser.parseFromString(item, 'text/xml').querySelector('ref');
|
|
415
|
+
if (ref) {
|
|
416
|
+
refList.appendChild(ref);
|
|
415
417
|
}
|
|
416
|
-
const ref = this.createElement('ref');
|
|
417
|
-
ref.setAttribute('id', normalizeID(id));
|
|
418
|
-
const getPublicationType = (pubType) => publicationTypeToJats[pubType !== null && pubType !== void 0 ? pubType : ''] || pubType || 'journal';
|
|
419
|
-
if (bibliographyItem.attrs.literal) {
|
|
420
|
-
this.appendElement(ref, 'mixed-citation', bibliographyItem.attrs.literal, {
|
|
421
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
const citation = this.appendElement(ref, 'element-citation', undefined, {
|
|
426
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
427
|
-
});
|
|
428
|
-
const attributeHandlers = {
|
|
429
|
-
author: (v) => this.processRefPersonGroup(citation, 'author', v),
|
|
430
|
-
editor: (v) => this.processRefPersonGroup(citation, 'editor', v),
|
|
431
|
-
title: (v) => this.setTitleContent(this.appendElement(citation, 'article-title'), v),
|
|
432
|
-
comment: (v) => this.appendElement(citation, 'comment', v),
|
|
433
|
-
'container-title': (v) => this.setTitleContent(this.appendElement(citation, 'source'), v),
|
|
434
|
-
issued: ({ 'date-parts': parts }) => this.processDateParts(citation, parts),
|
|
435
|
-
volume: (v) => this.appendElement(citation, 'volume', v),
|
|
436
|
-
issue: (v) => this.appendElement(citation, 'issue', v),
|
|
437
|
-
supplement: (v) => this.appendElement(citation, 'supplement', v),
|
|
438
|
-
page: (v) => this.processPageString(citation, String(v)),
|
|
439
|
-
DOI: (v) => this.appendElement(citation, 'pub-id', v, { 'pub-id-type': 'doi' }),
|
|
440
|
-
std: (v) => this.appendElement(citation, 'pub-id', v, {
|
|
441
|
-
'pub-id-type': 'std-designation',
|
|
442
|
-
}),
|
|
443
|
-
'collection-title': (v) => this.appendElement(citation, 'series', v),
|
|
444
|
-
edition: (v) => this.appendElement(citation, 'edition', v),
|
|
445
|
-
'publisher-place': (v) => this.appendElement(citation, 'publisher-loc', v),
|
|
446
|
-
publisher: (v) => this.appendElement(citation, 'publisher-name', v),
|
|
447
|
-
event: (v) => this.appendElement(citation, 'conf-name', v),
|
|
448
|
-
'event-place': (v) => this.appendElement(citation, 'conf-loc', v),
|
|
449
|
-
'number-of-pages': (v) => this.appendElement(citation, 'size', v, { units: 'pages' }),
|
|
450
|
-
institution: (v) => this.appendElement(citation, 'institution', v),
|
|
451
|
-
locator: (v) => this.appendElement(citation, 'elocation-id', v),
|
|
452
|
-
URL: (v) => this.appendElement(citation, 'ext-link', v, {
|
|
453
|
-
'ext-link-type': 'uri',
|
|
454
|
-
}),
|
|
455
|
-
'event-date': (v) => this.processDate(citation, 'conf-date', v),
|
|
456
|
-
accessed: (v) => this.processDate(citation, 'date-in-citation', v),
|
|
457
|
-
};
|
|
458
|
-
Object.entries(attributeHandlers).forEach(([key, handler]) => {
|
|
459
|
-
const value = bibliographyItem.attrs[key];
|
|
460
|
-
if (value) {
|
|
461
|
-
handler(value);
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
refList.appendChild(ref);
|
|
466
418
|
}
|
|
467
419
|
return back;
|
|
468
420
|
};
|
|
469
|
-
this.processDateParts = (parent, dateParts) => {
|
|
470
|
-
const [[year, month, day]] = dateParts;
|
|
471
|
-
if (year) {
|
|
472
|
-
this.appendElement(parent, 'year', String(year));
|
|
473
|
-
}
|
|
474
|
-
if (month) {
|
|
475
|
-
this.appendElement(parent, 'month', String(month));
|
|
476
|
-
}
|
|
477
|
-
if (day) {
|
|
478
|
-
this.appendElement(parent, 'day', String(day));
|
|
479
|
-
}
|
|
480
|
-
};
|
|
481
|
-
this.processPageString = (parent, page) => {
|
|
482
|
-
const numPattern = /^\d+$/;
|
|
483
|
-
const rangePattern = /^(\d+)-(\d+)$/;
|
|
484
|
-
if (numPattern.test(page)) {
|
|
485
|
-
this.appendElement(parent, 'fpage', page);
|
|
486
|
-
}
|
|
487
|
-
else if (rangePattern.test(page)) {
|
|
488
|
-
const [fpage, lpage] = page.split('-');
|
|
489
|
-
this.appendElement(parent, 'fpage', fpage);
|
|
490
|
-
this.appendElement(parent, 'lpage', lpage);
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
this.appendElement(parent, 'page-range', page);
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
this.processDate = (parent, tag, date) => {
|
|
497
|
-
const buildISODate = (date) => {
|
|
498
|
-
const dateParts = date['date-parts'];
|
|
499
|
-
if (dateParts && dateParts.length) {
|
|
500
|
-
const [[year, month, day]] = dateParts;
|
|
501
|
-
if (year && month && day) {
|
|
502
|
-
return new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
const isoDate = buildISODate(date);
|
|
507
|
-
if (!isoDate) {
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
return this.appendElement(parent, tag, isoDate.toDateString(), {
|
|
511
|
-
'iso-8601-date': isoDate.toISOString(),
|
|
512
|
-
});
|
|
513
|
-
};
|
|
514
|
-
this.processRefPersonGroup = (citation, type, people) => {
|
|
515
|
-
if (!(people === null || people === void 0 ? void 0 : people.length)) {
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
const group = this.appendElement(citation, 'person-group', undefined, {
|
|
519
|
-
'person-group-type': type,
|
|
520
|
-
});
|
|
521
|
-
people.forEach((person) => {
|
|
522
|
-
if (person.literal) {
|
|
523
|
-
this.appendElement(group, 'collab', person.literal);
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const name = this.createElement('string-name');
|
|
527
|
-
if (person.family) {
|
|
528
|
-
this.appendElement(name, 'surname', person.family);
|
|
529
|
-
}
|
|
530
|
-
if (person.given) {
|
|
531
|
-
this.appendElement(name, 'given-names', person.given);
|
|
532
|
-
}
|
|
533
|
-
if (name.childNodes.length) {
|
|
534
|
-
group.appendChild(name);
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
};
|
|
538
421
|
this.createElement = (tag, content, attrs) => {
|
|
539
422
|
const el = this.document.createElement(tag);
|
|
540
423
|
if (content) {
|
|
@@ -668,35 +551,30 @@ export class JATSExporter {
|
|
|
668
551
|
const xref = this.createElement('xref');
|
|
669
552
|
xref.setAttribute('ref-type', 'bibr');
|
|
670
553
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
671
|
-
const
|
|
672
|
-
if (
|
|
673
|
-
|
|
554
|
+
const fragment = this.renderedCitations.get(node.attrs.id);
|
|
555
|
+
if (fragment) {
|
|
556
|
+
xref.innerHTML = fragment;
|
|
674
557
|
}
|
|
675
|
-
xref.textContent = textFromHTML(citationTextContent);
|
|
676
558
|
return xref;
|
|
677
559
|
},
|
|
678
560
|
cross_reference: (node) => {
|
|
679
|
-
var _a, _b, _c;
|
|
561
|
+
var _a, _b, _c, _d;
|
|
680
562
|
const cross = node;
|
|
681
563
|
const rids = cross.attrs.rids;
|
|
682
564
|
if (!rids.length) {
|
|
683
565
|
return (_a = cross.attrs.label) !== null && _a !== void 0 ? _a : '';
|
|
684
566
|
}
|
|
685
567
|
const rid = rids[0];
|
|
686
|
-
const text = cross.attrs.label
|
|
687
|
-
const target = (
|
|
568
|
+
const text = (_b = cross.attrs.label) !== null && _b !== void 0 ? _b : (_c = this.labelTargets.get(rid)) === null || _c === void 0 ? void 0 : _c.label;
|
|
569
|
+
const target = (_d = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _d === void 0 ? void 0 : _d.node;
|
|
688
570
|
if (!target) {
|
|
689
|
-
|
|
690
|
-
return text || '';
|
|
571
|
+
return text !== null && text !== void 0 ? text : '';
|
|
691
572
|
}
|
|
692
573
|
const xref = this.createElement('xref');
|
|
693
574
|
const type = chooseRefType(target.type);
|
|
694
575
|
if (type) {
|
|
695
576
|
xref.setAttribute('ref-type', type);
|
|
696
577
|
}
|
|
697
|
-
else {
|
|
698
|
-
warn(`Unset ref-type for schema type ${target.type.name}`);
|
|
699
|
-
}
|
|
700
578
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
701
579
|
xref.textContent = text !== null && text !== void 0 ? text : '';
|
|
702
580
|
return xref;
|
|
@@ -1086,7 +964,6 @@ export class JATSExporter {
|
|
|
1086
964
|
this.validateContributor(contributor);
|
|
1087
965
|
}
|
|
1088
966
|
catch (error) {
|
|
1089
|
-
warn(error.message);
|
|
1090
967
|
return;
|
|
1091
968
|
}
|
|
1092
969
|
const contrib = this.createElement('contrib');
|
|
@@ -1363,10 +1240,6 @@ export class JATSExporter {
|
|
|
1363
1240
|
if (!container) {
|
|
1364
1241
|
return;
|
|
1365
1242
|
}
|
|
1366
|
-
const isContainerEmpty = container.children.length === 0;
|
|
1367
|
-
if (!isContainerEmpty) {
|
|
1368
|
-
warn('Backmatter section is not empty.');
|
|
1369
|
-
}
|
|
1370
1243
|
body.removeChild(container);
|
|
1371
1244
|
};
|
|
1372
1245
|
this.moveAwards = (front, body) => {
|
|
@@ -1510,27 +1383,6 @@ export class JATSExporter {
|
|
|
1510
1383
|
return name;
|
|
1511
1384
|
};
|
|
1512
1385
|
}
|
|
1513
|
-
generateCitations() {
|
|
1514
|
-
const nodes = [];
|
|
1515
|
-
this.manuscriptNode.descendants((node) => {
|
|
1516
|
-
if (isCitationNode(node)) {
|
|
1517
|
-
nodes.push(node);
|
|
1518
|
-
}
|
|
1519
|
-
});
|
|
1520
|
-
return buildCitations(nodes);
|
|
1521
|
-
}
|
|
1522
|
-
generateCitationTexts(csl, manuscriptID) {
|
|
1523
|
-
this.citationTexts = new Map();
|
|
1524
|
-
this.citationProvider = new CitationProvider({
|
|
1525
|
-
getLibraryItem: this.getLibraryItem(manuscriptID),
|
|
1526
|
-
locale: csl.locale,
|
|
1527
|
-
citationStyle: csl.style,
|
|
1528
|
-
});
|
|
1529
|
-
const citations = this.generateCitations();
|
|
1530
|
-
this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
|
|
1531
|
-
this.citationTexts.set(id, output);
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
1386
|
getFirstChildOfType(type, node) {
|
|
1535
1387
|
return this.getChildrenOfType(type, node)[0];
|
|
1536
1388
|
}
|
|
@@ -13,10 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import {
|
|
16
|
+
import { buildContribution, ObjectTypes } from '@manuscripts/json-schema';
|
|
17
17
|
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
18
18
|
import { dateToTimestamp, getCRediTRoleRole, getHTMLContent, getTrimmedTextContent, } from '../../lib/utils';
|
|
19
|
-
import { publicationTypeToPM, } from '../../schema';
|
|
20
19
|
import { DEFAULT_PROFILE_ID } from './jats-comments';
|
|
21
20
|
export class JATSDOMParser {
|
|
22
21
|
constructor(sectionCategories, schema) {
|
|
@@ -128,11 +127,22 @@ export class JATSDOMParser {
|
|
|
128
127
|
this.getAddressLine = (element, index) => {
|
|
129
128
|
return (getTrimmedTextContent(element, `addr-line:nth-of-type(${index})`) || '');
|
|
130
129
|
};
|
|
131
|
-
this.
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
this.getRefType = (element) => {
|
|
131
|
+
const citation = element.querySelector('element-citation, mixed-citation');
|
|
132
|
+
const type = citation === null || citation === void 0 ? void 0 : citation.getAttribute('publication-type');
|
|
133
|
+
if (!type) {
|
|
134
|
+
return 'article-journal';
|
|
135
|
+
}
|
|
136
|
+
switch (type) {
|
|
137
|
+
case 'journal':
|
|
138
|
+
return 'article-journal';
|
|
139
|
+
case 'web':
|
|
140
|
+
return 'webpage';
|
|
141
|
+
case 'data':
|
|
142
|
+
return 'dataset';
|
|
143
|
+
default:
|
|
144
|
+
return type;
|
|
145
|
+
}
|
|
136
146
|
};
|
|
137
147
|
this.getFigContent = (node) => {
|
|
138
148
|
const element = node;
|
|
@@ -151,18 +161,6 @@ export class JATSDOMParser {
|
|
|
151
161
|
}
|
|
152
162
|
return Fragment.from(content);
|
|
153
163
|
};
|
|
154
|
-
this.parseRefLiteral = (element) => {
|
|
155
|
-
var _a;
|
|
156
|
-
const mixedCitation = element.querySelector('mixed-citation');
|
|
157
|
-
const hasDirectTextNodeWithLetters = Array.from((_a = mixedCitation === null || mixedCitation === void 0 ? void 0 : mixedCitation.childNodes) !== null && _a !== void 0 ? _a : []).some((node) => {
|
|
158
|
-
var _a;
|
|
159
|
-
return node.nodeType === Node.TEXT_NODE &&
|
|
160
|
-
((_a = node.textContent) === null || _a === void 0 ? void 0 : _a.match(/[A-Za-z]+/g));
|
|
161
|
-
});
|
|
162
|
-
if (hasDirectTextNodeWithLetters) {
|
|
163
|
-
return getTrimmedTextContent(mixedCitation);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
164
|
this.parseRefPages = (element) => {
|
|
167
165
|
const fpage = getTrimmedTextContent(element, 'fpage');
|
|
168
166
|
const lpage = getTrimmedTextContent(element, 'lpage');
|
|
@@ -171,10 +169,9 @@ export class JATSDOMParser {
|
|
|
171
169
|
}
|
|
172
170
|
};
|
|
173
171
|
this.parseRef = (element) => {
|
|
174
|
-
var _a, _b;
|
|
175
172
|
return {
|
|
176
173
|
id: element.id,
|
|
177
|
-
type: this.
|
|
174
|
+
type: this.getRefType(element),
|
|
178
175
|
comment: getTrimmedTextContent(element, 'comment'),
|
|
179
176
|
volume: getTrimmedTextContent(element, 'volume'),
|
|
180
177
|
issue: getTrimmedTextContent(element, 'issue'),
|
|
@@ -192,23 +189,13 @@ export class JATSDOMParser {
|
|
|
192
189
|
institution: getTrimmedTextContent(element, 'institution'),
|
|
193
190
|
locator: getTrimmedTextContent(element, 'elocation-id'),
|
|
194
191
|
'container-title': getHTMLContent(element, 'source'),
|
|
195
|
-
title:
|
|
196
|
-
author: this.getNameContent(element, '
|
|
197
|
-
editor: this.getNameContent(element, '
|
|
198
|
-
literal:
|
|
192
|
+
title: getHTMLContent(element, 'article-title, data-title, part-title'),
|
|
193
|
+
author: this.getNameContent(element, 'author'),
|
|
194
|
+
editor: this.getNameContent(element, 'editor'),
|
|
195
|
+
literal: getTrimmedTextContent(element, 'mixed-citation'),
|
|
199
196
|
accessed: this.getDateContent(element, 'date-in-citation'),
|
|
200
197
|
'event-date': this.getDateContent(element, 'conf-date'),
|
|
201
|
-
issued:
|
|
202
|
-
? buildBibliographicDate({
|
|
203
|
-
'date-parts': [
|
|
204
|
-
[
|
|
205
|
-
getTrimmedTextContent(element.querySelector('element-citation, mixed-citation'), ':scope > year') || '',
|
|
206
|
-
getTrimmedTextContent(element.querySelector('element-citation, mixed-citation'), ':scope > month') || '',
|
|
207
|
-
getTrimmedTextContent(element.querySelector('element-citation, mixed-citation'), ':scope > day') || '',
|
|
208
|
-
],
|
|
209
|
-
],
|
|
210
|
-
})
|
|
211
|
-
: undefined,
|
|
198
|
+
issued: this.getIssuedDateContent(element),
|
|
212
199
|
page: this.parseRefPages(element),
|
|
213
200
|
};
|
|
214
201
|
};
|
|
@@ -1072,30 +1059,22 @@ export class JATSDOMParser {
|
|
|
1072
1059
|
}
|
|
1073
1060
|
}
|
|
1074
1061
|
}
|
|
1075
|
-
getNameContent(element,
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
if (given) {
|
|
1081
|
-
name.given = given;
|
|
1082
|
-
}
|
|
1083
|
-
if (family) {
|
|
1084
|
-
name.family = family;
|
|
1085
|
-
}
|
|
1086
|
-
if (node.nodeName === 'collab') {
|
|
1087
|
-
name.literal = getTrimmedTextContent(node);
|
|
1088
|
-
}
|
|
1089
|
-
return name;
|
|
1090
|
-
};
|
|
1091
|
-
const personNodes = element.querySelectorAll(query);
|
|
1092
|
-
if (personNodes.length) {
|
|
1093
|
-
return Array.from(personNodes).map(buildName);
|
|
1062
|
+
getNameContent(element, type) {
|
|
1063
|
+
const query = `person-group[person-group-type="${type}"] > *`;
|
|
1064
|
+
const groups = [...element.querySelectorAll(query)];
|
|
1065
|
+
if (!groups.length) {
|
|
1066
|
+
return;
|
|
1094
1067
|
}
|
|
1068
|
+
return groups.map((node) => ({
|
|
1069
|
+
given: getTrimmedTextContent(node, 'given-names'),
|
|
1070
|
+
family: getTrimmedTextContent(node, 'surname'),
|
|
1071
|
+
literal: node.nodeName === 'collab' ? getTrimmedTextContent(node) : undefined,
|
|
1072
|
+
}));
|
|
1095
1073
|
}
|
|
1096
1074
|
getDateContent(element, query) {
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1075
|
+
const date = element.querySelector(query);
|
|
1076
|
+
if (date) {
|
|
1077
|
+
const isoDate = date.getAttribute('iso-8601-date');
|
|
1099
1078
|
if (!isoDate) {
|
|
1100
1079
|
return;
|
|
1101
1080
|
}
|
|
@@ -1105,13 +1084,20 @@ export class JATSDOMParser {
|
|
|
1105
1084
|
parsedDate.getMonth() + 1,
|
|
1106
1085
|
parsedDate.getDate(),
|
|
1107
1086
|
];
|
|
1108
|
-
return
|
|
1087
|
+
return {
|
|
1109
1088
|
'date-parts': [parts],
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
getIssuedDateContent(element) {
|
|
1093
|
+
const year = getTrimmedTextContent(element, ':scope > * > year');
|
|
1094
|
+
if (!year) {
|
|
1095
|
+
return;
|
|
1115
1096
|
}
|
|
1097
|
+
const month = getTrimmedTextContent(element, ':scope > * > month');
|
|
1098
|
+
const day = getTrimmedTextContent(element, ':scope > * > day');
|
|
1099
|
+
return {
|
|
1100
|
+
'date-parts': [[year, month !== null && month !== void 0 ? month : '', day !== null && day !== void 0 ? day : '']],
|
|
1101
|
+
};
|
|
1116
1102
|
}
|
|
1117
1103
|
}
|
package/dist/es/schema/index.js
CHANGED
|
@@ -143,6 +143,7 @@ export * from './nodes/placeholder_element';
|
|
|
143
143
|
export * from './nodes/pullquote_element';
|
|
144
144
|
export * from './nodes/section';
|
|
145
145
|
export * from './nodes/section_title';
|
|
146
|
+
export * from './nodes/section_label';
|
|
146
147
|
export * from './nodes/supplement';
|
|
147
148
|
export * from './nodes/supplements';
|
|
148
149
|
export * from './nodes/table';
|
|
@@ -13,12 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export const publicationTypeToPM = {
|
|
17
|
-
journal: 'article-journal',
|
|
18
|
-
web: 'webpage',
|
|
19
|
-
data: 'dataset',
|
|
20
|
-
preprint: 'article-journal',
|
|
21
|
-
};
|
|
22
16
|
export const bibliographyItem = {
|
|
23
17
|
content: 'inline{0}',
|
|
24
18
|
attrs: {
|
|
@@ -55,3 +49,4 @@ export const bibliographyItem = {
|
|
|
55
49
|
selectable: false,
|
|
56
50
|
group: 'block',
|
|
57
51
|
};
|
|
52
|
+
export const isBibliographyItemNode = (node) => node.type === node.type.schema.nodes.bibliography_item;
|
|
@@ -1,50 +1,11 @@
|
|
|
1
1
|
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
2
|
-
export const getJatsListType = (cssStyle) => {
|
|
3
|
-
switch (cssStyle) {
|
|
4
|
-
case 'disc':
|
|
5
|
-
return 'bullet';
|
|
6
|
-
case 'decimal':
|
|
7
|
-
return 'order';
|
|
8
|
-
case 'lower-alpha':
|
|
9
|
-
return 'alpha-lower';
|
|
10
|
-
case 'upper-alpha':
|
|
11
|
-
return 'alpha-upper';
|
|
12
|
-
case 'lower-roman':
|
|
13
|
-
return 'roman-lower';
|
|
14
|
-
case 'upper-roman':
|
|
15
|
-
return 'roman-upper';
|
|
16
|
-
case 'simple':
|
|
17
|
-
return 'none';
|
|
18
|
-
default:
|
|
19
|
-
return 'none';
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
export const getListType = (style) => {
|
|
23
|
-
switch (style) {
|
|
24
|
-
case 'bullet':
|
|
25
|
-
return { type: 'ul', style: 'disc' };
|
|
26
|
-
case 'order':
|
|
27
|
-
return { type: 'ul', style: 'decimal' };
|
|
28
|
-
case 'alpha-lower':
|
|
29
|
-
return { type: 'ul', style: 'lower-alpha' };
|
|
30
|
-
case 'alpha-upper':
|
|
31
|
-
return { type: 'ul', style: 'upper-alpha' };
|
|
32
|
-
case 'roman-lower':
|
|
33
|
-
return { type: 'ul', style: 'lower-roman' };
|
|
34
|
-
case 'roman-upper':
|
|
35
|
-
return { type: 'ul', style: 'upper-roman' };
|
|
36
|
-
case 'simple':
|
|
37
|
-
default:
|
|
38
|
-
return { type: 'ul', style: 'none' };
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
2
|
export const list = {
|
|
42
3
|
content: 'list_item+',
|
|
43
4
|
group: 'block list element',
|
|
44
5
|
attrs: {
|
|
45
6
|
id: { default: '' },
|
|
46
|
-
dataTracked: { default: null },
|
|
47
7
|
listStyleType: { default: null },
|
|
8
|
+
dataTracked: { default: null },
|
|
48
9
|
},
|
|
49
10
|
parseDOM: [
|
|
50
11
|
{
|
|
@@ -70,9 +31,8 @@ export const list = {
|
|
|
70
31
|
],
|
|
71
32
|
toDOM: (node) => {
|
|
72
33
|
const list = node;
|
|
73
|
-
const { type } = getListType(list.attrs.listStyleType);
|
|
74
34
|
return [
|
|
75
|
-
|
|
35
|
+
'ul',
|
|
76
36
|
{
|
|
77
37
|
id: list.attrs.id,
|
|
78
38
|
'list-type': list.attrs.listStyleType,
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "3.0
|
|
1
|
+
export const VERSION = "3.1.0";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export * from './jats/types';
|
|
|
5
5
|
export * from './lib/footnotes';
|
|
6
6
|
export * from './lib/utils';
|
|
7
7
|
export * from './lib/section-categories';
|
|
8
|
+
export * from './lib/citeproc';
|
|
8
9
|
export * from './schema';
|
|
9
10
|
export { migrateFor } from './schema/migration/migrate';
|
|
10
|
-
export { isSectionLabelNode } from './schema/nodes/section_label';
|
|
11
11
|
export * from './transformer';
|
|
12
12
|
export * from './types';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2025 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 Citeproc from 'citeproc';
|
|
17
|
+
export declare const initJats: () => void;
|
|
18
|
+
export declare const jatsVariableWrapper: Citeproc.VariableWrapper;
|