@manuscripts/transform 4.5.8 → 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 +23 -0
- package/dist/cjs/jats/__tests__/jats-importer.test.js +26 -0
- package/dist/cjs/jats/exporter/JATSExporterBase.js +118 -0
- package/dist/cjs/jats/exporter/jats-exporter.js +224 -342
- 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 +23 -0
- package/dist/es/jats/__tests__/jats-importer.test.js +26 -0
- package/dist/es/jats/exporter/JATSExporterBase.js +114 -0
- package/dist/es/jats/exporter/jats-exporter.js +198 -315
- 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 +22 -18
- 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 +1 -1
- 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 +34 -0
- package/src/jats/__tests__/jats-importer.test.ts +37 -0
- package/src/jats/exporter/JATSExporterBase.ts +164 -0
- package/src/jats/exporter/jats-exporter.ts +212 -380
- 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
|
@@ -203,4 +203,27 @@ describe('JATS exporter', () => {
|
|
|
203
203
|
expect(fn).not.toBeUndefined();
|
|
204
204
|
}
|
|
205
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
|
+
});
|
|
206
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');
|
|
@@ -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;
|