@manuscripts/transform 4.5.7 → 4.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/jats/__tests__/jats-exporter.test.js +27 -20
- package/dist/cjs/jats/__tests__/jats-roundtrip.test.js +6 -1
- package/dist/cjs/jats/exporter/jats-exporter.js +3 -7
- package/dist/cjs/version.js +1 -1
- package/dist/es/jats/__tests__/jats-exporter.test.js +24 -20
- package/dist/es/jats/__tests__/jats-roundtrip.test.js +3 -1
- package/dist/es/jats/exporter/jats-exporter.js +3 -4
- package/dist/es/version.js +1 -1
- package/dist/types/jats/exporter/jats-exporter.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/jats/__tests__/jats-exporter.test.ts +26 -20
- package/src/jats/__tests__/jats-roundtrip.test.ts +3 -1
- package/src/jats/exporter/jats-exporter.ts +5 -6
- package/src/version.ts +1 -1
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
17
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
21
|
const libxmljs2_1 = require("libxmljs2");
|
|
22
|
+
const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
|
|
19
23
|
const jats_exporter_1 = require("../exporter/jats-exporter");
|
|
20
24
|
const parse_jats_article_1 = require("../importer/parse-jats-article");
|
|
21
25
|
const citations_1 = require("./citations");
|
|
@@ -32,10 +36,10 @@ describe('JATS exporter', () => {
|
|
|
32
36
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
33
37
|
const input = await (0, files_1.readAndParseFixture)('jats-example-full.xml');
|
|
34
38
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
35
|
-
const
|
|
39
|
+
const document = await transformer.export(node, {
|
|
36
40
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
37
41
|
});
|
|
38
|
-
expect(
|
|
42
|
+
expect((0, w3c_xmlserializer_1.default)(document)).toMatchSnapshot('jats-export');
|
|
39
43
|
});
|
|
40
44
|
test('export with & and < in bibliography metadata', async () => {
|
|
41
45
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
@@ -48,27 +52,27 @@ describe('JATS exporter', () => {
|
|
|
48
52
|
}
|
|
49
53
|
});
|
|
50
54
|
biblio.attrs.title += ' & Sons 55 < 135';
|
|
51
|
-
const
|
|
55
|
+
const document = await transformer.export(node, {
|
|
52
56
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
53
57
|
});
|
|
54
|
-
expect(
|
|
58
|
+
expect((0, w3c_xmlserializer_1.default)(document)).toMatchSnapshot('jats-export-with-xml-unsafe-in-biblios');
|
|
55
59
|
});
|
|
56
60
|
test('export v1.1', async () => {
|
|
57
61
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
58
62
|
const input = await (0, files_1.readAndParseFixture)('jats-example-full.xml');
|
|
59
63
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
60
|
-
const
|
|
64
|
+
const document = await transformer.export(node, {
|
|
61
65
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
62
66
|
version: '1.1',
|
|
63
67
|
});
|
|
64
|
-
expect(
|
|
68
|
+
expect((0, w3c_xmlserializer_1.default)(document)).toMatchSnapshot('jats-export-1.1');
|
|
65
69
|
});
|
|
66
70
|
test('export unknown version', async () => {
|
|
67
71
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
68
72
|
const input = await (0, files_1.readAndParseFixture)('jats-example-full.xml');
|
|
69
73
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
70
74
|
await expect(async () => {
|
|
71
|
-
await transformer.
|
|
75
|
+
await transformer.export(node, {
|
|
72
76
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
73
77
|
version: '1.0',
|
|
74
78
|
});
|
|
@@ -78,9 +82,10 @@ describe('JATS exporter', () => {
|
|
|
78
82
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
79
83
|
const input = await (0, files_1.readAndParseFixture)('jats-tables-example.xml');
|
|
80
84
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
81
|
-
const
|
|
85
|
+
const document = await transformer.export(node, {
|
|
82
86
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
83
87
|
});
|
|
88
|
+
const xml = (0, w3c_xmlserializer_1.default)(document);
|
|
84
89
|
const resultDoc = parseXMLWithDTD(xml);
|
|
85
90
|
const tableWrapFoot = resultDoc.get('//table-wrap/table-wrap-foot');
|
|
86
91
|
const paragraph = resultDoc.get('//table-wrap/table-wrap-foot/p');
|
|
@@ -91,30 +96,30 @@ describe('JATS exporter', () => {
|
|
|
91
96
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
92
97
|
const input = await (0, files_1.readAndParseFixture)('jats-import.xml');
|
|
93
98
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
94
|
-
const
|
|
99
|
+
const document = await transformer.export(node, {
|
|
95
100
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
96
101
|
});
|
|
97
|
-
const { errors } = parseXMLWithDTD(
|
|
102
|
+
const { errors } = parseXMLWithDTD((0, w3c_xmlserializer_1.default)(document));
|
|
98
103
|
expect(errors).toHaveLength(0);
|
|
99
104
|
});
|
|
100
105
|
test('DTD validation: article with title markup and citations', async () => {
|
|
101
106
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
102
107
|
const input = await (0, files_1.readAndParseFixture)('jats-document.xml');
|
|
103
108
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
104
|
-
const
|
|
109
|
+
const document = await transformer.export(node, {
|
|
105
110
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
106
111
|
});
|
|
107
|
-
const { errors } = parseXMLWithDTD(
|
|
112
|
+
const { errors } = parseXMLWithDTD((0, w3c_xmlserializer_1.default)(document));
|
|
108
113
|
expect(errors).toHaveLength(0);
|
|
109
114
|
});
|
|
110
115
|
test('Export link', async () => {
|
|
111
116
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
112
117
|
const input = await (0, files_1.readAndParseFixture)('jats-import.xml');
|
|
113
118
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
114
|
-
const
|
|
119
|
+
const document = await transformer.export(node, {
|
|
115
120
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
116
121
|
});
|
|
117
|
-
const output = parseXMLWithDTD(
|
|
122
|
+
const output = parseXMLWithDTD((0, w3c_xmlserializer_1.default)(document));
|
|
118
123
|
const link = output.get('//ext-link[@ext-link-type="uri"]');
|
|
119
124
|
expect(link).not.toBeNull();
|
|
120
125
|
expect(link.text()).toBe('https//orcid.org/0000-0003-2217-5904');
|
|
@@ -129,20 +134,20 @@ describe('JATS exporter', () => {
|
|
|
129
134
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
130
135
|
const input = await (0, files_1.readAndParseFixture)('jats-example-doc.xml');
|
|
131
136
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
132
|
-
const
|
|
137
|
+
const document = await transformer.export(node, {
|
|
133
138
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
134
139
|
});
|
|
135
|
-
const { errors } = parseXMLWithDTD(
|
|
140
|
+
const { errors } = parseXMLWithDTD((0, w3c_xmlserializer_1.default)(document));
|
|
136
141
|
expect(errors).toHaveLength(0);
|
|
137
142
|
});
|
|
138
143
|
test('export with supplement', async () => {
|
|
139
144
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
140
145
|
const input = await (0, files_1.readAndParseFixture)('jats-import.xml');
|
|
141
146
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
142
|
-
const
|
|
147
|
+
const document = await transformer.export(node, {
|
|
143
148
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
144
149
|
});
|
|
145
|
-
const resultDoc = parseXMLWithDTD(
|
|
150
|
+
const resultDoc = parseXMLWithDTD((0, w3c_xmlserializer_1.default)(document));
|
|
146
151
|
const supplementaryMaterial = resultDoc.get('//supplementary-material');
|
|
147
152
|
if (!supplementaryMaterial) {
|
|
148
153
|
throw new Error('No supplementary material found');
|
|
@@ -169,9 +174,10 @@ describe('JATS exporter', () => {
|
|
|
169
174
|
n.attrs.rids.forEach((rid) => citedIDs.add(rid));
|
|
170
175
|
}
|
|
171
176
|
});
|
|
172
|
-
const
|
|
177
|
+
const document = await new jats_exporter_1.JATSExporter().export(node, {
|
|
173
178
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
174
179
|
});
|
|
180
|
+
const xml = (0, w3c_xmlserializer_1.default)(document);
|
|
175
181
|
const refCount = parseXMLWithDTD(xml).find('//ref-list/ref').length;
|
|
176
182
|
expect(refCount).toBe(bibliographyItemIDs.size);
|
|
177
183
|
const { errors } = parseXMLWithDTD(xml);
|
|
@@ -181,9 +187,10 @@ describe('JATS exporter', () => {
|
|
|
181
187
|
const transformer = new jats_exporter_1.JATSExporter();
|
|
182
188
|
const input = await (0, files_1.readAndParseFixture)('jats-fn-group.xml');
|
|
183
189
|
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
184
|
-
const
|
|
190
|
+
const document = await transformer.export(node, {
|
|
185
191
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
186
192
|
});
|
|
193
|
+
const xml = (0, w3c_xmlserializer_1.default)(document);
|
|
187
194
|
const footnoteCategories = [
|
|
188
195
|
'con',
|
|
189
196
|
'deceased',
|
|
@@ -14,8 +14,12 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
17
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
21
|
const libxmljs2_1 = require("libxmljs2");
|
|
22
|
+
const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
|
|
19
23
|
const jats_exporter_1 = require("../exporter/jats-exporter");
|
|
20
24
|
const parse_jats_article_1 = require("../importer/parse-jats-article");
|
|
21
25
|
const citations_1 = require("./citations");
|
|
@@ -31,9 +35,10 @@ const roundtrip = async (filename) => {
|
|
|
31
35
|
const doc = new DOMParser().parseFromString(input, 'application/xml');
|
|
32
36
|
const node = (0, parse_jats_article_1.parseJATSArticle)(doc, section_categories_1.sectionCategories);
|
|
33
37
|
const exporter = new jats_exporter_1.JATSExporter();
|
|
34
|
-
|
|
38
|
+
const document = await exporter.export(node, {
|
|
35
39
|
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
36
40
|
});
|
|
41
|
+
return (0, w3c_xmlserializer_1.default)(document);
|
|
37
42
|
};
|
|
38
43
|
describe('JATS roundtrip', () => {
|
|
39
44
|
test('jats-import.xml roundtrip', async () => {
|
|
@@ -47,15 +47,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
47
47
|
return result;
|
|
48
48
|
};
|
|
49
49
|
})();
|
|
50
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
-
};
|
|
53
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
51
|
exports.JATSExporter = exports.createCounter = void 0;
|
|
55
52
|
const Citeproc = __importStar(require("citeproc"));
|
|
56
53
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
57
54
|
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
58
|
-
const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
|
|
59
55
|
const citeproc_1 = require("../../lib/citeproc");
|
|
60
56
|
const credit_roles_1 = require("../../lib/credit-roles");
|
|
61
57
|
const footnotes_1 = require("../../lib/footnotes");
|
|
@@ -118,7 +114,7 @@ class JATSExporter {
|
|
|
118
114
|
this.nodesMap.set(type, nodes);
|
|
119
115
|
});
|
|
120
116
|
};
|
|
121
|
-
this.
|
|
117
|
+
this.export = async (manuscriptNode, options) => {
|
|
122
118
|
this.manuscriptNode = manuscriptNode;
|
|
123
119
|
this.populateNodesMap();
|
|
124
120
|
this.initCiteprocEngine(options);
|
|
@@ -149,7 +145,7 @@ class JATSExporter {
|
|
|
149
145
|
$article.appendChild($floatsGroup);
|
|
150
146
|
}
|
|
151
147
|
await this.rewriteIDs();
|
|
152
|
-
return
|
|
148
|
+
return this.document;
|
|
153
149
|
};
|
|
154
150
|
this.appendChildNodeOfType = ($element, node, type) => {
|
|
155
151
|
const childNode = this.getFirstChildOfType(type, node);
|
|
@@ -440,7 +436,7 @@ class JATSExporter {
|
|
|
440
436
|
const [, bibliography] = this.engine.makeBibliography();
|
|
441
437
|
const parser = new DOMParser();
|
|
442
438
|
bibliography.forEach((item) => {
|
|
443
|
-
const fragment = `<
|
|
439
|
+
const fragment = `<wrapper xmlns:xlink="${xml_1.XLINK_NAMESPACE}">${(0, xml_1.sanitizeXmlString)(item)}</wrapper>`;
|
|
444
440
|
const $ref = parser
|
|
445
441
|
.parseFromString(fragment, 'text/xml')
|
|
446
442
|
.querySelector('ref');
|
package/dist/cjs/version.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { parseXml } from 'libxmljs2';
|
|
17
|
+
import serializeToXML from 'w3c-xmlserializer';
|
|
17
18
|
import { JATSExporter } from '../exporter/jats-exporter';
|
|
18
19
|
import { parseJATSArticle } from '../importer/parse-jats-article';
|
|
19
20
|
import { DEFAULT_CSL_OPTIONS } from './citations';
|
|
@@ -30,10 +31,10 @@ describe('JATS exporter', () => {
|
|
|
30
31
|
const transformer = new JATSExporter();
|
|
31
32
|
const input = await readAndParseFixture('jats-example-full.xml');
|
|
32
33
|
const node = parseJATSArticle(input, sectionCategories);
|
|
33
|
-
const
|
|
34
|
+
const document = await transformer.export(node, {
|
|
34
35
|
csl: DEFAULT_CSL_OPTIONS,
|
|
35
36
|
});
|
|
36
|
-
expect(
|
|
37
|
+
expect(serializeToXML(document)).toMatchSnapshot('jats-export');
|
|
37
38
|
});
|
|
38
39
|
test('export with & and < in bibliography metadata', async () => {
|
|
39
40
|
const transformer = new JATSExporter();
|
|
@@ -46,27 +47,27 @@ describe('JATS exporter', () => {
|
|
|
46
47
|
}
|
|
47
48
|
});
|
|
48
49
|
biblio.attrs.title += ' & Sons 55 < 135';
|
|
49
|
-
const
|
|
50
|
+
const document = await transformer.export(node, {
|
|
50
51
|
csl: DEFAULT_CSL_OPTIONS,
|
|
51
52
|
});
|
|
52
|
-
expect(
|
|
53
|
+
expect(serializeToXML(document)).toMatchSnapshot('jats-export-with-xml-unsafe-in-biblios');
|
|
53
54
|
});
|
|
54
55
|
test('export v1.1', async () => {
|
|
55
56
|
const transformer = new JATSExporter();
|
|
56
57
|
const input = await readAndParseFixture('jats-example-full.xml');
|
|
57
58
|
const node = parseJATSArticle(input, sectionCategories);
|
|
58
|
-
const
|
|
59
|
+
const document = await transformer.export(node, {
|
|
59
60
|
csl: DEFAULT_CSL_OPTIONS,
|
|
60
61
|
version: '1.1',
|
|
61
62
|
});
|
|
62
|
-
expect(
|
|
63
|
+
expect(serializeToXML(document)).toMatchSnapshot('jats-export-1.1');
|
|
63
64
|
});
|
|
64
65
|
test('export unknown version', async () => {
|
|
65
66
|
const transformer = new JATSExporter();
|
|
66
67
|
const input = await readAndParseFixture('jats-example-full.xml');
|
|
67
68
|
const node = parseJATSArticle(input, sectionCategories);
|
|
68
69
|
await expect(async () => {
|
|
69
|
-
await transformer.
|
|
70
|
+
await transformer.export(node, {
|
|
70
71
|
csl: DEFAULT_CSL_OPTIONS,
|
|
71
72
|
version: '1.0',
|
|
72
73
|
});
|
|
@@ -76,9 +77,10 @@ describe('JATS exporter', () => {
|
|
|
76
77
|
const transformer = new JATSExporter();
|
|
77
78
|
const input = await readAndParseFixture('jats-tables-example.xml');
|
|
78
79
|
const node = parseJATSArticle(input, sectionCategories);
|
|
79
|
-
const
|
|
80
|
+
const document = await transformer.export(node, {
|
|
80
81
|
csl: DEFAULT_CSL_OPTIONS,
|
|
81
82
|
});
|
|
83
|
+
const xml = serializeToXML(document);
|
|
82
84
|
const resultDoc = parseXMLWithDTD(xml);
|
|
83
85
|
const tableWrapFoot = resultDoc.get('//table-wrap/table-wrap-foot');
|
|
84
86
|
const paragraph = resultDoc.get('//table-wrap/table-wrap-foot/p');
|
|
@@ -89,30 +91,30 @@ describe('JATS exporter', () => {
|
|
|
89
91
|
const transformer = new JATSExporter();
|
|
90
92
|
const input = await readAndParseFixture('jats-import.xml');
|
|
91
93
|
const node = parseJATSArticle(input, sectionCategories);
|
|
92
|
-
const
|
|
94
|
+
const document = await transformer.export(node, {
|
|
93
95
|
csl: DEFAULT_CSL_OPTIONS,
|
|
94
96
|
});
|
|
95
|
-
const { errors } = parseXMLWithDTD(
|
|
97
|
+
const { errors } = parseXMLWithDTD(serializeToXML(document));
|
|
96
98
|
expect(errors).toHaveLength(0);
|
|
97
99
|
});
|
|
98
100
|
test('DTD validation: article with title markup and citations', async () => {
|
|
99
101
|
const transformer = new JATSExporter();
|
|
100
102
|
const input = await readAndParseFixture('jats-document.xml');
|
|
101
103
|
const node = parseJATSArticle(input, sectionCategories);
|
|
102
|
-
const
|
|
104
|
+
const document = await transformer.export(node, {
|
|
103
105
|
csl: DEFAULT_CSL_OPTIONS,
|
|
104
106
|
});
|
|
105
|
-
const { errors } = parseXMLWithDTD(
|
|
107
|
+
const { errors } = parseXMLWithDTD(serializeToXML(document));
|
|
106
108
|
expect(errors).toHaveLength(0);
|
|
107
109
|
});
|
|
108
110
|
test('Export link', async () => {
|
|
109
111
|
const transformer = new JATSExporter();
|
|
110
112
|
const input = await readAndParseFixture('jats-import.xml');
|
|
111
113
|
const node = parseJATSArticle(input, sectionCategories);
|
|
112
|
-
const
|
|
114
|
+
const document = await transformer.export(node, {
|
|
113
115
|
csl: DEFAULT_CSL_OPTIONS,
|
|
114
116
|
});
|
|
115
|
-
const output = parseXMLWithDTD(
|
|
117
|
+
const output = parseXMLWithDTD(serializeToXML(document));
|
|
116
118
|
const link = output.get('//ext-link[@ext-link-type="uri"]');
|
|
117
119
|
expect(link).not.toBeNull();
|
|
118
120
|
expect(link.text()).toBe('https//orcid.org/0000-0003-2217-5904');
|
|
@@ -127,20 +129,20 @@ describe('JATS exporter', () => {
|
|
|
127
129
|
const transformer = new JATSExporter();
|
|
128
130
|
const input = await readAndParseFixture('jats-example-doc.xml');
|
|
129
131
|
const node = parseJATSArticle(input, sectionCategories);
|
|
130
|
-
const
|
|
132
|
+
const document = await transformer.export(node, {
|
|
131
133
|
csl: DEFAULT_CSL_OPTIONS,
|
|
132
134
|
});
|
|
133
|
-
const { errors } = parseXMLWithDTD(
|
|
135
|
+
const { errors } = parseXMLWithDTD(serializeToXML(document));
|
|
134
136
|
expect(errors).toHaveLength(0);
|
|
135
137
|
});
|
|
136
138
|
test('export with supplement', async () => {
|
|
137
139
|
const transformer = new JATSExporter();
|
|
138
140
|
const input = await readAndParseFixture('jats-import.xml');
|
|
139
141
|
const node = parseJATSArticle(input, sectionCategories);
|
|
140
|
-
const
|
|
142
|
+
const document = await transformer.export(node, {
|
|
141
143
|
csl: DEFAULT_CSL_OPTIONS,
|
|
142
144
|
});
|
|
143
|
-
const resultDoc = parseXMLWithDTD(
|
|
145
|
+
const resultDoc = parseXMLWithDTD(serializeToXML(document));
|
|
144
146
|
const supplementaryMaterial = resultDoc.get('//supplementary-material');
|
|
145
147
|
if (!supplementaryMaterial) {
|
|
146
148
|
throw new Error('No supplementary material found');
|
|
@@ -167,9 +169,10 @@ describe('JATS exporter', () => {
|
|
|
167
169
|
n.attrs.rids.forEach((rid) => citedIDs.add(rid));
|
|
168
170
|
}
|
|
169
171
|
});
|
|
170
|
-
const
|
|
172
|
+
const document = await new JATSExporter().export(node, {
|
|
171
173
|
csl: DEFAULT_CSL_OPTIONS,
|
|
172
174
|
});
|
|
175
|
+
const xml = serializeToXML(document);
|
|
173
176
|
const refCount = parseXMLWithDTD(xml).find('//ref-list/ref').length;
|
|
174
177
|
expect(refCount).toBe(bibliographyItemIDs.size);
|
|
175
178
|
const { errors } = parseXMLWithDTD(xml);
|
|
@@ -179,9 +182,10 @@ describe('JATS exporter', () => {
|
|
|
179
182
|
const transformer = new JATSExporter();
|
|
180
183
|
const input = await readAndParseFixture('jats-fn-group.xml');
|
|
181
184
|
const node = parseJATSArticle(input, sectionCategories);
|
|
182
|
-
const
|
|
185
|
+
const document = await transformer.export(node, {
|
|
183
186
|
csl: DEFAULT_CSL_OPTIONS,
|
|
184
187
|
});
|
|
188
|
+
const xml = serializeToXML(document);
|
|
185
189
|
const footnoteCategories = [
|
|
186
190
|
'con',
|
|
187
191
|
'deceased',
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { parseXml } from 'libxmljs2';
|
|
17
|
+
import serializeToXML from 'w3c-xmlserializer';
|
|
17
18
|
import { JATSExporter } from '../exporter/jats-exporter';
|
|
18
19
|
import { parseJATSArticle } from '../importer/parse-jats-article';
|
|
19
20
|
import { DEFAULT_CSL_OPTIONS } from './citations';
|
|
@@ -29,9 +30,10 @@ const roundtrip = async (filename) => {
|
|
|
29
30
|
const doc = new DOMParser().parseFromString(input, 'application/xml');
|
|
30
31
|
const node = parseJATSArticle(doc, sectionCategories);
|
|
31
32
|
const exporter = new JATSExporter();
|
|
32
|
-
|
|
33
|
+
const document = await exporter.export(node, {
|
|
33
34
|
csl: DEFAULT_CSL_OPTIONS,
|
|
34
35
|
});
|
|
36
|
+
return serializeToXML(document);
|
|
35
37
|
};
|
|
36
38
|
describe('JATS roundtrip', () => {
|
|
37
39
|
test('jats-import.xml roundtrip', async () => {
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
import * as Citeproc from 'citeproc';
|
|
17
17
|
import { DOMSerializer } from 'prosemirror-model';
|
|
18
18
|
import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils';
|
|
19
|
-
import serializeToXML from 'w3c-xmlserializer';
|
|
20
19
|
import { buildCiteprocCitation } from '../../lib/citeproc';
|
|
21
20
|
import { CreditRoleUrls } from '../../lib/credit-roles';
|
|
22
21
|
import { generateFootnoteLabels } from '../../lib/footnotes';
|
|
@@ -78,7 +77,7 @@ export class JATSExporter {
|
|
|
78
77
|
this.nodesMap.set(type, nodes);
|
|
79
78
|
});
|
|
80
79
|
};
|
|
81
|
-
this.
|
|
80
|
+
this.export = async (manuscriptNode, options) => {
|
|
82
81
|
this.manuscriptNode = manuscriptNode;
|
|
83
82
|
this.populateNodesMap();
|
|
84
83
|
this.initCiteprocEngine(options);
|
|
@@ -109,7 +108,7 @@ export class JATSExporter {
|
|
|
109
108
|
$article.appendChild($floatsGroup);
|
|
110
109
|
}
|
|
111
110
|
await this.rewriteIDs();
|
|
112
|
-
return
|
|
111
|
+
return this.document;
|
|
113
112
|
};
|
|
114
113
|
this.appendChildNodeOfType = ($element, node, type) => {
|
|
115
114
|
const childNode = this.getFirstChildOfType(type, node);
|
|
@@ -400,7 +399,7 @@ export class JATSExporter {
|
|
|
400
399
|
const [, bibliography] = this.engine.makeBibliography();
|
|
401
400
|
const parser = new DOMParser();
|
|
402
401
|
bibliography.forEach((item) => {
|
|
403
|
-
const fragment = `<
|
|
402
|
+
const fragment = `<wrapper xmlns:xlink="${XLINK_NAMESPACE}">${sanitizeXmlString(item)}</wrapper>`;
|
|
404
403
|
const $ref = parser
|
|
405
404
|
.parseFromString(fragment, 'text/xml')
|
|
406
405
|
.querySelector('ref');
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "4.5.
|
|
1
|
+
export const VERSION = "4.5.8";
|
|
@@ -42,7 +42,7 @@ export declare class JATSExporter {
|
|
|
42
42
|
private populateNodesMap;
|
|
43
43
|
protected getFirstChildOfType<T extends ManuscriptNode>(type: NodeType, node?: ManuscriptNode): T | undefined;
|
|
44
44
|
protected getChildrenOfType<T extends ManuscriptNode>(type: NodeType, node?: ManuscriptNode): T[];
|
|
45
|
-
|
|
45
|
+
export: (manuscriptNode: ActualManuscriptNode, options: ExportOptions) => Promise<Document>;
|
|
46
46
|
private appendChildNodeOfType;
|
|
47
47
|
private appendChildrenNodeOfType;
|
|
48
48
|
protected appendCaption: ($element: Element, node: ManuscriptNode) => void;
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.5.
|
|
1
|
+
export declare const VERSION = "4.5.8";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manuscripts/transform",
|
|
3
3
|
"description": "ProseMirror transformer for Manuscripts applications",
|
|
4
|
-
"version": "4.5.
|
|
4
|
+
"version": "4.5.8",
|
|
5
5
|
"repository": "github:Atypon-OpenSource/manuscripts-transform",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "dist/cjs",
|
|
@@ -39,8 +39,7 @@
|
|
|
39
39
|
"prosemirror-tables": "1.7.1",
|
|
40
40
|
"prosemirror-utils": "1.2.2",
|
|
41
41
|
"semver": "7.7.4",
|
|
42
|
-
"uuid": "14.0.0"
|
|
43
|
-
"w3c-xmlserializer": "5.0.0"
|
|
42
|
+
"uuid": "14.0.0"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
45
|
"@eslint/eslintrc": "3.3.5",
|
|
@@ -80,7 +79,8 @@
|
|
|
80
79
|
"prosemirror-state": "1.4.3",
|
|
81
80
|
"prosemirror-view": "1.39.2",
|
|
82
81
|
"rimraf": "6.1.3",
|
|
83
|
-
"typescript": "6.0.3"
|
|
82
|
+
"typescript": "6.0.3",
|
|
83
|
+
"w3c-xmlserializer": "5.0.0"
|
|
84
84
|
},
|
|
85
85
|
"engines": {
|
|
86
86
|
"node": ">=22"
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { Element as XMLElement, parseXml } from 'libxmljs2'
|
|
18
|
+
import serializeToXML from 'w3c-xmlserializer'
|
|
18
19
|
|
|
19
20
|
import { JATSExporter } from '../exporter/jats-exporter'
|
|
20
21
|
import { Version } from '../exporter/jats-versions'
|
|
@@ -40,11 +41,11 @@ describe('JATS exporter', () => {
|
|
|
40
41
|
const transformer = new JATSExporter()
|
|
41
42
|
const input = await readAndParseFixture('jats-example-full.xml')
|
|
42
43
|
const node = parseJATSArticle(input, sectionCategories)
|
|
43
|
-
const
|
|
44
|
+
const document = await transformer.export(node, {
|
|
44
45
|
csl: DEFAULT_CSL_OPTIONS,
|
|
45
46
|
})
|
|
46
47
|
|
|
47
|
-
expect(
|
|
48
|
+
expect(serializeToXML(document)).toMatchSnapshot('jats-export')
|
|
48
49
|
})
|
|
49
50
|
|
|
50
51
|
test('export with & and < in bibliography metadata', async () => {
|
|
@@ -61,23 +62,25 @@ describe('JATS exporter', () => {
|
|
|
61
62
|
|
|
62
63
|
biblio!.attrs.title += ' & Sons 55 < 135'
|
|
63
64
|
|
|
64
|
-
const
|
|
65
|
+
const document = await transformer.export(node, {
|
|
65
66
|
csl: DEFAULT_CSL_OPTIONS,
|
|
66
67
|
})
|
|
67
68
|
|
|
68
|
-
expect(
|
|
69
|
+
expect(serializeToXML(document)).toMatchSnapshot(
|
|
70
|
+
'jats-export-with-xml-unsafe-in-biblios'
|
|
71
|
+
)
|
|
69
72
|
})
|
|
70
73
|
|
|
71
74
|
test('export v1.1', async () => {
|
|
72
75
|
const transformer = new JATSExporter()
|
|
73
76
|
const input = await readAndParseFixture('jats-example-full.xml')
|
|
74
77
|
const node = parseJATSArticle(input, sectionCategories)
|
|
75
|
-
const
|
|
78
|
+
const document = await transformer.export(node, {
|
|
76
79
|
csl: DEFAULT_CSL_OPTIONS,
|
|
77
80
|
version: '1.1',
|
|
78
81
|
})
|
|
79
82
|
|
|
80
|
-
expect(
|
|
83
|
+
expect(serializeToXML(document)).toMatchSnapshot('jats-export-1.1')
|
|
81
84
|
})
|
|
82
85
|
|
|
83
86
|
test('export unknown version', async () => {
|
|
@@ -86,7 +89,7 @@ describe('JATS exporter', () => {
|
|
|
86
89
|
const node = parseJATSArticle(input, sectionCategories)
|
|
87
90
|
|
|
88
91
|
await expect(async () => {
|
|
89
|
-
await transformer.
|
|
92
|
+
await transformer.export(node, {
|
|
90
93
|
csl: DEFAULT_CSL_OPTIONS,
|
|
91
94
|
version: '1.0' as unknown as Version,
|
|
92
95
|
})
|
|
@@ -96,9 +99,10 @@ describe('JATS exporter', () => {
|
|
|
96
99
|
const transformer = new JATSExporter()
|
|
97
100
|
const input = await readAndParseFixture('jats-tables-example.xml')
|
|
98
101
|
const node = parseJATSArticle(input, sectionCategories)
|
|
99
|
-
const
|
|
102
|
+
const document = await transformer.export(node, {
|
|
100
103
|
csl: DEFAULT_CSL_OPTIONS,
|
|
101
104
|
})
|
|
105
|
+
const xml = serializeToXML(document)
|
|
102
106
|
|
|
103
107
|
const resultDoc = parseXMLWithDTD(xml)
|
|
104
108
|
const tableWrapFoot = resultDoc.get('//table-wrap/table-wrap-foot')
|
|
@@ -111,11 +115,11 @@ describe('JATS exporter', () => {
|
|
|
111
115
|
const transformer = new JATSExporter()
|
|
112
116
|
const input = await readAndParseFixture('jats-import.xml')
|
|
113
117
|
const node = parseJATSArticle(input, sectionCategories)
|
|
114
|
-
const
|
|
118
|
+
const document = await transformer.export(node, {
|
|
115
119
|
csl: DEFAULT_CSL_OPTIONS,
|
|
116
120
|
})
|
|
117
121
|
|
|
118
|
-
const { errors } = parseXMLWithDTD(
|
|
122
|
+
const { errors } = parseXMLWithDTD(serializeToXML(document))
|
|
119
123
|
|
|
120
124
|
expect(errors).toHaveLength(0)
|
|
121
125
|
})
|
|
@@ -124,10 +128,10 @@ describe('JATS exporter', () => {
|
|
|
124
128
|
const transformer = new JATSExporter()
|
|
125
129
|
const input = await readAndParseFixture('jats-document.xml')
|
|
126
130
|
const node = parseJATSArticle(input, sectionCategories)
|
|
127
|
-
const
|
|
131
|
+
const document = await transformer.export(node, {
|
|
128
132
|
csl: DEFAULT_CSL_OPTIONS,
|
|
129
133
|
})
|
|
130
|
-
const { errors } = parseXMLWithDTD(
|
|
134
|
+
const { errors } = parseXMLWithDTD(serializeToXML(document))
|
|
131
135
|
|
|
132
136
|
expect(errors).toHaveLength(0)
|
|
133
137
|
})
|
|
@@ -136,11 +140,11 @@ describe('JATS exporter', () => {
|
|
|
136
140
|
const transformer = new JATSExporter()
|
|
137
141
|
const input = await readAndParseFixture('jats-import.xml')
|
|
138
142
|
const node = parseJATSArticle(input, sectionCategories)
|
|
139
|
-
const
|
|
143
|
+
const document = await transformer.export(node, {
|
|
140
144
|
csl: DEFAULT_CSL_OPTIONS,
|
|
141
145
|
})
|
|
142
146
|
|
|
143
|
-
const output = parseXMLWithDTD(
|
|
147
|
+
const output = parseXMLWithDTD(serializeToXML(document))
|
|
144
148
|
const link = output.get<XMLElement>('//ext-link[@ext-link-type="uri"]')
|
|
145
149
|
expect(link).not.toBeNull()
|
|
146
150
|
expect(link!.text()).toBe('https//orcid.org/0000-0003-2217-5904')
|
|
@@ -159,11 +163,11 @@ describe('JATS exporter', () => {
|
|
|
159
163
|
const transformer = new JATSExporter()
|
|
160
164
|
const input = await readAndParseFixture('jats-example-doc.xml')
|
|
161
165
|
const node = parseJATSArticle(input, sectionCategories)
|
|
162
|
-
const
|
|
166
|
+
const document = await transformer.export(node, {
|
|
163
167
|
csl: DEFAULT_CSL_OPTIONS,
|
|
164
168
|
})
|
|
165
169
|
|
|
166
|
-
const { errors } = parseXMLWithDTD(
|
|
170
|
+
const { errors } = parseXMLWithDTD(serializeToXML(document))
|
|
167
171
|
|
|
168
172
|
expect(errors).toHaveLength(0)
|
|
169
173
|
})
|
|
@@ -172,10 +176,10 @@ describe('JATS exporter', () => {
|
|
|
172
176
|
const transformer = new JATSExporter()
|
|
173
177
|
const input = await readAndParseFixture('jats-import.xml')
|
|
174
178
|
const node = parseJATSArticle(input, sectionCategories)
|
|
175
|
-
const
|
|
179
|
+
const document = await transformer.export(node, {
|
|
176
180
|
csl: DEFAULT_CSL_OPTIONS,
|
|
177
181
|
})
|
|
178
|
-
const resultDoc = parseXMLWithDTD(
|
|
182
|
+
const resultDoc = parseXMLWithDTD(serializeToXML(document))
|
|
179
183
|
const supplementaryMaterial = resultDoc.get('//supplementary-material')
|
|
180
184
|
if (!supplementaryMaterial) {
|
|
181
185
|
throw new Error('No supplementary material found')
|
|
@@ -215,9 +219,10 @@ describe('JATS exporter', () => {
|
|
|
215
219
|
n.attrs.rids.forEach((rid: string) => citedIDs.add(rid))
|
|
216
220
|
}
|
|
217
221
|
})
|
|
218
|
-
const
|
|
222
|
+
const document = await new JATSExporter().export(node, {
|
|
219
223
|
csl: DEFAULT_CSL_OPTIONS,
|
|
220
224
|
})
|
|
225
|
+
const xml = serializeToXML(document)
|
|
221
226
|
const refCount = parseXMLWithDTD(xml).find('//ref-list/ref').length
|
|
222
227
|
expect(refCount).toBe(bibliographyItemIDs.size)
|
|
223
228
|
const { errors } = parseXMLWithDTD(xml)
|
|
@@ -228,9 +233,10 @@ describe('JATS exporter', () => {
|
|
|
228
233
|
const transformer = new JATSExporter()
|
|
229
234
|
const input = await readAndParseFixture('jats-fn-group.xml')
|
|
230
235
|
const node = parseJATSArticle(input, sectionCategories)
|
|
231
|
-
const
|
|
236
|
+
const document = await transformer.export(node, {
|
|
232
237
|
csl: DEFAULT_CSL_OPTIONS,
|
|
233
238
|
})
|
|
239
|
+
const xml = serializeToXML(document)
|
|
234
240
|
const footnoteCategories = [
|
|
235
241
|
'con',
|
|
236
242
|
'deceased',
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { parseXml } from 'libxmljs2'
|
|
18
|
+
import serializeToXML from 'w3c-xmlserializer'
|
|
18
19
|
|
|
19
20
|
import { JATSExporter } from '../exporter/jats-exporter'
|
|
20
21
|
import { parseJATSArticle } from '../importer/parse-jats-article'
|
|
@@ -36,9 +37,10 @@ const roundtrip = async (filename: string) => {
|
|
|
36
37
|
const node = parseJATSArticle(doc, sectionCategories)
|
|
37
38
|
|
|
38
39
|
const exporter = new JATSExporter()
|
|
39
|
-
|
|
40
|
+
const document = await exporter.export(node, {
|
|
40
41
|
csl: DEFAULT_CSL_OPTIONS,
|
|
41
42
|
})
|
|
43
|
+
return serializeToXML(document)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
describe('JATS roundtrip', () => {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
import * as Citeproc from 'citeproc'
|
|
18
18
|
import { DOMOutputSpec, DOMSerializer, type NodeType } from 'prosemirror-model'
|
|
19
19
|
import { findChildrenByAttr, findChildrenByType } from 'prosemirror-utils'
|
|
20
|
-
import serializeToXML from 'w3c-xmlserializer'
|
|
21
20
|
|
|
22
21
|
import { buildCiteprocCitation } from '../../lib/citeproc'
|
|
23
22
|
import { CreditRoleUrls } from '../../lib/credit-roles'
|
|
@@ -163,10 +162,10 @@ export class JATSExporter {
|
|
|
163
162
|
return (nodes ?? []).filter((n): n is T => isNodeOfType<T>(n, type))
|
|
164
163
|
}
|
|
165
164
|
|
|
166
|
-
public
|
|
165
|
+
public export = async (
|
|
167
166
|
manuscriptNode: ActualManuscriptNode,
|
|
168
167
|
options: ExportOptions
|
|
169
|
-
): Promise<
|
|
168
|
+
): Promise<Document> => {
|
|
170
169
|
this.manuscriptNode = manuscriptNode
|
|
171
170
|
this.populateNodesMap()
|
|
172
171
|
this.initCiteprocEngine(options)
|
|
@@ -223,7 +222,7 @@ export class JATSExporter {
|
|
|
223
222
|
$article.appendChild($floatsGroup)
|
|
224
223
|
}
|
|
225
224
|
await this.rewriteIDs()
|
|
226
|
-
return
|
|
225
|
+
return this.document
|
|
227
226
|
}
|
|
228
227
|
|
|
229
228
|
private appendChildNodeOfType = (
|
|
@@ -616,9 +615,9 @@ export class JATSExporter {
|
|
|
616
615
|
const [, bibliography] = this.engine.makeBibliography()
|
|
617
616
|
const parser = new DOMParser()
|
|
618
617
|
bibliography.forEach((item) => {
|
|
619
|
-
const fragment = `<
|
|
618
|
+
const fragment = `<wrapper xmlns:xlink="${XLINK_NAMESPACE}">${sanitizeXmlString(
|
|
620
619
|
item
|
|
621
|
-
)}</
|
|
620
|
+
)}</wrapper>`
|
|
622
621
|
const $ref = parser
|
|
623
622
|
.parseFromString(fragment, 'text/xml')
|
|
624
623
|
.querySelector('ref')
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "4.5.
|
|
1
|
+
export const VERSION = "4.5.8";
|