@manuscripts/transform 3.0.67 → 3.0.68-LEAN-4574.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 normalizeID = (id) => id.replace(/:/g, '_');
|
|
38
31
|
const parser = ProsemirrorDOMParser.fromSchema(schema);
|
|
@@ -90,27 +83,8 @@ const chooseRefType = (type) => {
|
|
|
90
83
|
}
|
|
91
84
|
};
|
|
92
85
|
const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
|
|
93
|
-
export const buildCitations = (citations) => citations.map((citation) => ({
|
|
94
|
-
citationID: citation.attrs.id,
|
|
95
|
-
citationItems: citation.attrs.rids.map((rid) => ({
|
|
96
|
-
id: rid,
|
|
97
|
-
})),
|
|
98
|
-
properties: {
|
|
99
|
-
noteIndex: 0,
|
|
100
|
-
},
|
|
101
|
-
}));
|
|
102
86
|
export class JATSExporter {
|
|
103
87
|
constructor() {
|
|
104
|
-
this.getLibraryItem = (manuscriptID) => {
|
|
105
|
-
return (id) => {
|
|
106
|
-
var _a;
|
|
107
|
-
const node = (_a = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
108
|
-
if (!node) {
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
return Object.assign(Object.assign({}, node.attrs), { _id: node.attrs.id, manuscriptID, objectType: ObjectTypes.BibliographyItem });
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
88
|
this.nodesMap = new Map();
|
|
115
89
|
this.populateNodesMap = () => {
|
|
116
90
|
this.manuscriptNode.descendants((node) => {
|
|
@@ -125,7 +99,7 @@ export class JATSExporter {
|
|
|
125
99
|
var _a;
|
|
126
100
|
this.manuscriptNode = manuscriptNode;
|
|
127
101
|
this.populateNodesMap();
|
|
128
|
-
this.
|
|
102
|
+
this.initCiteprocEngine(options.csl);
|
|
129
103
|
this.createSerializer();
|
|
130
104
|
const versionIds = selectVersionIds((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
|
|
131
105
|
this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
|
|
@@ -152,6 +126,34 @@ export class JATSExporter {
|
|
|
152
126
|
await this.rewriteIDs();
|
|
153
127
|
return serializeToXML(this.document);
|
|
154
128
|
};
|
|
129
|
+
this.initCiteprocEngine = (csl) => {
|
|
130
|
+
const bibitems = new Map();
|
|
131
|
+
const citations = new Map();
|
|
132
|
+
this.manuscriptNode.descendants((n) => {
|
|
133
|
+
if (isBibliographyItemNode(n)) {
|
|
134
|
+
bibitems.set(n.attrs.id, n.attrs);
|
|
135
|
+
}
|
|
136
|
+
if (isCitationNode(n)) {
|
|
137
|
+
citations.set(n.attrs.id, buildCiteprocCitation(n.attrs));
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
initJats();
|
|
141
|
+
const engine = new Citeproc.Engine({
|
|
142
|
+
retrieveLocale: () => csl.locale,
|
|
143
|
+
retrieveItem: (id) => {
|
|
144
|
+
const item = bibitems.get(id);
|
|
145
|
+
if (!item) {
|
|
146
|
+
throw Error(`Missing bibliography item with id ${id}`);
|
|
147
|
+
}
|
|
148
|
+
return item;
|
|
149
|
+
},
|
|
150
|
+
variableWrapper: jatsVariableWrapper,
|
|
151
|
+
}, csl.style);
|
|
152
|
+
engine.setOutputFormat('jats');
|
|
153
|
+
const output = engine.rebuildProcessorState([...citations.values()]);
|
|
154
|
+
this.engine = engine;
|
|
155
|
+
this.renderedCitations = new Map(output.map((i) => [i[0], i[2]]));
|
|
156
|
+
};
|
|
155
157
|
this.nodeFromJATS = (JATSFragment) => {
|
|
156
158
|
JATSFragment = JATSFragment.trim();
|
|
157
159
|
JATSFragment = JATSFragment.replace(' ', ' ');
|
|
@@ -406,139 +408,20 @@ export class JATSExporter {
|
|
|
406
408
|
}
|
|
407
409
|
let refList = this.document.querySelector('ref-list');
|
|
408
410
|
if (!refList) {
|
|
409
|
-
warn('No bibliography element, creating a ref-list anyway');
|
|
410
411
|
refList = this.createElement('ref-list');
|
|
411
412
|
}
|
|
412
413
|
back.appendChild(refList);
|
|
413
|
-
const
|
|
414
|
-
const [
|
|
415
|
-
for (
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
|
|
414
|
+
const parser = new DOMParser();
|
|
415
|
+
const [_, bibliography] = this.engine.makeBibliography();
|
|
416
|
+
for (let i = 0; i < bibliography.length; i++) {
|
|
417
|
+
const item = `<template xmlns:xlink="${XLINK_NAMESPACE}">${bibliography[i]}</template>`;
|
|
418
|
+
const ref = parser.parseFromString(item, 'text/xml').querySelector('ref');
|
|
419
|
+
if (ref) {
|
|
420
|
+
refList.appendChild(ref);
|
|
419
421
|
}
|
|
420
|
-
const ref = this.createElement('ref');
|
|
421
|
-
ref.setAttribute('id', normalizeID(id));
|
|
422
|
-
const getPublicationType = (pubType) => publicationTypeToJats[pubType !== null && pubType !== void 0 ? pubType : ''] || pubType || 'journal';
|
|
423
|
-
if (bibliographyItem.attrs.literal) {
|
|
424
|
-
this.appendElement(ref, 'mixed-citation', bibliographyItem.attrs.literal, {
|
|
425
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
const citation = this.appendElement(ref, 'element-citation', undefined, {
|
|
430
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
431
|
-
});
|
|
432
|
-
const attributeHandlers = {
|
|
433
|
-
author: (v) => this.processRefPersonGroup(citation, 'author', v),
|
|
434
|
-
editor: (v) => this.processRefPersonGroup(citation, 'editor', v),
|
|
435
|
-
title: (v) => this.setTitleContent(this.appendElement(citation, 'article-title'), v),
|
|
436
|
-
comment: (v) => this.appendElement(citation, 'comment', v),
|
|
437
|
-
'container-title': (v) => this.setTitleContent(this.appendElement(citation, 'source'), v),
|
|
438
|
-
issued: ({ 'date-parts': parts }) => this.processDateParts(citation, parts),
|
|
439
|
-
volume: (v) => this.appendElement(citation, 'volume', v),
|
|
440
|
-
issue: (v) => this.appendElement(citation, 'issue', v),
|
|
441
|
-
supplement: (v) => this.appendElement(citation, 'supplement', v),
|
|
442
|
-
page: (v) => this.processPageString(citation, String(v)),
|
|
443
|
-
DOI: (v) => this.appendElement(citation, 'pub-id', v, { 'pub-id-type': 'doi' }),
|
|
444
|
-
std: (v) => this.appendElement(citation, 'pub-id', v, {
|
|
445
|
-
'pub-id-type': 'std-designation',
|
|
446
|
-
}),
|
|
447
|
-
'collection-title': (v) => this.appendElement(citation, 'series', v),
|
|
448
|
-
edition: (v) => this.appendElement(citation, 'edition', v),
|
|
449
|
-
'publisher-place': (v) => this.appendElement(citation, 'publisher-loc', v),
|
|
450
|
-
publisher: (v) => this.appendElement(citation, 'publisher-name', v),
|
|
451
|
-
event: (v) => this.appendElement(citation, 'conf-name', v),
|
|
452
|
-
'event-place': (v) => this.appendElement(citation, 'conf-loc', v),
|
|
453
|
-
'number-of-pages': (v) => this.appendElement(citation, 'size', v, { units: 'pages' }),
|
|
454
|
-
institution: (v) => this.appendElement(citation, 'institution', v),
|
|
455
|
-
locator: (v) => this.appendElement(citation, 'elocation-id', v),
|
|
456
|
-
URL: (v) => this.appendElement(citation, 'ext-link', v, {
|
|
457
|
-
'ext-link-type': 'uri',
|
|
458
|
-
}),
|
|
459
|
-
'event-date': (v) => this.processDate(citation, 'conf-date', v),
|
|
460
|
-
accessed: (v) => this.processDate(citation, 'date-in-citation', v),
|
|
461
|
-
};
|
|
462
|
-
Object.entries(attributeHandlers).forEach(([key, handler]) => {
|
|
463
|
-
const value = bibliographyItem.attrs[key];
|
|
464
|
-
if (value) {
|
|
465
|
-
handler(value);
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
refList.appendChild(ref);
|
|
470
422
|
}
|
|
471
423
|
return back;
|
|
472
424
|
};
|
|
473
|
-
this.processDateParts = (parent, dateParts) => {
|
|
474
|
-
const [[year, month, day]] = dateParts;
|
|
475
|
-
if (year) {
|
|
476
|
-
this.appendElement(parent, 'year', String(year));
|
|
477
|
-
}
|
|
478
|
-
if (month) {
|
|
479
|
-
this.appendElement(parent, 'month', String(month));
|
|
480
|
-
}
|
|
481
|
-
if (day) {
|
|
482
|
-
this.appendElement(parent, 'day', String(day));
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
this.processPageString = (parent, page) => {
|
|
486
|
-
const numPattern = /^\d+$/;
|
|
487
|
-
const rangePattern = /^(\d+)-(\d+)$/;
|
|
488
|
-
if (numPattern.test(page)) {
|
|
489
|
-
this.appendElement(parent, 'fpage', page);
|
|
490
|
-
}
|
|
491
|
-
else if (rangePattern.test(page)) {
|
|
492
|
-
const [fpage, lpage] = page.split('-');
|
|
493
|
-
this.appendElement(parent, 'fpage', fpage);
|
|
494
|
-
this.appendElement(parent, 'lpage', lpage);
|
|
495
|
-
}
|
|
496
|
-
else {
|
|
497
|
-
this.appendElement(parent, 'page-range', page);
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
this.processDate = (parent, tag, date) => {
|
|
501
|
-
const buildISODate = (date) => {
|
|
502
|
-
const dateParts = date['date-parts'];
|
|
503
|
-
if (dateParts && dateParts.length) {
|
|
504
|
-
const [[year, month, day]] = dateParts;
|
|
505
|
-
if (year && month && day) {
|
|
506
|
-
return new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
const isoDate = buildISODate(date);
|
|
511
|
-
if (!isoDate) {
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
514
|
-
return this.appendElement(parent, tag, isoDate.toDateString(), {
|
|
515
|
-
'iso-8601-date': isoDate.toISOString(),
|
|
516
|
-
});
|
|
517
|
-
};
|
|
518
|
-
this.processRefPersonGroup = (citation, type, people) => {
|
|
519
|
-
if (!(people === null || people === void 0 ? void 0 : people.length)) {
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
const group = this.appendElement(citation, 'person-group', undefined, {
|
|
523
|
-
'person-group-type': type,
|
|
524
|
-
});
|
|
525
|
-
people.forEach((person) => {
|
|
526
|
-
if (person.literal) {
|
|
527
|
-
this.appendElement(group, 'collab', person.literal);
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const name = this.createElement('string-name');
|
|
531
|
-
if (person.family) {
|
|
532
|
-
this.appendElement(name, 'surname', person.family);
|
|
533
|
-
}
|
|
534
|
-
if (person.given) {
|
|
535
|
-
this.appendElement(name, 'given-names', person.given);
|
|
536
|
-
}
|
|
537
|
-
if (name.childNodes.length) {
|
|
538
|
-
group.appendChild(name);
|
|
539
|
-
}
|
|
540
|
-
});
|
|
541
|
-
};
|
|
542
425
|
this.createElement = (tag, content, attrs) => {
|
|
543
426
|
const el = this.document.createElement(tag);
|
|
544
427
|
if (content) {
|
|
@@ -660,35 +543,30 @@ export class JATSExporter {
|
|
|
660
543
|
const xref = this.createElement('xref');
|
|
661
544
|
xref.setAttribute('ref-type', 'bibr');
|
|
662
545
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
663
|
-
const
|
|
664
|
-
if (
|
|
665
|
-
|
|
546
|
+
const fragment = this.renderedCitations.get(node.attrs.id);
|
|
547
|
+
if (fragment) {
|
|
548
|
+
xref.innerHTML = fragment;
|
|
666
549
|
}
|
|
667
|
-
xref.textContent = textFromHTML(citationTextContent);
|
|
668
550
|
return xref;
|
|
669
551
|
},
|
|
670
552
|
cross_reference: (node) => {
|
|
671
|
-
var _a, _b, _c;
|
|
553
|
+
var _a, _b, _c, _d;
|
|
672
554
|
const cross = node;
|
|
673
555
|
const rids = cross.attrs.rids;
|
|
674
556
|
if (!rids.length) {
|
|
675
557
|
return (_a = cross.attrs.label) !== null && _a !== void 0 ? _a : '';
|
|
676
558
|
}
|
|
677
559
|
const rid = rids[0];
|
|
678
|
-
const text = cross.attrs.label
|
|
679
|
-
const target = (
|
|
560
|
+
const text = (_b = cross.attrs.label) !== null && _b !== void 0 ? _b : (_c = this.labelTargets.get(rid)) === null || _c === void 0 ? void 0 : _c.label;
|
|
561
|
+
const target = (_d = findChildrenByAttr(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _d === void 0 ? void 0 : _d.node;
|
|
680
562
|
if (!target) {
|
|
681
|
-
|
|
682
|
-
return text || '';
|
|
563
|
+
return text !== null && text !== void 0 ? text : '';
|
|
683
564
|
}
|
|
684
565
|
const xref = this.createElement('xref');
|
|
685
566
|
const type = chooseRefType(target.type);
|
|
686
567
|
if (type) {
|
|
687
568
|
xref.setAttribute('ref-type', type);
|
|
688
569
|
}
|
|
689
|
-
else {
|
|
690
|
-
warn(`Unset ref-type for schema type ${target.type.name}`);
|
|
691
|
-
}
|
|
692
570
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
693
571
|
xref.textContent = text !== null && text !== void 0 ? text : '';
|
|
694
572
|
return xref;
|
|
@@ -1078,7 +956,6 @@ export class JATSExporter {
|
|
|
1078
956
|
this.validateContributor(contributor);
|
|
1079
957
|
}
|
|
1080
958
|
catch (error) {
|
|
1081
|
-
warn(error.message);
|
|
1082
959
|
return;
|
|
1083
960
|
}
|
|
1084
961
|
const contrib = this.createElement('contrib');
|
|
@@ -1355,10 +1232,6 @@ export class JATSExporter {
|
|
|
1355
1232
|
if (!container) {
|
|
1356
1233
|
return;
|
|
1357
1234
|
}
|
|
1358
|
-
const isContainerEmpty = container.children.length === 0;
|
|
1359
|
-
if (!isContainerEmpty) {
|
|
1360
|
-
warn('Backmatter section is not empty.');
|
|
1361
|
-
}
|
|
1362
1235
|
body.removeChild(container);
|
|
1363
1236
|
};
|
|
1364
1237
|
this.moveAwards = (front, body) => {
|
|
@@ -1504,27 +1377,6 @@ export class JATSExporter {
|
|
|
1504
1377
|
return name;
|
|
1505
1378
|
};
|
|
1506
1379
|
}
|
|
1507
|
-
generateCitations() {
|
|
1508
|
-
const nodes = [];
|
|
1509
|
-
this.manuscriptNode.descendants((node) => {
|
|
1510
|
-
if (isCitationNode(node)) {
|
|
1511
|
-
nodes.push(node);
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
return buildCitations(nodes);
|
|
1515
|
-
}
|
|
1516
|
-
generateCitationTexts(csl, manuscriptID) {
|
|
1517
|
-
this.citationTexts = new Map();
|
|
1518
|
-
this.citationProvider = new CitationProvider({
|
|
1519
|
-
getLibraryItem: this.getLibraryItem(manuscriptID),
|
|
1520
|
-
locale: csl.locale,
|
|
1521
|
-
citationStyle: csl.style,
|
|
1522
|
-
});
|
|
1523
|
-
const citations = this.generateCitations();
|
|
1524
|
-
this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
|
|
1525
|
-
this.citationTexts.set(id, output);
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
1380
|
getFirstChildOfType(type, node) {
|
|
1529
1381
|
return this.getChildrenOfType(type, node)[0];
|
|
1530
1382
|
}
|
|
@@ -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
|
};
|
|
@@ -1060,30 +1047,22 @@ export class JATSDOMParser {
|
|
|
1060
1047
|
}
|
|
1061
1048
|
}
|
|
1062
1049
|
}
|
|
1063
|
-
getNameContent(element,
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
if (given) {
|
|
1069
|
-
name.given = given;
|
|
1070
|
-
}
|
|
1071
|
-
if (family) {
|
|
1072
|
-
name.family = family;
|
|
1073
|
-
}
|
|
1074
|
-
if (node.nodeName === 'collab') {
|
|
1075
|
-
name.literal = getTrimmedTextContent(node);
|
|
1076
|
-
}
|
|
1077
|
-
return name;
|
|
1078
|
-
};
|
|
1079
|
-
const personNodes = element.querySelectorAll(query);
|
|
1080
|
-
if (personNodes.length) {
|
|
1081
|
-
return Array.from(personNodes).map(buildName);
|
|
1050
|
+
getNameContent(element, type) {
|
|
1051
|
+
const query = `person-group[person-group-type="${type}"] > *`;
|
|
1052
|
+
const groups = [...element.querySelectorAll(query)];
|
|
1053
|
+
if (!groups.length) {
|
|
1054
|
+
return;
|
|
1082
1055
|
}
|
|
1056
|
+
return groups.map((node) => ({
|
|
1057
|
+
given: getTrimmedTextContent(node, 'given-names'),
|
|
1058
|
+
family: getTrimmedTextContent(node, 'surname'),
|
|
1059
|
+
literal: node.nodeName === 'collab' ? getTrimmedTextContent(node) : undefined,
|
|
1060
|
+
}));
|
|
1083
1061
|
}
|
|
1084
1062
|
getDateContent(element, query) {
|
|
1085
|
-
const
|
|
1086
|
-
|
|
1063
|
+
const date = element.querySelector(query);
|
|
1064
|
+
if (date) {
|
|
1065
|
+
const isoDate = date.getAttribute('iso-8601-date');
|
|
1087
1066
|
if (!isoDate) {
|
|
1088
1067
|
return;
|
|
1089
1068
|
}
|
|
@@ -1093,13 +1072,20 @@ export class JATSDOMParser {
|
|
|
1093
1072
|
parsedDate.getMonth() + 1,
|
|
1094
1073
|
parsedDate.getDate(),
|
|
1095
1074
|
];
|
|
1096
|
-
return
|
|
1075
|
+
return {
|
|
1097
1076
|
'date-parts': [parts],
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
getIssuedDateContent(element) {
|
|
1081
|
+
const year = getTrimmedTextContent(element, ':scope > * > year');
|
|
1082
|
+
if (!year) {
|
|
1083
|
+
return;
|
|
1103
1084
|
}
|
|
1085
|
+
const month = getTrimmedTextContent(element, ':scope > * > month');
|
|
1086
|
+
const day = getTrimmedTextContent(element, ':scope > * > day');
|
|
1087
|
+
return {
|
|
1088
|
+
'date-parts': [[year, month !== null && month !== void 0 ? month : '', day !== null && day !== void 0 ? day : '']],
|
|
1089
|
+
};
|
|
1104
1090
|
}
|
|
1105
1091
|
}
|
package/dist/es/schema/index.js
CHANGED
|
@@ -142,6 +142,7 @@ export * from './nodes/placeholder_element';
|
|
|
142
142
|
export * from './nodes/pullquote_element';
|
|
143
143
|
export * from './nodes/section';
|
|
144
144
|
export * from './nodes/section_title';
|
|
145
|
+
export * from './nodes/section_label';
|
|
145
146
|
export * from './nodes/supplement';
|
|
146
147
|
export * from './nodes/supplements';
|
|
147
148
|
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.0.68-LEAN-4574.2";
|
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;
|