@manuscripts/transform 4.5.7 → 4.6.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/jats/__tests__/jats-exporter.test.js +50 -20
- package/dist/cjs/jats/__tests__/jats-importer.test.js +26 -0
- package/dist/cjs/jats/__tests__/jats-roundtrip.test.js +6 -1
- package/dist/cjs/jats/exporter/JATSExporterBase.js +118 -0
- package/dist/cjs/jats/exporter/jats-exporter.js +227 -349
- package/dist/cjs/jats/exporter/lib.js +62 -0
- package/dist/cjs/jats/importer/jats-dom-parser.js +11 -3
- package/dist/cjs/schema/index.js +4 -1
- package/dist/cjs/schema/migration/migration-scripts/4.5.9.js +30 -0
- package/dist/cjs/schema/migration/migration-scripts/index.js +3 -1
- package/dist/cjs/schema/nodes/bibliography_element.js +0 -1
- package/dist/cjs/schema/nodes/bio.js +24 -0
- package/dist/cjs/schema/nodes/contributor.js +1 -2
- package/dist/cjs/schema/nodes/keywords_element.js +0 -1
- package/dist/cjs/types.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/es/jats/__tests__/jats-exporter.test.js +47 -20
- package/dist/es/jats/__tests__/jats-importer.test.js +26 -0
- package/dist/es/jats/__tests__/jats-roundtrip.test.js +3 -1
- package/dist/es/jats/exporter/JATSExporterBase.js +114 -0
- package/dist/es/jats/exporter/jats-exporter.js +201 -319
- package/dist/es/jats/exporter/lib.js +55 -0
- package/dist/es/jats/importer/jats-dom-parser.js +11 -3
- package/dist/es/schema/index.js +4 -1
- package/dist/es/schema/migration/migration-scripts/4.5.9.js +28 -0
- package/dist/es/schema/migration/migration-scripts/index.js +3 -1
- package/dist/es/schema/nodes/bibliography_element.js +0 -1
- package/dist/es/schema/nodes/bio.js +20 -0
- package/dist/es/schema/nodes/contributor.js +1 -2
- package/dist/es/schema/nodes/keywords_element.js +0 -1
- package/dist/es/types.js +1 -1
- package/dist/es/version.js +1 -1
- package/dist/types/jats/exporter/JATSExporterBase.d.ts +35 -0
- package/dist/types/jats/exporter/jats-exporter.d.ts +23 -19
- package/dist/types/jats/exporter/lib.d.ts +23 -0
- package/dist/types/schema/index.d.ts +2 -1
- package/dist/types/schema/migration/migration-scripts/4.5.9.d.ts +8 -0
- package/dist/types/schema/migration/migration-scripts/index.d.ts +3 -2
- package/dist/types/schema/nodes/bio.d.ts +10 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/types.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/jats/__tests__/__fixtures__/jats-import.xml +7 -0
- package/src/jats/__tests__/__snapshots__/jats-importer.test.ts.snap +272 -151
- package/src/jats/__tests__/__snapshots__/jats-roundtrip.test.ts.snap +2 -2
- package/src/jats/__tests__/jats-exporter.test.ts +60 -20
- package/src/jats/__tests__/jats-importer.test.ts +37 -0
- package/src/jats/__tests__/jats-roundtrip.test.ts +3 -1
- package/src/jats/exporter/JATSExporterBase.ts +164 -0
- package/src/jats/exporter/jats-exporter.ts +217 -386
- package/src/jats/exporter/lib.ts +69 -0
- package/src/jats/importer/jats-dom-parser.ts +15 -5
- package/src/schema/index.ts +4 -1
- package/src/schema/migration/migration-scripts/4.5.9.ts +62 -0
- package/src/schema/migration/migration-scripts/index.ts +3 -1
- package/src/schema/nodes/bibliography_element.ts +0 -1
- package/src/schema/nodes/bio.ts +48 -0
- package/src/schema/nodes/contributor.ts +1 -2
- package/src/schema/nodes/keywords_element.ts +0 -1
- package/src/schema/types.ts +1 -0
- package/src/types.ts +1 -1
- 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',
|
|
@@ -196,4 +203,27 @@ describe('JATS exporter', () => {
|
|
|
196
203
|
expect(fn).not.toBeUndefined();
|
|
197
204
|
}
|
|
198
205
|
});
|
|
206
|
+
test('export contributor bio', async () => {
|
|
207
|
+
const transformer = new jats_exporter_1.JATSExporter();
|
|
208
|
+
const input = await (0, files_1.readAndParseFixture)('jats-import.xml');
|
|
209
|
+
const node = (0, parse_jats_article_1.parseJATSArticle)(input, section_categories_1.sectionCategories);
|
|
210
|
+
const xml = await transformer.export(node, {
|
|
211
|
+
csl: citations_1.DEFAULT_CSL_OPTIONS,
|
|
212
|
+
});
|
|
213
|
+
const serialized = (0, w3c_xmlserializer_1.default)(xml);
|
|
214
|
+
const resultDoc = parseXMLWithDTD(serialized);
|
|
215
|
+
expect(resultDoc.errors).toHaveLength(0);
|
|
216
|
+
const contribs = resultDoc.find('//contrib-group/contrib');
|
|
217
|
+
expect(contribs).toHaveLength(2);
|
|
218
|
+
expect(contribs[0].find('bio')).toHaveLength(1);
|
|
219
|
+
expect(contribs[1].find('bio')).toHaveLength(0);
|
|
220
|
+
const graphic = resultDoc.get('//contrib/bio/graphic');
|
|
221
|
+
expect(graphic).not.toBeNull();
|
|
222
|
+
expect(graphic.attr('href')?.value()).toBe('agnete-hornnes.png');
|
|
223
|
+
expect(graphic.find('caption')).toHaveLength(0);
|
|
224
|
+
expect(resultDoc.get('//contrib/bio/graphic/alt-text').text()).toBe('Headshot of Agnete Hviid Hornnes');
|
|
225
|
+
const paragraph = resultDoc.get('//contrib/bio/p');
|
|
226
|
+
expect(paragraph.text()).toBe('Agnete is a Professor of Neurology at Herlev og Gentofte Hospital, specializing in stroke research.');
|
|
227
|
+
expect(resultDoc.get('//contrib/bio/p/italic')?.text()).toBe('Professor of Neurology');
|
|
228
|
+
});
|
|
199
229
|
});
|
|
@@ -60,6 +60,32 @@ describe('JATS importer', () => {
|
|
|
60
60
|
expect(contributorsNode).toHaveLength(0);
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
|
+
describe('bio', () => {
|
|
64
|
+
it('should parse bio with graphic and paragraph into the contributor node', async () => {
|
|
65
|
+
const jats = await (0, files_1.readAndParseFixture)('jats-import.xml');
|
|
66
|
+
const node = (0, parse_jats_article_1.parseJATSArticle)(jats, section_categories_1.sectionCategories);
|
|
67
|
+
(0, utils_1.changeIDs)(node);
|
|
68
|
+
const [contributor] = (0, utils_1.findNodesByType)(node, schema_1.schema.nodes.contributor);
|
|
69
|
+
expect(contributor.childCount).toBe(1);
|
|
70
|
+
const bio = contributor.firstChild;
|
|
71
|
+
expect(bio.type).toBe(schema_1.schema.nodes.bio);
|
|
72
|
+
expect(bio.childCount).toBe(2);
|
|
73
|
+
const image = (0, utils_1.findNodeByType)(bio, schema_1.schema.nodes.image_element);
|
|
74
|
+
expect((0, utils_1.findNodeByType)(image, schema_1.schema.nodes.figure).attrs.src).toBe('agnete-hornnes.png');
|
|
75
|
+
expect((0, utils_1.findNodeByType)(image, schema_1.schema.nodes.alt_text).textContent).toBe('Headshot of Agnete Hviid Hornnes');
|
|
76
|
+
const paragraph = bio.lastChild;
|
|
77
|
+
expect(paragraph.type).toBe(schema_1.schema.nodes.paragraph);
|
|
78
|
+
expect(paragraph.textContent).toBe('Agnete is a Professor of Neurology at Herlev og Gentofte Hospital, specializing in stroke research.');
|
|
79
|
+
expect(bio).toMatchSnapshot();
|
|
80
|
+
});
|
|
81
|
+
it('should not add bio content to contributors without a bio element', async () => {
|
|
82
|
+
const jats = await (0, files_1.readAndParseFixture)('jats-import.xml');
|
|
83
|
+
const node = (0, parse_jats_article_1.parseJATSArticle)(jats, section_categories_1.sectionCategories);
|
|
84
|
+
const [, contributor] = (0, utils_1.findNodesByType)(node, schema_1.schema.nodes.contributor);
|
|
85
|
+
expect(contributor.childCount).toBe(0);
|
|
86
|
+
expect((0, utils_1.findNodesByType)(node, schema_1.schema.nodes.bio)).toHaveLength(1);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
63
89
|
describe('affiliations', () => {
|
|
64
90
|
it('should correctly parse affiliation nodes', async () => {
|
|
65
91
|
const jats = await (0, files_1.readAndParseFixture)('jats-import.xml');
|
|
@@ -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 () => {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* © 2026 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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.JATSExporterBase = void 0;
|
|
19
|
+
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
20
|
+
const schema_1 = require("../../schema");
|
|
21
|
+
const lib_1 = require("./lib");
|
|
22
|
+
class JATSExporterBase {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.nodesMap = new Map();
|
|
25
|
+
this.populateNodesMap = () => {
|
|
26
|
+
this.manuscriptNode.descendants((node) => {
|
|
27
|
+
const type = node.type;
|
|
28
|
+
const nodes = this.nodesMap.get(type) ?? [];
|
|
29
|
+
nodes.push(node);
|
|
30
|
+
this.nodesMap.set(type, nodes);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
this.createElement = (tag, content, attrs) => {
|
|
34
|
+
const $element = this.document.createElement(tag);
|
|
35
|
+
if (content) {
|
|
36
|
+
$element.textContent = content;
|
|
37
|
+
}
|
|
38
|
+
if (attrs) {
|
|
39
|
+
Object.entries(attrs).forEach(([k, v]) => {
|
|
40
|
+
if (v) {
|
|
41
|
+
$element.setAttribute(k, v);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return $element;
|
|
46
|
+
};
|
|
47
|
+
this.appendElement = ($parent, tag, content, attrs) => {
|
|
48
|
+
const $element = this.createElement(tag, content, attrs);
|
|
49
|
+
$parent.appendChild($element);
|
|
50
|
+
return $element;
|
|
51
|
+
};
|
|
52
|
+
this.changeTag = ($node, tag) => {
|
|
53
|
+
const $clone = this.createElement(tag);
|
|
54
|
+
for (const attr of $node.attributes) {
|
|
55
|
+
$clone.setAttributeNS(null, attr.name, attr.value);
|
|
56
|
+
}
|
|
57
|
+
while ($node.firstChild) {
|
|
58
|
+
$clone.appendChild($node.firstChild);
|
|
59
|
+
}
|
|
60
|
+
$node.replaceWith($clone);
|
|
61
|
+
return $clone;
|
|
62
|
+
};
|
|
63
|
+
this.processChildNodes = ($element, node, contentNodeType) => {
|
|
64
|
+
node.forEach((childNode) => {
|
|
65
|
+
if (childNode.type === contentNodeType) {
|
|
66
|
+
if (childNode.attrs.id) {
|
|
67
|
+
$element.appendChild(this.serializeNode(childNode));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (childNode.type === node.type.schema.nodes.paragraph) {
|
|
71
|
+
$element.appendChild(this.serializeNode(childNode));
|
|
72
|
+
}
|
|
73
|
+
else if (childNode.type === node.type.schema.nodes.missing_figure) {
|
|
74
|
+
$element.appendChild(this.serializeNode(childNode));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
isChildOfNodeType(targetID, type, descend = false) {
|
|
80
|
+
const nodes = this.getChildrenOfType(type);
|
|
81
|
+
return nodes.some((node) => {
|
|
82
|
+
const result = (0, prosemirror_utils_1.findChildrenByAttr)(node, (attrs) => attrs.id === targetID, descend)[0];
|
|
83
|
+
return !!result;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
getChildrenOfType(type, node) {
|
|
87
|
+
const nodes = node
|
|
88
|
+
? (0, prosemirror_utils_1.findChildrenByType)(node, type).map(({ node }) => node)
|
|
89
|
+
: this.nodesMap.get(type);
|
|
90
|
+
return (nodes ?? []).filter((n) => (0, schema_1.isNodeOfType)(n, type));
|
|
91
|
+
}
|
|
92
|
+
getFirstChildOfType(type, node) {
|
|
93
|
+
return this.getChildrenOfType(type, node)[0];
|
|
94
|
+
}
|
|
95
|
+
fillEmptyElements($article, selector, tagName = 'p') {
|
|
96
|
+
const $empty = Array.from($article.querySelectorAll(selector)).filter(($el) => !$el.innerHTML);
|
|
97
|
+
$empty.forEach(($element) => $element.appendChild(this.createElement(tagName)));
|
|
98
|
+
}
|
|
99
|
+
createElementWithID(node, nodeName) {
|
|
100
|
+
const $element = this.createElement(nodeName);
|
|
101
|
+
$element.setAttribute('id', (0, lib_1.normalizeID)(node.attrs.id));
|
|
102
|
+
return $element;
|
|
103
|
+
}
|
|
104
|
+
serializeNode(node) {
|
|
105
|
+
return this.serializer.serializeNode(node, {
|
|
106
|
+
document: this.document,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
appendChildIfPresent($parent, tagName, textContent) {
|
|
110
|
+
if (!textContent) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const $element = this.createElement(tagName);
|
|
114
|
+
$element.textContent = textContent;
|
|
115
|
+
$parent.appendChild($element);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.JATSExporterBase = JATSExporterBase;
|