@manuscripts/transform 2.1.1 → 2.1.2-LEAN-3092-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/jats/importer/jats-body-dom-parser.js +27 -72
- package/dist/cjs/jats/importer/jats-body-transformations.js +10 -0
- package/dist/cjs/jats/importer/jats-parser-utils.js +6 -0
- package/dist/cjs/jats/importer/parse-jats-article.js +1 -0
- package/dist/cjs/jats/jats-exporter.js +30 -38
- package/dist/cjs/schema/index.js +0 -1
- package/dist/cjs/schema/nodes/equation.js +12 -14
- package/dist/cjs/schema/nodes/equation_element.js +4 -5
- package/dist/cjs/schema/nodes/inline_equation.js +13 -15
- package/dist/cjs/transformer/builders.js +3 -9
- package/dist/cjs/transformer/decode.js +22 -24
- package/dist/cjs/transformer/encode.js +14 -25
- package/dist/cjs/transformer/footnotes-order.js +1 -4
- package/dist/cjs/transformer/node-types.js +0 -1
- package/dist/cjs/transformer/object-types.js +0 -1
- package/dist/es/index.js +0 -1
- package/dist/es/jats/importer/jats-body-dom-parser.js +28 -73
- package/dist/es/jats/importer/jats-body-transformations.js +10 -0
- package/dist/es/jats/importer/jats-parser-utils.js +6 -0
- package/dist/es/jats/importer/parse-jats-article.js +1 -0
- package/dist/es/jats/jats-exporter.js +30 -38
- package/dist/es/schema/index.js +0 -1
- package/dist/es/schema/nodes/equation.js +12 -14
- package/dist/es/schema/nodes/equation_element.js +4 -5
- package/dist/es/schema/nodes/inline_equation.js +13 -15
- package/dist/es/transformer/builders.js +2 -7
- package/dist/es/transformer/decode.js +23 -25
- package/dist/es/transformer/encode.js +15 -26
- package/dist/es/transformer/footnotes-order.js +0 -2
- package/dist/es/transformer/node-types.js +0 -1
- package/dist/es/transformer/object-types.js +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/jats/importer/jats-body-transformations.d.ts +1 -0
- package/dist/types/jats/jats-exporter.d.ts +1 -0
- package/dist/types/schema/index.d.ts +0 -1
- package/dist/types/schema/nodes/equation.d.ts +3 -4
- package/dist/types/schema/nodes/equation_element.d.ts +1 -2
- package/dist/types/schema/nodes/inline_equation.d.ts +4 -3
- package/dist/types/transformer/builders.d.ts +2 -3
- package/dist/types/transformer/footnotes-order.d.ts +0 -1
- package/package.json +3 -4
- package/dist/cjs/mathjax/index.js +0 -41
- package/dist/cjs/mathjax/mathjax-packages.js +0 -20
- package/dist/cjs/mathjax/mathml-to-svg.js +0 -70
- package/dist/cjs/mathjax/tex-to-mathml.js +0 -49
- package/dist/cjs/mathjax/tex-to-svg.js +0 -59
- package/dist/es/mathjax/index.js +0 -12
- package/dist/es/mathjax/mathjax-packages.js +0 -17
- package/dist/es/mathjax/mathml-to-svg.js +0 -66
- package/dist/es/mathjax/tex-to-mathml.js +0 -45
- package/dist/es/mathjax/tex-to-svg.js +0 -55
- package/dist/types/mathjax/index.d.ts +0 -3
- package/dist/types/mathjax/mathjax-packages.d.ts +0 -16
- package/dist/types/mathjax/mathml-to-svg.d.ts +0 -17
- package/dist/types/mathjax/tex-to-mathml.d.ts +0 -17
- package/dist/types/mathjax/tex-to-svg.d.ts +0 -17
package/dist/cjs/index.js
CHANGED
|
@@ -18,7 +18,6 @@ exports.isSectionLabelNode = void 0;
|
|
|
18
18
|
__exportStar(require("./lib/section-group-type"), exports);
|
|
19
19
|
__exportStar(require("./lib/table-cell-styles"), exports);
|
|
20
20
|
__exportStar(require("./lib/utils"), exports);
|
|
21
|
-
__exportStar(require("./mathjax"), exports);
|
|
22
21
|
__exportStar(require("./schema"), exports);
|
|
23
22
|
__exportStar(require("./transformer"), exports);
|
|
24
23
|
__exportStar(require("./jats"), exports);
|
|
@@ -21,8 +21,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
exports.jatsBodyDOMParser = void 0;
|
|
22
22
|
const mime_1 = __importDefault(require("mime"));
|
|
23
23
|
const prosemirror_model_1 = require("prosemirror-model");
|
|
24
|
-
const mathml_to_svg_1 = require("../../mathjax/mathml-to-svg");
|
|
25
|
-
const tex_to_svg_1 = require("../../mathjax/tex-to-svg");
|
|
26
24
|
const schema_1 = require("../../schema");
|
|
27
25
|
const transformer_1 = require("../../transformer");
|
|
28
26
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
@@ -39,6 +37,28 @@ const chooseContentType = (graphicNode) => {
|
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
};
|
|
40
|
+
const getEquationContent = (p) => {
|
|
41
|
+
var _a;
|
|
42
|
+
const element = p;
|
|
43
|
+
const id = element.getAttribute('id');
|
|
44
|
+
const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
|
|
45
|
+
let contents = '';
|
|
46
|
+
let format = '';
|
|
47
|
+
for (const child of container.childNodes) {
|
|
48
|
+
const nodeName = child.nodeName.replace(/^[a-z]:/, '');
|
|
49
|
+
switch (nodeName) {
|
|
50
|
+
case 'tex-math':
|
|
51
|
+
contents = child.innerHTML;
|
|
52
|
+
format = 'tex';
|
|
53
|
+
break;
|
|
54
|
+
case 'mml:math':
|
|
55
|
+
contents = child.outerHTML;
|
|
56
|
+
format = 'mathml';
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { id, format, contents };
|
|
61
|
+
};
|
|
42
62
|
const marks = [
|
|
43
63
|
{
|
|
44
64
|
tag: 'bold',
|
|
@@ -147,91 +167,26 @@ const nodes = [
|
|
|
147
167
|
tag: 'inline-formula',
|
|
148
168
|
node: 'inline_equation',
|
|
149
169
|
getAttrs: (node) => {
|
|
150
|
-
var _a, _b, _c, _d, _e;
|
|
151
170
|
const element = node;
|
|
152
|
-
|
|
153
|
-
id: element.getAttribute('id'),
|
|
154
|
-
MathMLRepresentation: '',
|
|
155
|
-
SVGRepresentation: '',
|
|
156
|
-
TeXRepresentation: '',
|
|
157
|
-
};
|
|
158
|
-
const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
|
|
159
|
-
for (const child of container.childNodes) {
|
|
160
|
-
const nodeName = child.nodeName.replace(/^[a-z]:/, '');
|
|
161
|
-
switch (nodeName) {
|
|
162
|
-
case 'tex-math':
|
|
163
|
-
attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
164
|
-
if (attrs.TeXRepresentation) {
|
|
165
|
-
attrs.SVGRepresentation =
|
|
166
|
-
(_d = (0, tex_to_svg_1.convertTeXToSVG)(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
|
|
167
|
-
}
|
|
168
|
-
break;
|
|
169
|
-
case 'mml:math':
|
|
170
|
-
;
|
|
171
|
-
child.removeAttribute('id');
|
|
172
|
-
attrs.MathMLRepresentation = transformer_1.xmlSerializer.serializeToString(child);
|
|
173
|
-
if (attrs.MathMLRepresentation) {
|
|
174
|
-
attrs.SVGRepresentation =
|
|
175
|
-
(_e = (0, mathml_to_svg_1.convertMathMLToSVG)(attrs.MathMLRepresentation, true)) !== null && _e !== void 0 ? _e : '';
|
|
176
|
-
}
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return attrs;
|
|
171
|
+
return getEquationContent(element);
|
|
181
172
|
},
|
|
182
173
|
},
|
|
183
174
|
{
|
|
184
175
|
tag: 'disp-formula',
|
|
185
176
|
node: 'equation_element',
|
|
186
177
|
getAttrs: (node) => {
|
|
178
|
+
var _a, _b;
|
|
187
179
|
const element = node;
|
|
188
|
-
const caption = element.querySelector('figcaption');
|
|
189
180
|
return {
|
|
190
181
|
id: element.getAttribute('id'),
|
|
191
|
-
|
|
182
|
+
label: (_b = (_a = element.querySelector('label')) === null || _a === void 0 ? void 0 : _a.textContent) !== null && _b !== void 0 ? _b : '',
|
|
192
183
|
};
|
|
193
184
|
},
|
|
194
185
|
getContent: (node, schema) => {
|
|
195
|
-
var _a, _b, _c, _d, _e;
|
|
196
186
|
const element = node;
|
|
197
|
-
const attrs =
|
|
198
|
-
MathMLStringRepresentation: '',
|
|
199
|
-
SVGStringRepresentation: '',
|
|
200
|
-
TeXRepresentation: '',
|
|
201
|
-
};
|
|
202
|
-
const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
|
|
203
|
-
for (const child of container.childNodes) {
|
|
204
|
-
const nodeName = child.nodeName.replace(/^[a-z]:/, '');
|
|
205
|
-
switch (nodeName) {
|
|
206
|
-
case 'tex-math':
|
|
207
|
-
attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
208
|
-
if (attrs.TeXRepresentation) {
|
|
209
|
-
attrs.SVGStringRepresentation =
|
|
210
|
-
(_d = (0, tex_to_svg_1.convertTeXToSVG)(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
|
|
211
|
-
}
|
|
212
|
-
break;
|
|
213
|
-
case 'mml:math':
|
|
214
|
-
;
|
|
215
|
-
child.removeAttribute('id');
|
|
216
|
-
attrs.MathMLStringRepresentation =
|
|
217
|
-
transformer_1.xmlSerializer.serializeToString(child);
|
|
218
|
-
if (attrs.MathMLStringRepresentation) {
|
|
219
|
-
attrs.SVGStringRepresentation =
|
|
220
|
-
(_e = (0, mathml_to_svg_1.convertMathMLToSVG)(attrs.MathMLStringRepresentation, true)) !== null && _e !== void 0 ? _e : '';
|
|
221
|
-
}
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
const caption = element.querySelector('figcaption');
|
|
226
|
-
const figcaption = schema.nodes.figcaption.create();
|
|
187
|
+
const attrs = getEquationContent(element);
|
|
227
188
|
return prosemirror_model_1.Fragment.from([
|
|
228
|
-
schema.nodes.equation.createChecked(attrs),
|
|
229
|
-
caption
|
|
230
|
-
?
|
|
231
|
-
exports.jatsBodyDOMParser.parse(caption, {
|
|
232
|
-
topNode: figcaption,
|
|
233
|
-
})
|
|
234
|
-
: figcaption,
|
|
189
|
+
schema.nodes.equation.createChecked(Object.assign({}, attrs)),
|
|
235
190
|
]);
|
|
236
191
|
},
|
|
237
192
|
},
|
|
@@ -265,6 +265,16 @@ exports.jatsBodyTransformations = {
|
|
|
265
265
|
}
|
|
266
266
|
});
|
|
267
267
|
},
|
|
268
|
+
orderTableFootnote(doc, body) {
|
|
269
|
+
const tableInlineFootnotesIds = new Set(Array.from(body.querySelectorAll('tbody > tr > td > xref[ref-type="fn"]').values()).map((inlineFootnote) => inlineFootnote.getAttribute('rid')));
|
|
270
|
+
const fnGroups = doc.querySelectorAll('table-wrap-foot > fn-group');
|
|
271
|
+
fnGroups.forEach((fnGroup) => {
|
|
272
|
+
const orderedFootnotes = Array.from(fnGroup.querySelectorAll('fn')).sort((fn) => tableInlineFootnotesIds.has(fn.getAttribute('id'))
|
|
273
|
+
? -1
|
|
274
|
+
: 0);
|
|
275
|
+
fnGroup.replaceChildren(...orderedFootnotes);
|
|
276
|
+
});
|
|
277
|
+
},
|
|
268
278
|
moveFloatsGroupToBody(doc, body, createElement) {
|
|
269
279
|
const group = doc.querySelector('floats-group');
|
|
270
280
|
if (group) {
|
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.htmlFromJatsNode = exports.updateDocumentIDs = void 0;
|
|
19
|
+
const uuid_1 = require("uuid");
|
|
20
|
+
const schema_1 = require("../../schema");
|
|
19
21
|
const transformer_1 = require("../../transformer");
|
|
20
22
|
const updateDocumentIDs = (node, replacements) => {
|
|
21
23
|
const warnings = [];
|
|
@@ -30,6 +32,10 @@ function recurseDoc(node, fn) {
|
|
|
30
32
|
node.descendants((n) => fn(n));
|
|
31
33
|
}
|
|
32
34
|
const updateNodeID = (node, replacements, warnings) => {
|
|
35
|
+
if (node.type === schema_1.schema.nodes.inline_equation) {
|
|
36
|
+
node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${(0, uuid_1.v4)()}` });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
33
39
|
if (!('id' in node.attrs)) {
|
|
34
40
|
return;
|
|
35
41
|
}
|
|
@@ -67,6 +67,7 @@ const parseJATSBody = (doc, body, references) => {
|
|
|
67
67
|
jats_body_transformations_1.jatsBodyTransformations.createBackmatter(doc, body, createElement);
|
|
68
68
|
jats_body_transformations_1.jatsBodyTransformations.createSuppleMaterials(doc, body, createElement);
|
|
69
69
|
jats_body_transformations_1.jatsBodyTransformations.createKeywords(doc, body, createElement);
|
|
70
|
+
jats_body_transformations_1.jatsBodyTransformations.orderTableFootnote(doc, body);
|
|
70
71
|
const node = jats_body_dom_parser_1.jatsBodyDOMParser.parse(body).firstChild;
|
|
71
72
|
if (!node) {
|
|
72
73
|
throw new Error('No content was parsed from the JATS article body');
|
|
@@ -95,7 +95,7 @@ const createDefaultIdGenerator = () => {
|
|
|
95
95
|
const counter = (0, exports.createCounter)();
|
|
96
96
|
return async (element) => {
|
|
97
97
|
const value = String(counter.increment(element.nodeName));
|
|
98
|
-
return `${element.
|
|
98
|
+
return `${element.localName}-${value}`;
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
101
|
const chooseRefType = (objectType) => {
|
|
@@ -164,6 +164,7 @@ class JATSExporter {
|
|
|
164
164
|
};
|
|
165
165
|
this.nodeFromJATS = (JATSFragment) => {
|
|
166
166
|
JATSFragment = JATSFragment.trim();
|
|
167
|
+
JATSFragment = JATSFragment.replace(' ', ' ');
|
|
167
168
|
if (!JATSFragment.length) {
|
|
168
169
|
return null;
|
|
169
170
|
}
|
|
@@ -686,22 +687,20 @@ class JATSExporter {
|
|
|
686
687
|
},
|
|
687
688
|
doc: () => '',
|
|
688
689
|
equation: (node) => {
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
return formula;
|
|
690
|
+
return this.createEquation(node);
|
|
691
|
+
},
|
|
692
|
+
inline_equation: (node) => {
|
|
693
|
+
const eqElement = this.document.createElement('inline-formula');
|
|
694
|
+
const equation = this.createEquation(node, true);
|
|
695
|
+
eqElement.append(equation);
|
|
696
|
+
return eqElement;
|
|
697
|
+
},
|
|
698
|
+
equation_element: (node) => {
|
|
699
|
+
const eqElement = this.document.createElement('disp-formula');
|
|
700
|
+
eqElement.setAttribute('id', normalizeID(node.attrs.id));
|
|
701
|
+
processChildNodes(eqElement, node, schema_1.schema.nodes.equation);
|
|
702
|
+
return eqElement;
|
|
703
703
|
},
|
|
704
|
-
equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
|
|
705
704
|
figcaption: (node) => {
|
|
706
705
|
if (!node.textContent) {
|
|
707
706
|
return '';
|
|
@@ -751,28 +750,6 @@ class JATSExporter {
|
|
|
751
750
|
},
|
|
752
751
|
hard_break: () => '',
|
|
753
752
|
highlight_marker: () => '',
|
|
754
|
-
inline_equation: (node) => {
|
|
755
|
-
const formula = this.document.createElement('inline-formula');
|
|
756
|
-
formula.setAttribute('id', normalizeID(node.attrs.id));
|
|
757
|
-
if (node.attrs.TeXRepresentation) {
|
|
758
|
-
const math = this.document.createElement('tex-math');
|
|
759
|
-
math.textContent = node.attrs.TeXRepresentation;
|
|
760
|
-
formula.appendChild(math);
|
|
761
|
-
}
|
|
762
|
-
else if (node.attrs.MathMLRepresentation) {
|
|
763
|
-
const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
|
|
764
|
-
if (math) {
|
|
765
|
-
formula.appendChild(math);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
else if (node.attrs.SVGRepresentation) {
|
|
769
|
-
const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
|
|
770
|
-
if (math) {
|
|
771
|
-
formula.appendChild(math);
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
return formula;
|
|
775
|
-
},
|
|
776
753
|
inline_footnote: (node) => {
|
|
777
754
|
const xref = this.document.createElement('xref');
|
|
778
755
|
xref.setAttribute('ref-type', 'fn');
|
|
@@ -1589,6 +1566,21 @@ class JATSExporter {
|
|
|
1589
1566
|
this.citationTexts.set(id, output);
|
|
1590
1567
|
});
|
|
1591
1568
|
}
|
|
1569
|
+
createEquation(node, isInline = false) {
|
|
1570
|
+
if (node.attrs.format === 'tex') {
|
|
1571
|
+
const texMath = this.document.createElement('tex-math');
|
|
1572
|
+
texMath.innerHTML = node.attrs.contents;
|
|
1573
|
+
return texMath;
|
|
1574
|
+
}
|
|
1575
|
+
else {
|
|
1576
|
+
const math = this.nodeFromJATS(node.attrs.contents);
|
|
1577
|
+
const mathml = math;
|
|
1578
|
+
if (!isInline) {
|
|
1579
|
+
mathml.setAttribute('id', normalizeID(node.attrs.id));
|
|
1580
|
+
}
|
|
1581
|
+
return mathml;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1592
1584
|
buildKeywords(articleMeta) {
|
|
1593
1585
|
const keywords = [...this.modelMap.values()].filter((model) => model.objectType === json_schema_1.ObjectTypes.Keyword);
|
|
1594
1586
|
const keywordGroups = new Map();
|
package/dist/cjs/schema/index.js
CHANGED
|
@@ -117,7 +117,6 @@ __exportStar(require("./nodes/footnotes_section"), exports);
|
|
|
117
117
|
__exportStar(require("./nodes/graphical_abstract_section"), exports);
|
|
118
118
|
__exportStar(require("./nodes/hard_break"), exports);
|
|
119
119
|
__exportStar(require("./nodes/highlight_marker"), exports);
|
|
120
|
-
__exportStar(require("./nodes/inline_equation"), exports);
|
|
121
120
|
__exportStar(require("./nodes/inline_footnote"), exports);
|
|
122
121
|
__exportStar(require("./nodes/keyword"), exports);
|
|
123
122
|
__exportStar(require("./nodes/keywords_element"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*!
|
|
3
|
-
* ©
|
|
3
|
+
* © 2023 Atypon Systems LLC
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -20,9 +20,8 @@ const json_schema_1 = require("@manuscripts/json-schema");
|
|
|
20
20
|
exports.equation = {
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
TeXRepresentation: { default: '' },
|
|
23
|
+
contents: { default: '' },
|
|
24
|
+
format: { default: '' },
|
|
26
25
|
dataTracked: { default: null },
|
|
27
26
|
},
|
|
28
27
|
group: 'block',
|
|
@@ -30,26 +29,25 @@ exports.equation = {
|
|
|
30
29
|
{
|
|
31
30
|
tag: `div.${json_schema_1.ObjectTypes.Equation}`,
|
|
32
31
|
getAttrs: (p) => {
|
|
33
|
-
const
|
|
32
|
+
const htmlEl = p;
|
|
34
33
|
return {
|
|
35
|
-
id:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
TeXRepresentation: dom.getAttribute('data-tex-representation'),
|
|
34
|
+
id: htmlEl.getAttribute('id'),
|
|
35
|
+
format: htmlEl.getAttribute('data-equation-format'),
|
|
36
|
+
contents: htmlEl.innerHTML,
|
|
39
37
|
};
|
|
40
38
|
},
|
|
41
39
|
},
|
|
42
40
|
],
|
|
43
41
|
toDOM: (node) => {
|
|
44
42
|
const equationNode = node;
|
|
43
|
+
const { id, contents, format } = equationNode.attrs;
|
|
45
44
|
const dom = document.createElement('div');
|
|
46
|
-
dom.setAttribute('id', equationNode.attrs.id);
|
|
47
45
|
dom.classList.add(json_schema_1.ObjectTypes.Equation);
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
dom.setAttribute('id', id);
|
|
47
|
+
if (format) {
|
|
48
|
+
dom.setAttribute('data-equation-format', format);
|
|
50
49
|
}
|
|
51
|
-
dom.
|
|
52
|
-
dom.innerHTML = equationNode.attrs.SVGStringRepresentation;
|
|
50
|
+
dom.innerHTML = contents;
|
|
53
51
|
return dom;
|
|
54
52
|
},
|
|
55
53
|
};
|
|
@@ -17,11 +17,10 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.equationElement = void 0;
|
|
19
19
|
exports.equationElement = {
|
|
20
|
-
content: '(equation | placeholder)
|
|
20
|
+
content: '(equation | placeholder)',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
|
-
|
|
24
|
-
suppressTitle: { default: undefined },
|
|
23
|
+
label: { default: '' },
|
|
25
24
|
dataTracked: { default: null },
|
|
26
25
|
comments: { default: null },
|
|
27
26
|
},
|
|
@@ -29,7 +28,7 @@ exports.equationElement = {
|
|
|
29
28
|
group: 'block element',
|
|
30
29
|
parseDOM: [
|
|
31
30
|
{
|
|
32
|
-
tag: '
|
|
31
|
+
tag: 'div.equation',
|
|
33
32
|
getAttrs: (p) => {
|
|
34
33
|
const dom = p;
|
|
35
34
|
return {
|
|
@@ -41,7 +40,7 @@ exports.equationElement = {
|
|
|
41
40
|
toDOM: (node) => {
|
|
42
41
|
const equationElementNode = node;
|
|
43
42
|
return [
|
|
44
|
-
'
|
|
43
|
+
'div',
|
|
45
44
|
{
|
|
46
45
|
class: 'equation',
|
|
47
46
|
id: equationElementNode.attrs.id,
|
|
@@ -16,14 +16,13 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.inlineEquation = void 0;
|
|
19
|
-
const json_schema_1 = require("@manuscripts/json-schema");
|
|
20
19
|
exports.inlineEquation = {
|
|
21
20
|
attrs: {
|
|
22
|
-
id: { default: '' },
|
|
23
|
-
MathMLRepresentation: { default: '' },
|
|
24
|
-
SVGRepresentation: { default: '' },
|
|
25
|
-
TeXRepresentation: { default: '' },
|
|
26
21
|
dataTracked: { default: null },
|
|
22
|
+
comments: { default: null },
|
|
23
|
+
id: { default: '' },
|
|
24
|
+
contents: { default: '' },
|
|
25
|
+
format: { default: '' },
|
|
27
26
|
},
|
|
28
27
|
atom: true,
|
|
29
28
|
inline: true,
|
|
@@ -31,28 +30,27 @@ exports.inlineEquation = {
|
|
|
31
30
|
group: 'inline',
|
|
32
31
|
parseDOM: [
|
|
33
32
|
{
|
|
34
|
-
tag: `span
|
|
33
|
+
tag: `span.MPInlineMathFragment`,
|
|
35
34
|
getAttrs: (p) => {
|
|
36
35
|
const dom = p;
|
|
37
36
|
return {
|
|
37
|
+
format: dom.getAttribute('data-equation-format'),
|
|
38
38
|
id: dom.getAttribute('id'),
|
|
39
|
-
|
|
40
|
-
SVGRepresentation: dom.innerHTML || '',
|
|
41
|
-
TeXRepresentation: dom.getAttribute('data-tex-representation') || '',
|
|
39
|
+
contents: dom.innerHTML,
|
|
42
40
|
};
|
|
43
41
|
},
|
|
44
42
|
},
|
|
45
43
|
],
|
|
46
44
|
toDOM: (node) => {
|
|
47
45
|
const inlineEquationNode = node;
|
|
46
|
+
const { id, contents, format } = inlineEquationNode.attrs;
|
|
48
47
|
const dom = document.createElement('span');
|
|
49
|
-
dom.
|
|
50
|
-
dom.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
dom.setAttribute('data-mathml-representation', inlineEquationNode.attrs.MathMLRepresentation);
|
|
48
|
+
dom.setAttribute('id', id);
|
|
49
|
+
dom.classList.add('MPInlineMathFragment');
|
|
50
|
+
if (format) {
|
|
51
|
+
dom.setAttribute('data-equation-format', format);
|
|
54
52
|
}
|
|
55
|
-
dom.innerHTML =
|
|
53
|
+
dom.innerHTML = contents;
|
|
56
54
|
return dom;
|
|
57
55
|
},
|
|
58
56
|
};
|
|
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.buildTitles = exports.buildElementsOrder = exports.auxiliaryObjectTypes = exports.buildJournal = exports.buildAttribution = exports.buildContributorRole = exports.buildContribution = exports.buildColor = exports.buildParagraph = exports.buildSection = exports.buildCorresp = exports.buildFootnotesOrder = exports.buildFootnote = exports.
|
|
21
|
+
exports.buildTitles = exports.buildElementsOrder = exports.auxiliaryObjectTypes = exports.buildJournal = exports.buildAttribution = exports.buildContributorRole = exports.buildContribution = exports.buildColor = exports.buildParagraph = exports.buildSection = exports.buildCorresp = exports.buildFootnotesOrder = exports.buildFootnote = exports.buildNote = exports.buildComment = exports.buildSupplementaryMaterial = exports.buildAffiliation = exports.buildFigure = exports.buildKeywordGroup = exports.buildKeyword = exports.buildBibliographyElement = exports.buildBibliographicDate = exports.buildBibliographicName = exports.buildBibliographyItem = exports.buildContributor = exports.buildManuscript = exports.buildProject = void 0;
|
|
22
22
|
const json_schema_1 = require("@manuscripts/json-schema");
|
|
23
23
|
const w3c_xmlserializer_1 = __importDefault(require("w3c-xmlserializer"));
|
|
24
24
|
const schema_1 = require("../schema");
|
|
@@ -115,13 +115,6 @@ const buildNote = (target, source, contents = '') => ({
|
|
|
115
115
|
contents,
|
|
116
116
|
});
|
|
117
117
|
exports.buildNote = buildNote;
|
|
118
|
-
const buildInlineMathFragment = (containingObject, TeXRepresentation) => ({
|
|
119
|
-
_id: (0, id_1.generateID)(json_schema_1.ObjectTypes.InlineMathFragment),
|
|
120
|
-
objectType: json_schema_1.ObjectTypes.InlineMathFragment,
|
|
121
|
-
containingObject: containingObject || undefined,
|
|
122
|
-
TeXRepresentation,
|
|
123
|
-
});
|
|
124
|
-
exports.buildInlineMathFragment = buildInlineMathFragment;
|
|
125
118
|
const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
|
|
126
119
|
_id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Footnote),
|
|
127
120
|
objectType: json_schema_1.ObjectTypes.Footnote,
|
|
@@ -130,10 +123,11 @@ const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
|
|
|
130
123
|
kind,
|
|
131
124
|
});
|
|
132
125
|
exports.buildFootnote = buildFootnote;
|
|
133
|
-
const buildFootnotesOrder = (footnotesList) => ({
|
|
126
|
+
const buildFootnotesOrder = (footnotesList, containedObjectID) => ({
|
|
134
127
|
_id: (0, id_1.generateID)(json_schema_1.ObjectTypes.FootnotesOrder),
|
|
135
128
|
objectType: json_schema_1.ObjectTypes.FootnotesOrder,
|
|
136
129
|
footnotesList,
|
|
130
|
+
containedObjectID,
|
|
137
131
|
});
|
|
138
132
|
exports.buildFootnotesOrder = buildFootnotesOrder;
|
|
139
133
|
const buildCorresp = (contents) => ({
|
|
@@ -68,7 +68,6 @@ const getSupplements = (modelMap) => (0, exports.getModelsByType)(modelMap, json
|
|
|
68
68
|
const getKeywordGroups = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.KeywordGroup);
|
|
69
69
|
const getKeywords = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Keyword);
|
|
70
70
|
const getTitles = (modelMap) => (0, exports.getModelsByType)(modelMap, json_schema_1.ObjectTypes.Titles)[0];
|
|
71
|
-
const isFootnote = (0, object_types_1.hasObjectType)(json_schema_1.ObjectTypes.Footnote);
|
|
72
71
|
const hasParentSection = (id) => (section) => section.path &&
|
|
73
72
|
section.path.length > 1 &&
|
|
74
73
|
section.path[section.path.length - 2] === id;
|
|
@@ -281,9 +280,8 @@ class Decoder {
|
|
|
281
280
|
const model = data;
|
|
282
281
|
return schema_1.schema.nodes.equation.createChecked({
|
|
283
282
|
id: model._id,
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
TeXRepresentation: model.TeXRepresentation,
|
|
283
|
+
contents: model.contents,
|
|
284
|
+
format: model.format,
|
|
287
285
|
});
|
|
288
286
|
},
|
|
289
287
|
[json_schema_1.ObjectTypes.EquationElement]: (data) => {
|
|
@@ -302,32 +300,32 @@ class Decoder {
|
|
|
302
300
|
else {
|
|
303
301
|
throw new errors_1.MissingElement(model.containedObjectID);
|
|
304
302
|
}
|
|
305
|
-
const figcaption = this.getFigcaption(model);
|
|
306
303
|
return schema_1.schema.nodes.equation_element.createChecked({
|
|
307
304
|
id: model._id,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}, [equation, figcaption]);
|
|
305
|
+
label: model.label,
|
|
306
|
+
}, [equation]);
|
|
311
307
|
},
|
|
312
308
|
[json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
|
|
313
309
|
const foonotesElementModel = data;
|
|
314
|
-
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
315
310
|
const footnotesOfKind = [];
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
model
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
311
|
+
const footnoteOrder = (0, exports.getModelsByType)(this.modelMap, json_schema_1.ObjectTypes.FootnotesOrder).find((model) => model.containedObjectID === data._id);
|
|
312
|
+
if (footnoteOrder) {
|
|
313
|
+
footnoteOrder.footnotesList.map(({ id }) => {
|
|
314
|
+
const model = this.modelMap.get(id);
|
|
315
|
+
const collateByKind = foonotesElementModel.collateByKind || 'footnote';
|
|
316
|
+
if (model.kind === collateByKind) {
|
|
317
|
+
const comments = this.createCommentNodes(model);
|
|
318
|
+
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
319
|
+
const footnote = this.parseContents(model.contents || '<div></div>', undefined, this.getComments(model), {
|
|
320
|
+
topNode: schema_1.schema.nodes.footnote.create({
|
|
321
|
+
id: model._id,
|
|
322
|
+
kind: model.kind,
|
|
323
|
+
comments: comments.map((c) => c.attrs.id),
|
|
324
|
+
}),
|
|
325
|
+
});
|
|
326
|
+
footnotesOfKind.push(footnote);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
331
329
|
}
|
|
332
330
|
return schema_1.schema.nodes.footnotes_element.create({
|
|
333
331
|
id: foonotesElementModel._id,
|
|
@@ -62,12 +62,6 @@ const listContents = (node) => {
|
|
|
62
62
|
}
|
|
63
63
|
return (0, w3c_xmlserializer_1.default)(output);
|
|
64
64
|
};
|
|
65
|
-
const svgDefs = (svg) => {
|
|
66
|
-
const template = document.createElement('template');
|
|
67
|
-
template.innerHTML = svg.trim();
|
|
68
|
-
const defs = template.content.querySelector('defs');
|
|
69
|
-
return defs ? (0, w3c_xmlserializer_1.default)(defs) : undefined;
|
|
70
|
-
};
|
|
71
65
|
const tableRowDisplayStyle = (tagName, parent) => {
|
|
72
66
|
switch (tagName) {
|
|
73
67
|
case 'thead':
|
|
@@ -353,20 +347,13 @@ const encoders = {
|
|
|
353
347
|
: false,
|
|
354
348
|
}),
|
|
355
349
|
equation: (node) => ({
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
SVGStringRepresentation: node.attrs.SVGStringRepresentation,
|
|
350
|
+
contents: node.attrs.contents,
|
|
351
|
+
format: node.attrs.format,
|
|
359
352
|
}),
|
|
360
353
|
equation_element: (node) => ({
|
|
361
354
|
containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
elementType: 'p',
|
|
365
|
-
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
366
|
-
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
367
|
-
node.attrs.suppressTitle === true
|
|
368
|
-
? undefined
|
|
369
|
-
: false,
|
|
355
|
+
elementType: 'div',
|
|
356
|
+
label: node.attrs.label,
|
|
370
357
|
}),
|
|
371
358
|
figure: (node) => ({
|
|
372
359
|
contentType: node.attrs.contentType || undefined,
|
|
@@ -413,12 +400,6 @@ const encoders = {
|
|
|
413
400
|
.map((childNode) => childNode.attrs.id)
|
|
414
401
|
.filter((id) => id),
|
|
415
402
|
}),
|
|
416
|
-
inline_equation: (node, parent) => ({
|
|
417
|
-
containingObject: parent.attrs.id,
|
|
418
|
-
TeXRepresentation: node.attrs.TeXRepresentation,
|
|
419
|
-
SVGRepresentation: node.attrs.SVGRepresentation,
|
|
420
|
-
SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
|
|
421
|
-
}),
|
|
422
403
|
keyword: (node, parent) => ({
|
|
423
404
|
containedGroup: parent.attrs.id,
|
|
424
405
|
name: keywordContents(node),
|
|
@@ -592,10 +573,12 @@ const encode = (node) => {
|
|
|
592
573
|
if (placeholderTypes.includes(child.type)) {
|
|
593
574
|
return;
|
|
594
575
|
}
|
|
595
|
-
if (parent.type === schema_1.schema.nodes.paragraph
|
|
596
|
-
child.type !== schema_1.schema.nodes.inline_equation) {
|
|
576
|
+
if (parent.type === schema_1.schema.nodes.paragraph) {
|
|
597
577
|
return;
|
|
598
578
|
}
|
|
579
|
+
if (child.type === schema_1.schema.nodes.footnotes_element) {
|
|
580
|
+
addFootnotesOrderModel(child, models);
|
|
581
|
+
}
|
|
599
582
|
const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
600
583
|
markers.forEach((marker) => {
|
|
601
584
|
const comment = models.get(marker._id);
|
|
@@ -647,3 +630,9 @@ const generateElementOrder = (node, nodeType) => {
|
|
|
647
630
|
order.elements = ids;
|
|
648
631
|
return order;
|
|
649
632
|
};
|
|
633
|
+
const addFootnotesOrderModel = (child, models) => {
|
|
634
|
+
const footnoteList = [];
|
|
635
|
+
child.forEach((footnote, _, index) => footnoteList.push({ id: footnote.attrs.id, index }));
|
|
636
|
+
const footnotesOrder = (0, builders_1.buildFootnotesOrder)(footnoteList, child.attrs.id);
|
|
637
|
+
models.set(footnotesOrder._id, footnotesOrder);
|
|
638
|
+
};
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
19
|
-
const builders_1 = require("./builders");
|
|
18
|
+
exports.handleFootnotesOrder = exports.createOrderedFootnotesIDs = void 0;
|
|
20
19
|
const createOrderedFootnotesIDs = (doc) => {
|
|
21
20
|
const footnotesRefs = [...doc.querySelectorAll('xref[ref-type="fn"][rid]')];
|
|
22
21
|
const footnotes = [...doc.querySelectorAll('fn:not([fn-type])')];
|
|
@@ -59,5 +58,3 @@ const handleFootnotesOrder = (orderedFootnotesIDs, replacements, footnotesOrder)
|
|
|
59
58
|
footnotesOrder.footnotesList = footnotesList;
|
|
60
59
|
};
|
|
61
60
|
exports.handleFootnotesOrder = handleFootnotesOrder;
|
|
62
|
-
const createEmptyFootnotesOrder = () => (0, builders_1.buildFootnotesOrder)([]);
|
|
63
|
-
exports.createEmptyFootnotesOrder = createEmptyFootnotesOrder;
|