@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
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.migrateFor = exports.getVersion = void 0;
|
|
18
18
|
__exportStar(require("./errors"), exports);
|
|
19
19
|
var getVersion_1 = require("./getVersion");
|
|
20
20
|
Object.defineProperty(exports, "getVersion", { enumerable: true, get: function () { return getVersion_1.getVersion; } });
|
|
@@ -23,10 +23,9 @@ __exportStar(require("./jats/types"), exports);
|
|
|
23
23
|
__exportStar(require("./lib/footnotes"), exports);
|
|
24
24
|
__exportStar(require("./lib/utils"), exports);
|
|
25
25
|
__exportStar(require("./lib/section-categories"), exports);
|
|
26
|
+
__exportStar(require("./lib/citeproc"), exports);
|
|
26
27
|
__exportStar(require("./schema"), exports);
|
|
27
28
|
var migrate_1 = require("./schema/migration/migrate");
|
|
28
29
|
Object.defineProperty(exports, "migrateFor", { enumerable: true, get: function () { return migrate_1.migrateFor; } });
|
|
29
|
-
var section_label_1 = require("./schema/nodes/section_label");
|
|
30
|
-
Object.defineProperty(exports, "isSectionLabelNode", { enumerable: true, get: function () { return section_label_1.isSectionLabelNode; } });
|
|
31
30
|
__exportStar(require("./transformer"), exports);
|
|
32
31
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2025 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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.jatsVariableWrapper = exports.initJats = void 0;
|
|
22
|
+
const citeproc_1 = __importDefault(require("citeproc"));
|
|
23
|
+
const normalizeID = (id) => id.replace(/:/g, '_');
|
|
24
|
+
const labelOnly = /^<label>.+<\/label>$/;
|
|
25
|
+
const initJats = () => {
|
|
26
|
+
if (citeproc_1.default.Output.Formats.jats) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
citeproc_1.default.Output.Formats.jats = Object.assign(Object.assign({}, citeproc_1.default.Output.Formats.html), { text_escape: function (text) {
|
|
30
|
+
return text !== null && text !== void 0 ? text : '';
|
|
31
|
+
}, bibstart: '<ref-list>', bibend: '</ref-list>', '@font-style/italic': '<italic>%%STRING%%</italic>', '@font-style/oblique': '<italic>%%STRING%%</italic>', '@font-style/normal': false, '@font-variant/small-caps': '<smallcaps>%%STRING%%</smallcaps>', '@font-variant/normal': false, '@font-weight/bold': '<bold>%%STRING%%</bold>', '@font-weight/normal': false, '@font-weight/light': false, '@text-decoration/none': false, '@text-decoration/underline': '<underline>%%STRING%%</underline>', '@vertical-align/sup': '<sup>%%STRING%%</sup>', '@vertical-align/sub': '<sub>%%STRING%%</sub>', '@vertical-align/baseline': false, '@bibliography/entry': function (state, str) {
|
|
32
|
+
const id = this.system_id;
|
|
33
|
+
const item = state.registry.registry[id].ref;
|
|
34
|
+
const type = getPublicationType(item);
|
|
35
|
+
str = str.trim();
|
|
36
|
+
if (labelOnly.test(str)) {
|
|
37
|
+
return `<ref id="${normalizeID(id)}">${str}<mixed-citation publication-type="${type}">${item.literal}</mixed-citation></ref>`;
|
|
38
|
+
}
|
|
39
|
+
else if (str.includes('mixed-citation')) {
|
|
40
|
+
return `<ref id="${normalizeID(id)}">${str.replace('%%TYPE%%', type)}</ref>`;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return `<ref id="${normalizeID(id)}"><mixed-citation publication-type="${type}">${str}</mixed-citation></ref>`;
|
|
44
|
+
}
|
|
45
|
+
}, '@display/block': false, '@display/left-margin': function (state, str) {
|
|
46
|
+
return `<label>${str}</label>`;
|
|
47
|
+
}, '@display/right-inline': function (state, str) {
|
|
48
|
+
return `<mixed-citation publication-type="%%TYPE%%">${str}</mixed-citation>`;
|
|
49
|
+
}, '@display/indent': false, '@URL/true': false, '@DOI/true': false });
|
|
50
|
+
const name = citeproc_1.default.NameOutput.prototype._renderOnePersonalName;
|
|
51
|
+
citeproc_1.default.NameOutput.prototype._renderOnePersonalName = function (...args) {
|
|
52
|
+
const area = this.state.tmp.area;
|
|
53
|
+
const blob = name.call(this, ...args);
|
|
54
|
+
if (blob && area === 'bibliography') {
|
|
55
|
+
blob.strings.prefix = '<string-name>';
|
|
56
|
+
blob.strings.suffix = '</string-name>';
|
|
57
|
+
}
|
|
58
|
+
return blob;
|
|
59
|
+
};
|
|
60
|
+
const given = citeproc_1.default.NameOutput.prototype._givenName;
|
|
61
|
+
citeproc_1.default.NameOutput.prototype._givenName = function (...args) {
|
|
62
|
+
const area = this.state.tmp.area;
|
|
63
|
+
const info = given.call(this, ...args);
|
|
64
|
+
if (info.blob && area === 'bibliography') {
|
|
65
|
+
info.blob.strings.prefix = '<given-names>';
|
|
66
|
+
info.blob.strings.suffix = '</given-names>';
|
|
67
|
+
}
|
|
68
|
+
return info;
|
|
69
|
+
};
|
|
70
|
+
const family = citeproc_1.default.NameOutput.prototype._familyName;
|
|
71
|
+
citeproc_1.default.NameOutput.prototype._familyName = function (...args) {
|
|
72
|
+
const area = this.state.tmp.area;
|
|
73
|
+
const blob = family.call(this, ...args);
|
|
74
|
+
if (blob && area === 'bibliography') {
|
|
75
|
+
blob.strings.prefix = '<surname>';
|
|
76
|
+
blob.strings.suffix = '</surname>';
|
|
77
|
+
}
|
|
78
|
+
return blob;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
exports.initJats = initJats;
|
|
82
|
+
const namesWrapper = (type) => (str) => `<person-group person-group-type="${type}">${str}</person-group>`;
|
|
83
|
+
const formatDate = (date) => {
|
|
84
|
+
let output = date.year;
|
|
85
|
+
if (date.month) {
|
|
86
|
+
output += '-' + String(date.month).padStart(2, '0');
|
|
87
|
+
if (date.day) {
|
|
88
|
+
output += '-' + String(date.day).padStart(2, '0');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return output;
|
|
92
|
+
};
|
|
93
|
+
const getPublicationType = (item) => {
|
|
94
|
+
switch (item.type) {
|
|
95
|
+
case 'article-journal':
|
|
96
|
+
return 'journal';
|
|
97
|
+
case 'webpage':
|
|
98
|
+
return 'page';
|
|
99
|
+
case 'dataset':
|
|
100
|
+
return 'data';
|
|
101
|
+
default:
|
|
102
|
+
return item.type;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const wrappers = {
|
|
106
|
+
author: namesWrapper('author'),
|
|
107
|
+
issued: (str, item) => str.replace(item.issued.year, `<year>${item.issued.year}</year>`),
|
|
108
|
+
'container-title': (str) => `<source>${str}</source>`,
|
|
109
|
+
volume: (str) => `<volume>${str}</volume>`,
|
|
110
|
+
issue: (str) => `<issue>${str}</issue>`,
|
|
111
|
+
supplement: (str) => `<supplement>${str}</supplement>`,
|
|
112
|
+
page: (str) => {
|
|
113
|
+
let fpage = str;
|
|
114
|
+
let lpage;
|
|
115
|
+
const parts = str.split('-');
|
|
116
|
+
if (parts.length === 2) {
|
|
117
|
+
fpage = parts[0];
|
|
118
|
+
lpage = parts[1];
|
|
119
|
+
}
|
|
120
|
+
str = str.replace(fpage, `<fpage>${fpage}</fpage>`);
|
|
121
|
+
if (lpage) {
|
|
122
|
+
str = str.replace(lpage, `<lpage>${lpage}</lpage>`);
|
|
123
|
+
}
|
|
124
|
+
return str;
|
|
125
|
+
},
|
|
126
|
+
title: (str, item) => {
|
|
127
|
+
const type = item.type;
|
|
128
|
+
switch (type) {
|
|
129
|
+
case 'dataset':
|
|
130
|
+
return `<data-title>${str}</data-title>`;
|
|
131
|
+
case 'article-journal':
|
|
132
|
+
case 'preprint':
|
|
133
|
+
return `<article-title>${str}</article-title>`;
|
|
134
|
+
default:
|
|
135
|
+
return `<part-title>${str}</part-title>`;
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
std: (str) => `<pub-id pub-id-type="std-designation">${str}</pub-id>`,
|
|
139
|
+
'collection-title': (str) => `<series>${str}</series>`,
|
|
140
|
+
edition: (str) => `<edition>${str}</edition>`,
|
|
141
|
+
publisher: (str) => `<publisher-name>${str}</publisher-name>`,
|
|
142
|
+
'publisher-place': (str) => `<publisher-loc>${str}</publisher-loc>`,
|
|
143
|
+
event: (str) => `<conf-name>${str}</conf-name>`,
|
|
144
|
+
'event-place': (str) => `<conf-loc>${str}</conf-loc>`,
|
|
145
|
+
'number-of-pages': (str) => `<size units="pages">${str}</size>`,
|
|
146
|
+
institution: (str) => `<institution>${str}</institution>`,
|
|
147
|
+
locator: (str) => `<elocation-id>${str}</elocation-id>`,
|
|
148
|
+
editor: namesWrapper('editor'),
|
|
149
|
+
accessed: (str, item) => `<date-in-citation content-type="access-date" iso-8601-date="${formatDate(item.accessed)}">${str}</date-in-citation>`,
|
|
150
|
+
'event-date': (str, item) => `<conf-date iso-8601-date="${formatDate(item['event-date'])}">${str}</conf-date>`,
|
|
151
|
+
DOI: (str) => `<pub-id pub-id-type="doi">${str}</pub-id>`,
|
|
152
|
+
URL: (str) => `<ext-link ext-link-type="uri" xlink:href="${str}">${str}</ext-link>`,
|
|
153
|
+
};
|
|
154
|
+
const jatsVariableWrapper = (params, pre, str, post) => {
|
|
155
|
+
if (str && params.context === 'bibliography') {
|
|
156
|
+
const name = params.variableNames[0];
|
|
157
|
+
const fn = wrappers[name];
|
|
158
|
+
if (fn) {
|
|
159
|
+
str = fn(str, params.itemData);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return `${pre}${str !== null && str !== void 0 ? str : ''}${post}`;
|
|
163
|
+
};
|
|
164
|
+
exports.jatsVariableWrapper = jatsVariableWrapper;
|
|
@@ -14,31 +14,47 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
17
40
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
41
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
42
|
};
|
|
20
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.JATSExporter = exports.
|
|
22
|
-
const
|
|
23
|
-
const library_1 = require("@manuscripts/library");
|
|
24
|
-
const debug_1 = __importDefault(require("debug"));
|
|
44
|
+
exports.JATSExporter = exports.createCounter = void 0;
|
|
45
|
+
const Citeproc = __importStar(require("citeproc"));
|
|
25
46
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
26
47
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
27
48
|
const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
|
|
49
|
+
const citeproc_1 = require("../../lib/citeproc");
|
|
28
50
|
const credit_roles_1 = require("../../lib/credit-roles");
|
|
29
51
|
const footnotes_1 = require("../../lib/footnotes");
|
|
30
52
|
const html_1 = require("../../lib/html");
|
|
31
53
|
const schema_1 = require("../../schema");
|
|
32
54
|
const transformer_1 = require("../../transformer");
|
|
55
|
+
const citeproc_2 = require("./citeproc");
|
|
33
56
|
const jats_versions_1 = require("./jats-versions");
|
|
34
57
|
const labels_1 = require("./labels");
|
|
35
|
-
const publicationTypeToJats = {
|
|
36
|
-
article: 'journal',
|
|
37
|
-
'article-journal': 'journal',
|
|
38
|
-
webpage: 'web',
|
|
39
|
-
dataset: 'data',
|
|
40
|
-
};
|
|
41
|
-
const warn = (0, debug_1.default)('manuscripts-transform');
|
|
42
58
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
43
59
|
const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
44
60
|
const normalizeID = (id) => id.replace(/:/g, '_');
|
|
@@ -93,28 +109,8 @@ const chooseRefType = (type) => {
|
|
|
93
109
|
}
|
|
94
110
|
};
|
|
95
111
|
const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
|
|
96
|
-
const buildCitations = (citations) => citations.map((citation) => ({
|
|
97
|
-
citationID: citation.attrs.id,
|
|
98
|
-
citationItems: citation.attrs.rids.map((rid) => ({
|
|
99
|
-
id: rid,
|
|
100
|
-
})),
|
|
101
|
-
properties: {
|
|
102
|
-
noteIndex: 0,
|
|
103
|
-
},
|
|
104
|
-
}));
|
|
105
|
-
exports.buildCitations = buildCitations;
|
|
106
112
|
class JATSExporter {
|
|
107
113
|
constructor() {
|
|
108
|
-
this.getLibraryItem = (manuscriptID) => {
|
|
109
|
-
return (id) => {
|
|
110
|
-
var _a;
|
|
111
|
-
const node = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
112
|
-
if (!node) {
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
return Object.assign(Object.assign({}, node.attrs), { _id: node.attrs.id, manuscriptID, objectType: json_schema_1.ObjectTypes.BibliographyItem });
|
|
116
|
-
};
|
|
117
|
-
};
|
|
118
114
|
this.nodesMap = new Map();
|
|
119
115
|
this.populateNodesMap = () => {
|
|
120
116
|
this.manuscriptNode.descendants((node) => {
|
|
@@ -129,7 +125,7 @@ class JATSExporter {
|
|
|
129
125
|
var _a;
|
|
130
126
|
this.manuscriptNode = manuscriptNode;
|
|
131
127
|
this.populateNodesMap();
|
|
132
|
-
this.
|
|
128
|
+
this.initCiteprocEngine(options.csl);
|
|
133
129
|
this.createSerializer();
|
|
134
130
|
const versionIds = (0, jats_versions_1.selectVersionIds)((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
|
|
135
131
|
this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
|
|
@@ -156,6 +152,34 @@ class JATSExporter {
|
|
|
156
152
|
await this.rewriteIDs();
|
|
157
153
|
return (0, w3c_xmlserializer_1.default)(this.document);
|
|
158
154
|
};
|
|
155
|
+
this.initCiteprocEngine = (csl) => {
|
|
156
|
+
const bibitems = new Map();
|
|
157
|
+
const citations = new Map();
|
|
158
|
+
this.manuscriptNode.descendants((n) => {
|
|
159
|
+
if ((0, schema_1.isBibliographyItemNode)(n)) {
|
|
160
|
+
bibitems.set(n.attrs.id, n.attrs);
|
|
161
|
+
}
|
|
162
|
+
if ((0, schema_1.isCitationNode)(n)) {
|
|
163
|
+
citations.set(n.attrs.id, (0, citeproc_1.buildCiteprocCitation)(n.attrs));
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
(0, citeproc_2.initJats)();
|
|
167
|
+
const engine = new Citeproc.Engine({
|
|
168
|
+
retrieveLocale: () => csl.locale,
|
|
169
|
+
retrieveItem: (id) => {
|
|
170
|
+
const item = bibitems.get(id);
|
|
171
|
+
if (!item) {
|
|
172
|
+
throw Error(`Missing bibliography item with id ${id}`);
|
|
173
|
+
}
|
|
174
|
+
return item;
|
|
175
|
+
},
|
|
176
|
+
variableWrapper: citeproc_2.jatsVariableWrapper,
|
|
177
|
+
}, csl.style);
|
|
178
|
+
engine.setOutputFormat('jats');
|
|
179
|
+
const output = engine.rebuildProcessorState([...citations.values()]);
|
|
180
|
+
this.engine = engine;
|
|
181
|
+
this.renderedCitations = new Map(output.map((i) => [i[0], i[2]]));
|
|
182
|
+
};
|
|
159
183
|
this.nodeFromJATS = (JATSFragment) => {
|
|
160
184
|
JATSFragment = JATSFragment.trim();
|
|
161
185
|
JATSFragment = JATSFragment.replace(' ', ' ');
|
|
@@ -410,139 +434,20 @@ class JATSExporter {
|
|
|
410
434
|
}
|
|
411
435
|
let refList = this.document.querySelector('ref-list');
|
|
412
436
|
if (!refList) {
|
|
413
|
-
warn('No bibliography element, creating a ref-list anyway');
|
|
414
437
|
refList = this.createElement('ref-list');
|
|
415
438
|
}
|
|
416
439
|
back.appendChild(refList);
|
|
417
|
-
const
|
|
418
|
-
const [
|
|
419
|
-
for (
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
|
|
440
|
+
const parser = new DOMParser();
|
|
441
|
+
const [_, bibliography] = this.engine.makeBibliography();
|
|
442
|
+
for (let i = 0; i < bibliography.length; i++) {
|
|
443
|
+
const item = `<template xmlns:xlink="${XLINK_NAMESPACE}">${bibliography[i]}</template>`;
|
|
444
|
+
const ref = parser.parseFromString(item, 'text/xml').querySelector('ref');
|
|
445
|
+
if (ref) {
|
|
446
|
+
refList.appendChild(ref);
|
|
423
447
|
}
|
|
424
|
-
const ref = this.createElement('ref');
|
|
425
|
-
ref.setAttribute('id', normalizeID(id));
|
|
426
|
-
const getPublicationType = (pubType) => publicationTypeToJats[pubType !== null && pubType !== void 0 ? pubType : ''] || pubType || 'journal';
|
|
427
|
-
if (bibliographyItem.attrs.literal) {
|
|
428
|
-
this.appendElement(ref, 'mixed-citation', bibliographyItem.attrs.literal, {
|
|
429
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
const citation = this.appendElement(ref, 'element-citation', undefined, {
|
|
434
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
435
|
-
});
|
|
436
|
-
const attributeHandlers = {
|
|
437
|
-
author: (v) => this.processRefPersonGroup(citation, 'author', v),
|
|
438
|
-
editor: (v) => this.processRefPersonGroup(citation, 'editor', v),
|
|
439
|
-
title: (v) => this.setTitleContent(this.appendElement(citation, 'article-title'), v),
|
|
440
|
-
comment: (v) => this.appendElement(citation, 'comment', v),
|
|
441
|
-
'container-title': (v) => this.setTitleContent(this.appendElement(citation, 'source'), v),
|
|
442
|
-
issued: ({ 'date-parts': parts }) => this.processDateParts(citation, parts),
|
|
443
|
-
volume: (v) => this.appendElement(citation, 'volume', v),
|
|
444
|
-
issue: (v) => this.appendElement(citation, 'issue', v),
|
|
445
|
-
supplement: (v) => this.appendElement(citation, 'supplement', v),
|
|
446
|
-
page: (v) => this.processPageString(citation, String(v)),
|
|
447
|
-
DOI: (v) => this.appendElement(citation, 'pub-id', v, { 'pub-id-type': 'doi' }),
|
|
448
|
-
std: (v) => this.appendElement(citation, 'pub-id', v, {
|
|
449
|
-
'pub-id-type': 'std-designation',
|
|
450
|
-
}),
|
|
451
|
-
'collection-title': (v) => this.appendElement(citation, 'series', v),
|
|
452
|
-
edition: (v) => this.appendElement(citation, 'edition', v),
|
|
453
|
-
'publisher-place': (v) => this.appendElement(citation, 'publisher-loc', v),
|
|
454
|
-
publisher: (v) => this.appendElement(citation, 'publisher-name', v),
|
|
455
|
-
event: (v) => this.appendElement(citation, 'conf-name', v),
|
|
456
|
-
'event-place': (v) => this.appendElement(citation, 'conf-loc', v),
|
|
457
|
-
'number-of-pages': (v) => this.appendElement(citation, 'size', v, { units: 'pages' }),
|
|
458
|
-
institution: (v) => this.appendElement(citation, 'institution', v),
|
|
459
|
-
locator: (v) => this.appendElement(citation, 'elocation-id', v),
|
|
460
|
-
URL: (v) => this.appendElement(citation, 'ext-link', v, {
|
|
461
|
-
'ext-link-type': 'uri',
|
|
462
|
-
}),
|
|
463
|
-
'event-date': (v) => this.processDate(citation, 'conf-date', v),
|
|
464
|
-
accessed: (v) => this.processDate(citation, 'date-in-citation', v),
|
|
465
|
-
};
|
|
466
|
-
Object.entries(attributeHandlers).forEach(([key, handler]) => {
|
|
467
|
-
const value = bibliographyItem.attrs[key];
|
|
468
|
-
if (value) {
|
|
469
|
-
handler(value);
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
refList.appendChild(ref);
|
|
474
448
|
}
|
|
475
449
|
return back;
|
|
476
450
|
};
|
|
477
|
-
this.processDateParts = (parent, dateParts) => {
|
|
478
|
-
const [[year, month, day]] = dateParts;
|
|
479
|
-
if (year) {
|
|
480
|
-
this.appendElement(parent, 'year', String(year));
|
|
481
|
-
}
|
|
482
|
-
if (month) {
|
|
483
|
-
this.appendElement(parent, 'month', String(month));
|
|
484
|
-
}
|
|
485
|
-
if (day) {
|
|
486
|
-
this.appendElement(parent, 'day', String(day));
|
|
487
|
-
}
|
|
488
|
-
};
|
|
489
|
-
this.processPageString = (parent, page) => {
|
|
490
|
-
const numPattern = /^\d+$/;
|
|
491
|
-
const rangePattern = /^(\d+)-(\d+)$/;
|
|
492
|
-
if (numPattern.test(page)) {
|
|
493
|
-
this.appendElement(parent, 'fpage', page);
|
|
494
|
-
}
|
|
495
|
-
else if (rangePattern.test(page)) {
|
|
496
|
-
const [fpage, lpage] = page.split('-');
|
|
497
|
-
this.appendElement(parent, 'fpage', fpage);
|
|
498
|
-
this.appendElement(parent, 'lpage', lpage);
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
this.appendElement(parent, 'page-range', page);
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
this.processDate = (parent, tag, date) => {
|
|
505
|
-
const buildISODate = (date) => {
|
|
506
|
-
const dateParts = date['date-parts'];
|
|
507
|
-
if (dateParts && dateParts.length) {
|
|
508
|
-
const [[year, month, day]] = dateParts;
|
|
509
|
-
if (year && month && day) {
|
|
510
|
-
return new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
const isoDate = buildISODate(date);
|
|
515
|
-
if (!isoDate) {
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
return this.appendElement(parent, tag, isoDate.toDateString(), {
|
|
519
|
-
'iso-8601-date': isoDate.toISOString(),
|
|
520
|
-
});
|
|
521
|
-
};
|
|
522
|
-
this.processRefPersonGroup = (citation, type, people) => {
|
|
523
|
-
if (!(people === null || people === void 0 ? void 0 : people.length)) {
|
|
524
|
-
return;
|
|
525
|
-
}
|
|
526
|
-
const group = this.appendElement(citation, 'person-group', undefined, {
|
|
527
|
-
'person-group-type': type,
|
|
528
|
-
});
|
|
529
|
-
people.forEach((person) => {
|
|
530
|
-
if (person.literal) {
|
|
531
|
-
this.appendElement(group, 'collab', person.literal);
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
const name = this.createElement('string-name');
|
|
535
|
-
if (person.family) {
|
|
536
|
-
this.appendElement(name, 'surname', person.family);
|
|
537
|
-
}
|
|
538
|
-
if (person.given) {
|
|
539
|
-
this.appendElement(name, 'given-names', person.given);
|
|
540
|
-
}
|
|
541
|
-
if (name.childNodes.length) {
|
|
542
|
-
group.appendChild(name);
|
|
543
|
-
}
|
|
544
|
-
});
|
|
545
|
-
};
|
|
546
451
|
this.createElement = (tag, content, attrs) => {
|
|
547
452
|
const el = this.document.createElement(tag);
|
|
548
453
|
if (content) {
|
|
@@ -676,35 +581,30 @@ class JATSExporter {
|
|
|
676
581
|
const xref = this.createElement('xref');
|
|
677
582
|
xref.setAttribute('ref-type', 'bibr');
|
|
678
583
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
679
|
-
const
|
|
680
|
-
if (
|
|
681
|
-
|
|
584
|
+
const fragment = this.renderedCitations.get(node.attrs.id);
|
|
585
|
+
if (fragment) {
|
|
586
|
+
xref.innerHTML = fragment;
|
|
682
587
|
}
|
|
683
|
-
xref.textContent = (0, html_1.textFromHTML)(citationTextContent);
|
|
684
588
|
return xref;
|
|
685
589
|
},
|
|
686
590
|
cross_reference: (node) => {
|
|
687
|
-
var _a, _b, _c;
|
|
591
|
+
var _a, _b, _c, _d;
|
|
688
592
|
const cross = node;
|
|
689
593
|
const rids = cross.attrs.rids;
|
|
690
594
|
if (!rids.length) {
|
|
691
595
|
return (_a = cross.attrs.label) !== null && _a !== void 0 ? _a : '';
|
|
692
596
|
}
|
|
693
597
|
const rid = rids[0];
|
|
694
|
-
const text = cross.attrs.label
|
|
695
|
-
const target = (
|
|
598
|
+
const text = (_b = cross.attrs.label) !== null && _b !== void 0 ? _b : (_c = this.labelTargets.get(rid)) === null || _c === void 0 ? void 0 : _c.label;
|
|
599
|
+
const target = (_d = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _d === void 0 ? void 0 : _d.node;
|
|
696
600
|
if (!target) {
|
|
697
|
-
|
|
698
|
-
return text || '';
|
|
601
|
+
return text !== null && text !== void 0 ? text : '';
|
|
699
602
|
}
|
|
700
603
|
const xref = this.createElement('xref');
|
|
701
604
|
const type = chooseRefType(target.type);
|
|
702
605
|
if (type) {
|
|
703
606
|
xref.setAttribute('ref-type', type);
|
|
704
607
|
}
|
|
705
|
-
else {
|
|
706
|
-
warn(`Unset ref-type for schema type ${target.type.name}`);
|
|
707
|
-
}
|
|
708
608
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
709
609
|
xref.textContent = text !== null && text !== void 0 ? text : '';
|
|
710
610
|
return xref;
|
|
@@ -1094,7 +994,6 @@ class JATSExporter {
|
|
|
1094
994
|
this.validateContributor(contributor);
|
|
1095
995
|
}
|
|
1096
996
|
catch (error) {
|
|
1097
|
-
warn(error.message);
|
|
1098
997
|
return;
|
|
1099
998
|
}
|
|
1100
999
|
const contrib = this.createElement('contrib');
|
|
@@ -1371,10 +1270,6 @@ class JATSExporter {
|
|
|
1371
1270
|
if (!container) {
|
|
1372
1271
|
return;
|
|
1373
1272
|
}
|
|
1374
|
-
const isContainerEmpty = container.children.length === 0;
|
|
1375
|
-
if (!isContainerEmpty) {
|
|
1376
|
-
warn('Backmatter section is not empty.');
|
|
1377
|
-
}
|
|
1378
1273
|
body.removeChild(container);
|
|
1379
1274
|
};
|
|
1380
1275
|
this.moveAwards = (front, body) => {
|
|
@@ -1518,27 +1413,6 @@ class JATSExporter {
|
|
|
1518
1413
|
return name;
|
|
1519
1414
|
};
|
|
1520
1415
|
}
|
|
1521
|
-
generateCitations() {
|
|
1522
|
-
const nodes = [];
|
|
1523
|
-
this.manuscriptNode.descendants((node) => {
|
|
1524
|
-
if ((0, schema_1.isCitationNode)(node)) {
|
|
1525
|
-
nodes.push(node);
|
|
1526
|
-
}
|
|
1527
|
-
});
|
|
1528
|
-
return (0, exports.buildCitations)(nodes);
|
|
1529
|
-
}
|
|
1530
|
-
generateCitationTexts(csl, manuscriptID) {
|
|
1531
|
-
this.citationTexts = new Map();
|
|
1532
|
-
this.citationProvider = new library_1.CitationProvider({
|
|
1533
|
-
getLibraryItem: this.getLibraryItem(manuscriptID),
|
|
1534
|
-
locale: csl.locale,
|
|
1535
|
-
citationStyle: csl.style,
|
|
1536
|
-
});
|
|
1537
|
-
const citations = this.generateCitations();
|
|
1538
|
-
this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
|
|
1539
|
-
this.citationTexts.set(id, output);
|
|
1540
|
-
});
|
|
1541
|
-
}
|
|
1542
1416
|
getFirstChildOfType(type, node) {
|
|
1543
1417
|
return this.getChildrenOfType(type, node)[0];
|
|
1544
1418
|
}
|