@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
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 normalizeID = (id) => id.replace(/:/g, '_');
|
|
44
60
|
const parser = prosemirror_model_1.DOMParser.fromSchema(schema_1.schema);
|
|
@@ -97,28 +113,8 @@ const chooseRefType = (type) => {
|
|
|
97
113
|
}
|
|
98
114
|
};
|
|
99
115
|
const sortContributors = (a, b) => Number(a.attrs.priority) - Number(b.attrs.priority);
|
|
100
|
-
const buildCitations = (citations) => citations.map((citation) => ({
|
|
101
|
-
citationID: citation.attrs.id,
|
|
102
|
-
citationItems: citation.attrs.rids.map((rid) => ({
|
|
103
|
-
id: rid,
|
|
104
|
-
})),
|
|
105
|
-
properties: {
|
|
106
|
-
noteIndex: 0,
|
|
107
|
-
},
|
|
108
|
-
}));
|
|
109
|
-
exports.buildCitations = buildCitations;
|
|
110
116
|
class JATSExporter {
|
|
111
117
|
constructor() {
|
|
112
|
-
this.getLibraryItem = (manuscriptID) => {
|
|
113
|
-
return (id) => {
|
|
114
|
-
var _a;
|
|
115
|
-
const node = (_a = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === id)[0]) === null || _a === void 0 ? void 0 : _a.node;
|
|
116
|
-
if (!node) {
|
|
117
|
-
return undefined;
|
|
118
|
-
}
|
|
119
|
-
return Object.assign(Object.assign({}, node.attrs), { _id: node.attrs.id, manuscriptID, objectType: json_schema_1.ObjectTypes.BibliographyItem });
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
118
|
this.nodesMap = new Map();
|
|
123
119
|
this.populateNodesMap = () => {
|
|
124
120
|
this.manuscriptNode.descendants((node) => {
|
|
@@ -133,7 +129,7 @@ class JATSExporter {
|
|
|
133
129
|
var _a;
|
|
134
130
|
this.manuscriptNode = manuscriptNode;
|
|
135
131
|
this.populateNodesMap();
|
|
136
|
-
this.
|
|
132
|
+
this.initCiteprocEngine(options.csl);
|
|
137
133
|
this.createSerializer();
|
|
138
134
|
const versionIds = (0, jats_versions_1.selectVersionIds)((_a = options.version) !== null && _a !== void 0 ? _a : '1.2');
|
|
139
135
|
this.document = document.implementation.createDocument(null, 'article', document.implementation.createDocumentType('article', versionIds.publicId, versionIds.systemId));
|
|
@@ -160,6 +156,34 @@ class JATSExporter {
|
|
|
160
156
|
await this.rewriteIDs();
|
|
161
157
|
return (0, w3c_xmlserializer_1.default)(this.document);
|
|
162
158
|
};
|
|
159
|
+
this.initCiteprocEngine = (csl) => {
|
|
160
|
+
const bibitems = new Map();
|
|
161
|
+
const citations = new Map();
|
|
162
|
+
this.manuscriptNode.descendants((n) => {
|
|
163
|
+
if ((0, schema_1.isBibliographyItemNode)(n)) {
|
|
164
|
+
bibitems.set(n.attrs.id, n.attrs);
|
|
165
|
+
}
|
|
166
|
+
if ((0, schema_1.isCitationNode)(n)) {
|
|
167
|
+
citations.set(n.attrs.id, (0, citeproc_1.buildCiteprocCitation)(n.attrs));
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
(0, citeproc_2.initJats)();
|
|
171
|
+
const engine = new Citeproc.Engine({
|
|
172
|
+
retrieveLocale: () => csl.locale,
|
|
173
|
+
retrieveItem: (id) => {
|
|
174
|
+
const item = bibitems.get(id);
|
|
175
|
+
if (!item) {
|
|
176
|
+
throw Error(`Missing bibliography item with id ${id}`);
|
|
177
|
+
}
|
|
178
|
+
return item;
|
|
179
|
+
},
|
|
180
|
+
variableWrapper: citeproc_2.jatsVariableWrapper,
|
|
181
|
+
}, csl.style);
|
|
182
|
+
engine.setOutputFormat('jats');
|
|
183
|
+
const output = engine.rebuildProcessorState([...citations.values()]);
|
|
184
|
+
this.engine = engine;
|
|
185
|
+
this.renderedCitations = new Map(output.map((i) => [i[0], i[2]]));
|
|
186
|
+
};
|
|
163
187
|
this.nodeFromJATS = (JATSFragment) => {
|
|
164
188
|
JATSFragment = JATSFragment.trim();
|
|
165
189
|
JATSFragment = JATSFragment.replace(' ', ' ');
|
|
@@ -414,139 +438,20 @@ class JATSExporter {
|
|
|
414
438
|
}
|
|
415
439
|
let refList = this.document.querySelector('ref-list');
|
|
416
440
|
if (!refList) {
|
|
417
|
-
warn('No bibliography element, creating a ref-list anyway');
|
|
418
441
|
refList = this.createElement('ref-list');
|
|
419
442
|
}
|
|
420
443
|
back.appendChild(refList);
|
|
421
|
-
const
|
|
422
|
-
const [
|
|
423
|
-
for (
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
|
|
444
|
+
const parser = new DOMParser();
|
|
445
|
+
const [_, bibliography] = this.engine.makeBibliography();
|
|
446
|
+
for (let i = 0; i < bibliography.length; i++) {
|
|
447
|
+
const item = `<template xmlns:xlink="${XLINK_NAMESPACE}">${bibliography[i]}</template>`;
|
|
448
|
+
const ref = parser.parseFromString(item, 'text/xml').querySelector('ref');
|
|
449
|
+
if (ref) {
|
|
450
|
+
refList.appendChild(ref);
|
|
427
451
|
}
|
|
428
|
-
const ref = this.createElement('ref');
|
|
429
|
-
ref.setAttribute('id', normalizeID(id));
|
|
430
|
-
const getPublicationType = (pubType) => publicationTypeToJats[pubType !== null && pubType !== void 0 ? pubType : ''] || pubType || 'journal';
|
|
431
|
-
if (bibliographyItem.attrs.literal) {
|
|
432
|
-
this.appendElement(ref, 'mixed-citation', bibliographyItem.attrs.literal, {
|
|
433
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
else {
|
|
437
|
-
const citation = this.appendElement(ref, 'element-citation', undefined, {
|
|
438
|
-
'publication-type': getPublicationType(bibliographyItem.attrs.type),
|
|
439
|
-
});
|
|
440
|
-
const attributeHandlers = {
|
|
441
|
-
author: (v) => this.processRefPersonGroup(citation, 'author', v),
|
|
442
|
-
editor: (v) => this.processRefPersonGroup(citation, 'editor', v),
|
|
443
|
-
title: (v) => this.setTitleContent(this.appendElement(citation, 'article-title'), v),
|
|
444
|
-
comment: (v) => this.appendElement(citation, 'comment', v),
|
|
445
|
-
'container-title': (v) => this.setTitleContent(this.appendElement(citation, 'source'), v),
|
|
446
|
-
issued: ({ 'date-parts': parts }) => this.processDateParts(citation, parts),
|
|
447
|
-
volume: (v) => this.appendElement(citation, 'volume', v),
|
|
448
|
-
issue: (v) => this.appendElement(citation, 'issue', v),
|
|
449
|
-
supplement: (v) => this.appendElement(citation, 'supplement', v),
|
|
450
|
-
page: (v) => this.processPageString(citation, String(v)),
|
|
451
|
-
DOI: (v) => this.appendElement(citation, 'pub-id', v, { 'pub-id-type': 'doi' }),
|
|
452
|
-
std: (v) => this.appendElement(citation, 'pub-id', v, {
|
|
453
|
-
'pub-id-type': 'std-designation',
|
|
454
|
-
}),
|
|
455
|
-
'collection-title': (v) => this.appendElement(citation, 'series', v),
|
|
456
|
-
edition: (v) => this.appendElement(citation, 'edition', v),
|
|
457
|
-
'publisher-place': (v) => this.appendElement(citation, 'publisher-loc', v),
|
|
458
|
-
publisher: (v) => this.appendElement(citation, 'publisher-name', v),
|
|
459
|
-
event: (v) => this.appendElement(citation, 'conf-name', v),
|
|
460
|
-
'event-place': (v) => this.appendElement(citation, 'conf-loc', v),
|
|
461
|
-
'number-of-pages': (v) => this.appendElement(citation, 'size', v, { units: 'pages' }),
|
|
462
|
-
institution: (v) => this.appendElement(citation, 'institution', v),
|
|
463
|
-
locator: (v) => this.appendElement(citation, 'elocation-id', v),
|
|
464
|
-
URL: (v) => this.appendElement(citation, 'ext-link', v, {
|
|
465
|
-
'ext-link-type': 'uri',
|
|
466
|
-
}),
|
|
467
|
-
'event-date': (v) => this.processDate(citation, 'conf-date', v),
|
|
468
|
-
accessed: (v) => this.processDate(citation, 'date-in-citation', v),
|
|
469
|
-
};
|
|
470
|
-
Object.entries(attributeHandlers).forEach(([key, handler]) => {
|
|
471
|
-
const value = bibliographyItem.attrs[key];
|
|
472
|
-
if (value) {
|
|
473
|
-
handler(value);
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
refList.appendChild(ref);
|
|
478
452
|
}
|
|
479
453
|
return back;
|
|
480
454
|
};
|
|
481
|
-
this.processDateParts = (parent, dateParts) => {
|
|
482
|
-
const [[year, month, day]] = dateParts;
|
|
483
|
-
if (year) {
|
|
484
|
-
this.appendElement(parent, 'year', String(year));
|
|
485
|
-
}
|
|
486
|
-
if (month) {
|
|
487
|
-
this.appendElement(parent, 'month', String(month));
|
|
488
|
-
}
|
|
489
|
-
if (day) {
|
|
490
|
-
this.appendElement(parent, 'day', String(day));
|
|
491
|
-
}
|
|
492
|
-
};
|
|
493
|
-
this.processPageString = (parent, page) => {
|
|
494
|
-
const numPattern = /^\d+$/;
|
|
495
|
-
const rangePattern = /^(\d+)-(\d+)$/;
|
|
496
|
-
if (numPattern.test(page)) {
|
|
497
|
-
this.appendElement(parent, 'fpage', page);
|
|
498
|
-
}
|
|
499
|
-
else if (rangePattern.test(page)) {
|
|
500
|
-
const [fpage, lpage] = page.split('-');
|
|
501
|
-
this.appendElement(parent, 'fpage', fpage);
|
|
502
|
-
this.appendElement(parent, 'lpage', lpage);
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
this.appendElement(parent, 'page-range', page);
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
this.processDate = (parent, tag, date) => {
|
|
509
|
-
const buildISODate = (date) => {
|
|
510
|
-
const dateParts = date['date-parts'];
|
|
511
|
-
if (dateParts && dateParts.length) {
|
|
512
|
-
const [[year, month, day]] = dateParts;
|
|
513
|
-
if (year && month && day) {
|
|
514
|
-
return new Date(Date.UTC(Number(year), Number(month) - 1, Number(day)));
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
const isoDate = buildISODate(date);
|
|
519
|
-
if (!isoDate) {
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
return this.appendElement(parent, tag, isoDate.toDateString(), {
|
|
523
|
-
'iso-8601-date': isoDate.toISOString(),
|
|
524
|
-
});
|
|
525
|
-
};
|
|
526
|
-
this.processRefPersonGroup = (citation, type, people) => {
|
|
527
|
-
if (!(people === null || people === void 0 ? void 0 : people.length)) {
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const group = this.appendElement(citation, 'person-group', undefined, {
|
|
531
|
-
'person-group-type': type,
|
|
532
|
-
});
|
|
533
|
-
people.forEach((person) => {
|
|
534
|
-
if (person.literal) {
|
|
535
|
-
this.appendElement(group, 'collab', person.literal);
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
const name = this.createElement('string-name');
|
|
539
|
-
if (person.family) {
|
|
540
|
-
this.appendElement(name, 'surname', person.family);
|
|
541
|
-
}
|
|
542
|
-
if (person.given) {
|
|
543
|
-
this.appendElement(name, 'given-names', person.given);
|
|
544
|
-
}
|
|
545
|
-
if (name.childNodes.length) {
|
|
546
|
-
group.appendChild(name);
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
};
|
|
550
455
|
this.createElement = (tag, content, attrs) => {
|
|
551
456
|
const el = this.document.createElement(tag);
|
|
552
457
|
if (content) {
|
|
@@ -668,35 +573,30 @@ class JATSExporter {
|
|
|
668
573
|
const xref = this.createElement('xref');
|
|
669
574
|
xref.setAttribute('ref-type', 'bibr');
|
|
670
575
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
671
|
-
const
|
|
672
|
-
if (
|
|
673
|
-
|
|
576
|
+
const fragment = this.renderedCitations.get(node.attrs.id);
|
|
577
|
+
if (fragment) {
|
|
578
|
+
xref.innerHTML = fragment;
|
|
674
579
|
}
|
|
675
|
-
xref.textContent = (0, html_1.textFromHTML)(citationTextContent);
|
|
676
580
|
return xref;
|
|
677
581
|
},
|
|
678
582
|
cross_reference: (node) => {
|
|
679
|
-
var _a, _b, _c;
|
|
583
|
+
var _a, _b, _c, _d;
|
|
680
584
|
const cross = node;
|
|
681
585
|
const rids = cross.attrs.rids;
|
|
682
586
|
if (!rids.length) {
|
|
683
587
|
return (_a = cross.attrs.label) !== null && _a !== void 0 ? _a : '';
|
|
684
588
|
}
|
|
685
589
|
const rid = rids[0];
|
|
686
|
-
const text = cross.attrs.label
|
|
687
|
-
const target = (
|
|
590
|
+
const text = (_b = cross.attrs.label) !== null && _b !== void 0 ? _b : (_c = this.labelTargets.get(rid)) === null || _c === void 0 ? void 0 : _c.label;
|
|
591
|
+
const target = (_d = (0, prosemirror_utils_1.findChildrenByAttr)(this.manuscriptNode, (attrs) => attrs.id === rid)[0]) === null || _d === void 0 ? void 0 : _d.node;
|
|
688
592
|
if (!target) {
|
|
689
|
-
|
|
690
|
-
return text || '';
|
|
593
|
+
return text !== null && text !== void 0 ? text : '';
|
|
691
594
|
}
|
|
692
595
|
const xref = this.createElement('xref');
|
|
693
596
|
const type = chooseRefType(target.type);
|
|
694
597
|
if (type) {
|
|
695
598
|
xref.setAttribute('ref-type', type);
|
|
696
599
|
}
|
|
697
|
-
else {
|
|
698
|
-
warn(`Unset ref-type for schema type ${target.type.name}`);
|
|
699
|
-
}
|
|
700
600
|
xref.setAttribute('rid', normalizeID(rids.join(' ')));
|
|
701
601
|
xref.textContent = text !== null && text !== void 0 ? text : '';
|
|
702
602
|
return xref;
|
|
@@ -1086,7 +986,6 @@ class JATSExporter {
|
|
|
1086
986
|
this.validateContributor(contributor);
|
|
1087
987
|
}
|
|
1088
988
|
catch (error) {
|
|
1089
|
-
warn(error.message);
|
|
1090
989
|
return;
|
|
1091
990
|
}
|
|
1092
991
|
const contrib = this.createElement('contrib');
|
|
@@ -1363,10 +1262,6 @@ class JATSExporter {
|
|
|
1363
1262
|
if (!container) {
|
|
1364
1263
|
return;
|
|
1365
1264
|
}
|
|
1366
|
-
const isContainerEmpty = container.children.length === 0;
|
|
1367
|
-
if (!isContainerEmpty) {
|
|
1368
|
-
warn('Backmatter section is not empty.');
|
|
1369
|
-
}
|
|
1370
1265
|
body.removeChild(container);
|
|
1371
1266
|
};
|
|
1372
1267
|
this.moveAwards = (front, body) => {
|
|
@@ -1512,27 +1407,6 @@ class JATSExporter {
|
|
|
1512
1407
|
return name;
|
|
1513
1408
|
};
|
|
1514
1409
|
}
|
|
1515
|
-
generateCitations() {
|
|
1516
|
-
const nodes = [];
|
|
1517
|
-
this.manuscriptNode.descendants((node) => {
|
|
1518
|
-
if ((0, schema_1.isCitationNode)(node)) {
|
|
1519
|
-
nodes.push(node);
|
|
1520
|
-
}
|
|
1521
|
-
});
|
|
1522
|
-
return (0, exports.buildCitations)(nodes);
|
|
1523
|
-
}
|
|
1524
|
-
generateCitationTexts(csl, manuscriptID) {
|
|
1525
|
-
this.citationTexts = new Map();
|
|
1526
|
-
this.citationProvider = new library_1.CitationProvider({
|
|
1527
|
-
getLibraryItem: this.getLibraryItem(manuscriptID),
|
|
1528
|
-
locale: csl.locale,
|
|
1529
|
-
citationStyle: csl.style,
|
|
1530
|
-
});
|
|
1531
|
-
const citations = this.generateCitations();
|
|
1532
|
-
this.citationProvider.rebuildState(citations).forEach(([id, , output]) => {
|
|
1533
|
-
this.citationTexts.set(id, output);
|
|
1534
|
-
});
|
|
1535
|
-
}
|
|
1536
1410
|
getFirstChildOfType(type, node) {
|
|
1537
1411
|
return this.getChildrenOfType(type, node)[0];
|
|
1538
1412
|
}
|