@manuscripts/transform 2.1.1-LEAN-3095 → 2.1.1-LEAN-3336-3
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 +1 -0
- package/dist/cjs/jats/importer/jats-body-dom-parser.js +73 -25
- package/dist/cjs/jats/jats-exporter.js +42 -18
- package/dist/cjs/mathjax/index.js +41 -0
- package/dist/cjs/mathjax/mathjax-packages.js +20 -0
- package/dist/cjs/mathjax/mathml-to-svg.js +70 -0
- package/dist/cjs/mathjax/tex-to-mathml.js +49 -0
- package/dist/cjs/mathjax/tex-to-svg.js +59 -0
- package/dist/cjs/schema/index.js +2 -1
- package/dist/cjs/schema/nodes/equation.js +14 -12
- package/dist/cjs/schema/nodes/equation_element.js +5 -4
- package/dist/cjs/schema/nodes/inline_equation.js +16 -12
- package/dist/cjs/schema/nodes/table.js +2 -15
- package/dist/cjs/schema/nodes/table_row.js +7 -6
- package/dist/cjs/transformer/builders.js +8 -1
- package/dist/cjs/transformer/decode.js +7 -4
- package/dist/cjs/transformer/encode.js +25 -22
- package/dist/cjs/transformer/node-types.js +1 -0
- package/dist/cjs/transformer/object-types.js +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/jats/importer/jats-body-dom-parser.js +74 -26
- package/dist/es/jats/jats-exporter.js +42 -18
- package/dist/es/mathjax/index.js +12 -0
- package/dist/es/mathjax/mathjax-packages.js +17 -0
- package/dist/es/mathjax/mathml-to-svg.js +66 -0
- package/dist/es/mathjax/tex-to-mathml.js +45 -0
- package/dist/es/mathjax/tex-to-svg.js +55 -0
- package/dist/es/schema/index.js +4 -3
- package/dist/es/schema/nodes/equation.js +14 -12
- package/dist/es/schema/nodes/equation_element.js +5 -4
- package/dist/es/schema/nodes/inline_equation.js +16 -12
- package/dist/es/schema/nodes/table.js +1 -14
- package/dist/es/schema/nodes/table_row.js +6 -5
- package/dist/es/transformer/builders.js +6 -0
- package/dist/es/transformer/decode.js +7 -4
- package/dist/es/transformer/encode.js +25 -22
- package/dist/es/transformer/node-types.js +1 -0
- package/dist/es/transformer/object-types.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/mathjax/index.d.ts +3 -0
- package/dist/types/mathjax/mathjax-packages.d.ts +16 -0
- package/dist/types/mathjax/mathml-to-svg.d.ts +17 -0
- package/dist/types/mathjax/tex-to-mathml.d.ts +17 -0
- package/dist/types/mathjax/tex-to-svg.d.ts +17 -0
- package/dist/types/schema/index.d.ts +1 -0
- package/dist/types/schema/nodes/equation.d.ts +4 -3
- package/dist/types/schema/nodes/equation_element.d.ts +2 -1
- package/dist/types/schema/nodes/inline_equation.d.ts +4 -4
- package/dist/types/schema/nodes/table.d.ts +0 -1
- package/dist/types/schema/nodes/table_row.d.ts +1 -0
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/builders.d.ts +2 -1
- package/package.json +4 -3
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.table = void 0;
|
|
19
19
|
exports.table = {
|
|
20
|
-
content: '
|
|
20
|
+
content: 'table_row+',
|
|
21
21
|
tableRole: 'table',
|
|
22
22
|
isolating: true,
|
|
23
23
|
group: 'block',
|
|
@@ -55,16 +55,3 @@ exports.table = {
|
|
|
55
55
|
];
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
|
-
exports.tableBody = {
|
|
59
|
-
content: 'table_row+',
|
|
60
|
-
group: 'block',
|
|
61
|
-
tableRole: 'table',
|
|
62
|
-
parseDOM: [
|
|
63
|
-
{
|
|
64
|
-
tag: 'tbody',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
toDOM() {
|
|
68
|
-
return ['tbody', 0];
|
|
69
|
-
},
|
|
70
|
-
};
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.tableCell = exports.tableRow = void 0;
|
|
18
|
+
exports.tableHeader = exports.tableCell = exports.tableRow = void 0;
|
|
19
19
|
const table_cell_styles_1 = require("../../lib/table-cell-styles");
|
|
20
20
|
const getCellAttrs = (p) => {
|
|
21
21
|
const dom = p;
|
|
@@ -43,7 +43,7 @@ const getCellAttrs = (p) => {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
exports.tableRow = {
|
|
46
|
-
content: 'table_cell
|
|
46
|
+
content: '(table_cell | table_header)*',
|
|
47
47
|
tableRole: 'row',
|
|
48
48
|
attrs: {
|
|
49
49
|
placeholder: { default: '' },
|
|
@@ -79,10 +79,7 @@ exports.tableCell = {
|
|
|
79
79
|
},
|
|
80
80
|
tableRole: 'cell',
|
|
81
81
|
isolating: true,
|
|
82
|
-
parseDOM: [
|
|
83
|
-
{ tag: 'td', getAttrs: getCellAttrs },
|
|
84
|
-
{ tag: 'th', getAttrs: getCellAttrs },
|
|
85
|
-
],
|
|
82
|
+
parseDOM: [{ tag: 'td', getAttrs: getCellAttrs }],
|
|
86
83
|
toDOM: (node) => {
|
|
87
84
|
const tableCellNode = node;
|
|
88
85
|
const attrs = {};
|
|
@@ -121,3 +118,7 @@ exports.tableCell = {
|
|
|
121
118
|
return [tag, attrs, 0];
|
|
122
119
|
},
|
|
123
120
|
};
|
|
121
|
+
exports.tableHeader = exports.tableCell && {
|
|
122
|
+
tableRole: 'header_cell',
|
|
123
|
+
parseDOM: [{ tag: 'th', getAttrs: getCellAttrs }],
|
|
124
|
+
};
|
|
@@ -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.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;
|
|
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.buildInlineMathFragment = 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,6 +115,13 @@ 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;
|
|
118
125
|
const buildFootnote = (containingObject, contents, kind = 'footnote') => ({
|
|
119
126
|
_id: (0, id_1.generateID)(json_schema_1.ObjectTypes.Footnote),
|
|
120
127
|
objectType: json_schema_1.ObjectTypes.Footnote,
|
|
@@ -281,8 +281,9 @@ class Decoder {
|
|
|
281
281
|
const model = data;
|
|
282
282
|
return schema_1.schema.nodes.equation.createChecked({
|
|
283
283
|
id: model._id,
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
MathMLStringRepresentation: model.MathMLStringRepresentation,
|
|
285
|
+
SVGStringRepresentation: model.SVGStringRepresentation,
|
|
286
|
+
TeXRepresentation: model.TeXRepresentation,
|
|
286
287
|
});
|
|
287
288
|
},
|
|
288
289
|
[json_schema_1.ObjectTypes.EquationElement]: (data) => {
|
|
@@ -301,10 +302,12 @@ class Decoder {
|
|
|
301
302
|
else {
|
|
302
303
|
throw new errors_1.MissingElement(model.containedObjectID);
|
|
303
304
|
}
|
|
305
|
+
const figcaption = this.getFigcaption(model);
|
|
304
306
|
return schema_1.schema.nodes.equation_element.createChecked({
|
|
305
307
|
id: model._id,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
+
suppressCaption: Boolean(model.suppressCaption),
|
|
309
|
+
suppressTitle: Boolean(model.suppressTitle === undefined ? true : model.suppressTitle),
|
|
310
|
+
}, [equation, figcaption]);
|
|
308
311
|
},
|
|
309
312
|
[json_schema_1.ObjectTypes.FootnotesElement]: (data) => {
|
|
310
313
|
const foonotesElementModel = data;
|
|
@@ -62,6 +62,12 @@ 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
|
+
};
|
|
65
71
|
const tableRowDisplayStyle = (tagName, parent) => {
|
|
66
72
|
switch (tagName) {
|
|
67
73
|
case 'thead':
|
|
@@ -93,27 +99,9 @@ const buildTableSection = (tagName, inputRows, parent) => {
|
|
|
93
99
|
}
|
|
94
100
|
return section;
|
|
95
101
|
};
|
|
96
|
-
function buildTableColGroup(cols) {
|
|
97
|
-
if (cols.length === 0) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
const colgroup = document.createElement('colgroup');
|
|
101
|
-
for (const inputCol of cols) {
|
|
102
|
-
const col = document.createElement('col');
|
|
103
|
-
for (const attribute of inputCol.attributes) {
|
|
104
|
-
col.setAttribute(attribute.name, attribute.value);
|
|
105
|
-
}
|
|
106
|
-
colgroup.appendChild(inputCol);
|
|
107
|
-
}
|
|
108
|
-
return colgroup;
|
|
109
|
-
}
|
|
110
102
|
const tableContents = (node, parent) => {
|
|
111
103
|
const input = serializer.serializeNode(node);
|
|
112
104
|
const output = document.createElement('table');
|
|
113
|
-
const colgroup = buildTableColGroup(Array.from(input.querySelectorAll('col')));
|
|
114
|
-
if (colgroup) {
|
|
115
|
-
output.appendChild(colgroup);
|
|
116
|
-
}
|
|
117
105
|
output.setAttribute('id', parent.attrs.id);
|
|
118
106
|
output.classList.add('MPElement');
|
|
119
107
|
if (parent.attrs.tableStyle) {
|
|
@@ -347,12 +335,20 @@ const encoders = {
|
|
|
347
335
|
: false,
|
|
348
336
|
}),
|
|
349
337
|
equation: (node) => ({
|
|
350
|
-
|
|
351
|
-
|
|
338
|
+
MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
|
|
339
|
+
TeXRepresentation: node.attrs.TeXRepresentation,
|
|
340
|
+
SVGStringRepresentation: node.attrs.SVGStringRepresentation,
|
|
352
341
|
}),
|
|
353
342
|
equation_element: (node) => ({
|
|
354
343
|
containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
|
|
355
|
-
|
|
344
|
+
caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
345
|
+
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
346
|
+
elementType: 'p',
|
|
347
|
+
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
348
|
+
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
349
|
+
node.attrs.suppressTitle === true
|
|
350
|
+
? undefined
|
|
351
|
+
: false,
|
|
356
352
|
}),
|
|
357
353
|
figure: (node) => ({
|
|
358
354
|
contentType: node.attrs.contentType || undefined,
|
|
@@ -399,6 +395,12 @@ const encoders = {
|
|
|
399
395
|
.map((childNode) => childNode.attrs.id)
|
|
400
396
|
.filter((id) => id),
|
|
401
397
|
}),
|
|
398
|
+
inline_equation: (node, parent) => ({
|
|
399
|
+
containingObject: parent.attrs.id,
|
|
400
|
+
TeXRepresentation: node.attrs.TeXRepresentation,
|
|
401
|
+
SVGRepresentation: node.attrs.SVGRepresentation,
|
|
402
|
+
SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
|
|
403
|
+
}),
|
|
402
404
|
keyword: (node, parent) => ({
|
|
403
405
|
containedGroup: parent.attrs.id,
|
|
404
406
|
name: keywordContents(node),
|
|
@@ -572,7 +574,8 @@ const encode = (node) => {
|
|
|
572
574
|
if (placeholderTypes.includes(child.type)) {
|
|
573
575
|
return;
|
|
574
576
|
}
|
|
575
|
-
if (parent.type === schema_1.schema.nodes.paragraph
|
|
577
|
+
if (parent.type === schema_1.schema.nodes.paragraph &&
|
|
578
|
+
child.type !== schema_1.schema.nodes.inline_equation) {
|
|
576
579
|
return;
|
|
577
580
|
}
|
|
578
581
|
const { model, markers } = (0, exports.modelFromNode)(child, parent, path, priority);
|
|
@@ -39,6 +39,7 @@ exports.nodeTypesMap = new Map([
|
|
|
39
39
|
[schema_1.schema.nodes.footnotes_section, json_schema_1.ObjectTypes.Section],
|
|
40
40
|
[schema_1.schema.nodes.graphical_abstract_section, json_schema_1.ObjectTypes.Section],
|
|
41
41
|
[schema_1.schema.nodes.highlight_marker, json_schema_1.ObjectTypes.HighlightMarker],
|
|
42
|
+
[schema_1.schema.nodes.inline_equation, json_schema_1.ObjectTypes.InlineMathFragment],
|
|
42
43
|
[schema_1.schema.nodes.keyword, json_schema_1.ObjectTypes.Keyword],
|
|
43
44
|
[schema_1.schema.nodes.keywords_element, json_schema_1.ObjectTypes.KeywordsElement],
|
|
44
45
|
[schema_1.schema.nodes.keywords, json_schema_1.ObjectTypes.Section],
|
|
@@ -38,6 +38,7 @@ exports.manuscriptObjects = [
|
|
|
38
38
|
json_schema_1.ObjectTypes.CommentAnnotation,
|
|
39
39
|
json_schema_1.ObjectTypes.Contributor,
|
|
40
40
|
json_schema_1.ObjectTypes.Footnote,
|
|
41
|
+
json_schema_1.ObjectTypes.InlineMathFragment,
|
|
41
42
|
json_schema_1.ObjectTypes.Section,
|
|
42
43
|
].concat(exports.elementObjects);
|
|
43
44
|
const isManuscriptModel = (model) => {
|
package/dist/es/index.js
CHANGED
|
@@ -15,8 +15,10 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import mime from 'mime';
|
|
17
17
|
import { DOMParser, Fragment } from 'prosemirror-model';
|
|
18
|
+
import { convertMathMLToSVG } from '../../mathjax/mathml-to-svg';
|
|
19
|
+
import { convertTeXToSVG } from '../../mathjax/tex-to-svg';
|
|
18
20
|
import { schema } from '../../schema';
|
|
19
|
-
import { chooseSectionCategory } from '../../transformer';
|
|
21
|
+
import { chooseSectionCategory, xmlSerializer } from '../../transformer';
|
|
20
22
|
const XLINK_NAMESPACE = 'http://www.w3.org/1999/xlink';
|
|
21
23
|
const chooseContentType = (graphicNode) => {
|
|
22
24
|
if (graphicNode) {
|
|
@@ -31,24 +33,6 @@ const chooseContentType = (graphicNode) => {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
|
-
const getEquationContent = (p) => {
|
|
35
|
-
var _a;
|
|
36
|
-
const element = p;
|
|
37
|
-
const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
|
|
38
|
-
let contents = '';
|
|
39
|
-
let format = '';
|
|
40
|
-
for (const child of container.childNodes) {
|
|
41
|
-
const nodeName = child.nodeName.replace(/^[a-z]:/, '');
|
|
42
|
-
switch (nodeName) {
|
|
43
|
-
case 'tex-math':
|
|
44
|
-
case 'mml:math':
|
|
45
|
-
contents = child.outerHTML;
|
|
46
|
-
format = nodeName === 'tex-math' ? 'tex' : 'mathml';
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return { format, contents };
|
|
51
|
-
};
|
|
52
36
|
const marks = [
|
|
53
37
|
{
|
|
54
38
|
tag: 'bold',
|
|
@@ -157,27 +141,91 @@ const nodes = [
|
|
|
157
141
|
tag: 'inline-formula',
|
|
158
142
|
node: 'inline_equation',
|
|
159
143
|
getAttrs: (node) => {
|
|
144
|
+
var _a, _b, _c, _d, _e;
|
|
160
145
|
const element = node;
|
|
161
|
-
|
|
146
|
+
const attrs = {
|
|
147
|
+
id: element.getAttribute('id'),
|
|
148
|
+
MathMLRepresentation: '',
|
|
149
|
+
SVGRepresentation: '',
|
|
150
|
+
TeXRepresentation: '',
|
|
151
|
+
};
|
|
152
|
+
const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
|
|
153
|
+
for (const child of container.childNodes) {
|
|
154
|
+
const nodeName = child.nodeName.replace(/^[a-z]:/, '');
|
|
155
|
+
switch (nodeName) {
|
|
156
|
+
case 'tex-math':
|
|
157
|
+
attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
158
|
+
if (attrs.TeXRepresentation) {
|
|
159
|
+
attrs.SVGRepresentation =
|
|
160
|
+
(_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
case 'mml:math':
|
|
164
|
+
;
|
|
165
|
+
child.removeAttribute('id');
|
|
166
|
+
attrs.MathMLRepresentation = xmlSerializer.serializeToString(child);
|
|
167
|
+
if (attrs.MathMLRepresentation) {
|
|
168
|
+
attrs.SVGRepresentation =
|
|
169
|
+
(_e = convertMathMLToSVG(attrs.MathMLRepresentation, true)) !== null && _e !== void 0 ? _e : '';
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return attrs;
|
|
162
175
|
},
|
|
163
176
|
},
|
|
164
177
|
{
|
|
165
178
|
tag: 'disp-formula',
|
|
166
179
|
node: 'equation_element',
|
|
167
180
|
getAttrs: (node) => {
|
|
168
|
-
var _a, _b;
|
|
169
181
|
const element = node;
|
|
182
|
+
const caption = element.querySelector('figcaption');
|
|
170
183
|
return {
|
|
171
184
|
id: element.getAttribute('id'),
|
|
172
|
-
|
|
185
|
+
suppressCaption: !caption,
|
|
173
186
|
};
|
|
174
187
|
},
|
|
175
188
|
getContent: (node, schema) => {
|
|
189
|
+
var _a, _b, _c, _d, _e;
|
|
176
190
|
const element = node;
|
|
177
|
-
const attrs =
|
|
178
|
-
|
|
191
|
+
const attrs = {
|
|
192
|
+
MathMLStringRepresentation: '',
|
|
193
|
+
SVGStringRepresentation: '',
|
|
194
|
+
TeXRepresentation: '',
|
|
195
|
+
};
|
|
196
|
+
const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
|
|
197
|
+
for (const child of container.childNodes) {
|
|
198
|
+
const nodeName = child.nodeName.replace(/^[a-z]:/, '');
|
|
199
|
+
switch (nodeName) {
|
|
200
|
+
case 'tex-math':
|
|
201
|
+
attrs.TeXRepresentation = (_c = (_b = child.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '';
|
|
202
|
+
if (attrs.TeXRepresentation) {
|
|
203
|
+
attrs.SVGStringRepresentation =
|
|
204
|
+
(_d = convertTeXToSVG(attrs.TeXRepresentation, true)) !== null && _d !== void 0 ? _d : '';
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
case 'mml:math':
|
|
208
|
+
;
|
|
209
|
+
child.removeAttribute('id');
|
|
210
|
+
attrs.MathMLStringRepresentation =
|
|
211
|
+
xmlSerializer.serializeToString(child);
|
|
212
|
+
if (attrs.MathMLStringRepresentation) {
|
|
213
|
+
attrs.SVGStringRepresentation =
|
|
214
|
+
(_e = convertMathMLToSVG(attrs.MathMLStringRepresentation, true)) !== null && _e !== void 0 ? _e : '';
|
|
215
|
+
}
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const caption = element.querySelector('figcaption');
|
|
220
|
+
const figcaption = schema.nodes.figcaption.create();
|
|
179
221
|
return Fragment.from([
|
|
180
|
-
schema.nodes.equation.createChecked(
|
|
222
|
+
schema.nodes.equation.createChecked(attrs),
|
|
223
|
+
caption
|
|
224
|
+
?
|
|
225
|
+
jatsBodyDOMParser.parse(caption, {
|
|
226
|
+
topNode: figcaption,
|
|
227
|
+
})
|
|
228
|
+
: figcaption,
|
|
181
229
|
]);
|
|
182
230
|
},
|
|
183
231
|
},
|
|
@@ -514,7 +562,7 @@ const nodes = [
|
|
|
514
562
|
},
|
|
515
563
|
{
|
|
516
564
|
tag: 'th',
|
|
517
|
-
node: '
|
|
565
|
+
node: 'table_header',
|
|
518
566
|
getAttrs: (node) => {
|
|
519
567
|
const element = node;
|
|
520
568
|
const colspan = element.getAttribute('colspan');
|
|
@@ -156,7 +156,6 @@ export class JATSExporter {
|
|
|
156
156
|
};
|
|
157
157
|
this.nodeFromJATS = (JATSFragment) => {
|
|
158
158
|
JATSFragment = JATSFragment.trim();
|
|
159
|
-
JATSFragment = JATSFragment.replace(' ', ' ');
|
|
160
159
|
if (!JATSFragment.length) {
|
|
161
160
|
return null;
|
|
162
161
|
}
|
|
@@ -607,6 +606,11 @@ export class JATSExporter {
|
|
|
607
606
|
this.createSerializer = () => {
|
|
608
607
|
const getModel = (id) => id ? this.modelMap.get(id) : undefined;
|
|
609
608
|
const nodes = {
|
|
609
|
+
table_header: (node) => [
|
|
610
|
+
node.attrs.celltype,
|
|
611
|
+
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
612
|
+
0,
|
|
613
|
+
],
|
|
610
614
|
title: () => '',
|
|
611
615
|
affiliations: () => '',
|
|
612
616
|
contributors: () => '',
|
|
@@ -679,23 +683,22 @@ export class JATSExporter {
|
|
|
679
683
|
},
|
|
680
684
|
doc: () => '',
|
|
681
685
|
equation: (node) => {
|
|
682
|
-
const
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
processChildNodes(eqElement, node, schema.nodes.equation);
|
|
697
|
-
return eqElement;
|
|
686
|
+
const formula = this.document.createElement('disp-formula');
|
|
687
|
+
formula.setAttribute('id', normalizeID(node.attrs.id));
|
|
688
|
+
if (node.attrs.TeXRepresentation) {
|
|
689
|
+
const math = this.document.createElement('tex-math');
|
|
690
|
+
math.textContent = node.attrs.TeXRepresentation;
|
|
691
|
+
formula.appendChild(math);
|
|
692
|
+
}
|
|
693
|
+
else if (node.attrs.MathMLStringRepresentation) {
|
|
694
|
+
const math = this.nodeFromJATS(node.attrs.MathMLStringRepresentation);
|
|
695
|
+
if (math) {
|
|
696
|
+
formula.appendChild(math);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return formula;
|
|
698
700
|
},
|
|
701
|
+
equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
|
|
699
702
|
figcaption: (node) => {
|
|
700
703
|
if (!node.textContent) {
|
|
701
704
|
return '';
|
|
@@ -745,6 +748,28 @@ export class JATSExporter {
|
|
|
745
748
|
},
|
|
746
749
|
hard_break: () => '',
|
|
747
750
|
highlight_marker: () => '',
|
|
751
|
+
inline_equation: (node) => {
|
|
752
|
+
const formula = this.document.createElement('inline-formula');
|
|
753
|
+
formula.setAttribute('id', normalizeID(node.attrs.id));
|
|
754
|
+
if (node.attrs.TeXRepresentation) {
|
|
755
|
+
const math = this.document.createElement('tex-math');
|
|
756
|
+
math.textContent = node.attrs.TeXRepresentation;
|
|
757
|
+
formula.appendChild(math);
|
|
758
|
+
}
|
|
759
|
+
else if (node.attrs.MathMLRepresentation) {
|
|
760
|
+
const math = this.nodeFromJATS(node.attrs.MathMLRepresentation);
|
|
761
|
+
if (math) {
|
|
762
|
+
formula.appendChild(math);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
else if (node.attrs.SVGRepresentation) {
|
|
766
|
+
const math = this.nodeFromJATS(node.attrs.SVGRepresentation);
|
|
767
|
+
if (math) {
|
|
768
|
+
formula.appendChild(math);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
return formula;
|
|
772
|
+
},
|
|
748
773
|
inline_footnote: (node) => {
|
|
749
774
|
const xref = this.document.createElement('xref');
|
|
750
775
|
xref.setAttribute('ref-type', 'fn');
|
|
@@ -845,7 +870,6 @@ export class JATSExporter {
|
|
|
845
870
|
element.setAttribute('position', 'anchor');
|
|
846
871
|
return element;
|
|
847
872
|
},
|
|
848
|
-
table_body: () => ['tbody', 0],
|
|
849
873
|
table_cell: (node) => [
|
|
850
874
|
node.attrs.celltype,
|
|
851
875
|
Object.assign(Object.assign({ valign: node.attrs.valign, align: node.attrs.align, scope: node.attrs.scope, style: node.attrs.style }, (node.attrs.rowspan > 1 && { rowspan: node.attrs.rowspan })), (node.attrs.colspan > 1 && { colspan: node.attrs.colspan })),
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const convertMathMLToSVG = async (mathml, display) => {
|
|
2
|
+
const { convertMathMLToSVG } = await import('./mathml-to-svg');
|
|
3
|
+
return convertMathMLToSVG(mathml, display);
|
|
4
|
+
};
|
|
5
|
+
export const convertTeXToMathML = async (tex, display) => {
|
|
6
|
+
const { convertTeXToMathML } = await import('./tex-to-mathml');
|
|
7
|
+
return convertTeXToMathML(tex, display);
|
|
8
|
+
};
|
|
9
|
+
export const convertTeXToSVG = async (tex, display) => {
|
|
10
|
+
const { convertTeXToSVG } = await import('./tex-to-svg');
|
|
11
|
+
return convertTeXToSVG(tex, display);
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
|
|
17
|
+
export const packages = AllPackages.filter((name) => name !== 'html' && name !== 'bussproofs');
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import 'mathjax-full/js/util/entities/all';
|
|
17
|
+
import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
|
|
18
|
+
import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
|
|
19
|
+
import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
|
|
20
|
+
import { MathML } from 'mathjax-full/js/input/mathml';
|
|
21
|
+
import { SVG } from 'mathjax-full/js/output/svg';
|
|
22
|
+
import { xmlSerializer } from '../transformer';
|
|
23
|
+
class ManuscriptsMmlFactory extends MmlFactory {
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.nodeMap.set('image', this.nodeMap.get('none'));
|
|
27
|
+
}
|
|
28
|
+
create(kind, properties = {}, children = []) {
|
|
29
|
+
if (kind === 'image') {
|
|
30
|
+
return this.node['none'](properties, children);
|
|
31
|
+
}
|
|
32
|
+
return this.node[kind](properties, children);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
|
|
36
|
+
setAttribute(node, name, value, ns) {
|
|
37
|
+
if (name !== 'xmlns') {
|
|
38
|
+
ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const InputJax = new MathML();
|
|
43
|
+
const OutputJax = new SVG({
|
|
44
|
+
fontCache: 'none',
|
|
45
|
+
});
|
|
46
|
+
const adaptor = new ManuscriptsHTMLAdaptor(window);
|
|
47
|
+
const doc = new HTMLDocument(document, adaptor, {
|
|
48
|
+
InputJax,
|
|
49
|
+
OutputJax,
|
|
50
|
+
MmlFactory: new ManuscriptsMmlFactory(),
|
|
51
|
+
});
|
|
52
|
+
doc.addStyleSheet();
|
|
53
|
+
export const convertMathMLToSVG = (mathml, display) => {
|
|
54
|
+
const item = doc.convert(mathml, {
|
|
55
|
+
display,
|
|
56
|
+
em: 16,
|
|
57
|
+
ex: 8,
|
|
58
|
+
containerWidth: 1000000,
|
|
59
|
+
lineWidth: 1000000,
|
|
60
|
+
scale: 1,
|
|
61
|
+
});
|
|
62
|
+
if (!item || !item.firstChild) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return xmlSerializer.serializeToString(item.firstChild);
|
|
66
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import 'mathjax-full/js/util/entities/all';
|
|
17
|
+
import { HTMLAdaptor } from 'mathjax-full/js/adaptors/HTMLAdaptor';
|
|
18
|
+
import { STATE } from 'mathjax-full/js/core/MathItem.js';
|
|
19
|
+
import { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';
|
|
20
|
+
import { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
|
|
21
|
+
import { TeX } from 'mathjax-full/js/input/tex';
|
|
22
|
+
import { packages } from './mathjax-packages';
|
|
23
|
+
const InputJax = new TeX({
|
|
24
|
+
packages,
|
|
25
|
+
});
|
|
26
|
+
const adaptor = new HTMLAdaptor(window);
|
|
27
|
+
const doc = new HTMLDocument(document, adaptor, {
|
|
28
|
+
InputJax,
|
|
29
|
+
});
|
|
30
|
+
const visitor = new SerializedMmlVisitor();
|
|
31
|
+
export const convertTeXToMathML = (tex, display) => {
|
|
32
|
+
const item = doc.convert(tex, {
|
|
33
|
+
display,
|
|
34
|
+
em: 16,
|
|
35
|
+
ex: 8,
|
|
36
|
+
containerWidth: 1000000,
|
|
37
|
+
lineWidth: 1000000,
|
|
38
|
+
scale: 1,
|
|
39
|
+
end: STATE.CONVERT,
|
|
40
|
+
});
|
|
41
|
+
if (!item) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return visitor.visitTree(item);
|
|
45
|
+
};
|