@manuscripts/transform 2.1.1-LEAN-3092-9 → 2.1.1-LEAN-3336-21
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 +74 -33
- package/dist/cjs/jats/importer/jats-body-transformations.js +0 -13
- package/dist/cjs/jats/importer/jats-parser-utils.js +0 -6
- package/dist/cjs/jats/jats-exporter.js +64 -32
- 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 +4 -5
- 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 +15 -13
- package/dist/cjs/schema/nodes/table.js +73 -30
- package/dist/cjs/schema/nodes/table_element.js +1 -1
- package/dist/cjs/transformer/builders.js +8 -1
- package/dist/cjs/transformer/decode.js +26 -7
- package/dist/cjs/transformer/encode.js +27 -6
- 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 +75 -34
- package/dist/es/jats/importer/jats-body-transformations.js +0 -13
- package/dist/es/jats/importer/jats-parser-utils.js +0 -6
- package/dist/es/jats/jats-exporter.js +64 -32
- 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 +3 -4
- 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 +15 -13
- package/dist/es/schema/nodes/table.js +72 -29
- package/dist/es/schema/nodes/table_element.js +1 -1
- package/dist/es/transformer/builders.js +6 -0
- package/dist/es/transformer/decode.js +26 -7
- package/dist/es/transformer/encode.js +27 -6
- 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/jats/jats-exporter.d.ts +0 -1
- 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 -1
- 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 +3 -4
- package/dist/types/schema/nodes/table.d.ts +72 -10
- package/dist/types/schema/types.d.ts +1 -1
- package/dist/types/transformer/builders.d.ts +2 -1
- package/dist/types/transformer/decode.d.ts +1 -0
- package/package.json +7 -5
- package/dist/cjs/schema/nodes/table_row.js +0 -123
- package/dist/es/schema/nodes/table_row.js +0 -120
- package/dist/types/schema/nodes/table_row.d.ts +0 -41
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*!
|
|
3
|
-
* ©
|
|
3
|
+
* © 2019 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,8 +20,9 @@ const json_schema_1 = require("@manuscripts/json-schema");
|
|
|
20
20
|
exports.equation = {
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
MathMLStringRepresentation: { default: '' },
|
|
24
|
+
SVGStringRepresentation: { default: '' },
|
|
25
|
+
TeXRepresentation: { default: '' },
|
|
25
26
|
dataTracked: { default: null },
|
|
26
27
|
},
|
|
27
28
|
group: 'block',
|
|
@@ -29,25 +30,26 @@ exports.equation = {
|
|
|
29
30
|
{
|
|
30
31
|
tag: `div.${json_schema_1.ObjectTypes.Equation}`,
|
|
31
32
|
getAttrs: (p) => {
|
|
32
|
-
const
|
|
33
|
+
const dom = p;
|
|
33
34
|
return {
|
|
34
|
-
id:
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
id: dom.getAttribute('id'),
|
|
36
|
+
MathMLStringRepresentation: dom.getAttribute('data-mathml-string-representation'),
|
|
37
|
+
SVGStringRepresentation: dom.innerHTML,
|
|
38
|
+
TeXRepresentation: dom.getAttribute('data-tex-representation'),
|
|
37
39
|
};
|
|
38
40
|
},
|
|
39
41
|
},
|
|
40
42
|
],
|
|
41
43
|
toDOM: (node) => {
|
|
42
44
|
const equationNode = node;
|
|
43
|
-
const { id, contents, format } = equationNode.attrs;
|
|
44
45
|
const dom = document.createElement('div');
|
|
46
|
+
dom.setAttribute('id', equationNode.attrs.id);
|
|
45
47
|
dom.classList.add(json_schema_1.ObjectTypes.Equation);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
dom.setAttribute('data-equation-format', format);
|
|
48
|
+
if (equationNode.attrs.MathMLStringRepresentation) {
|
|
49
|
+
dom.setAttribute('data-mathml-string-representation', equationNode.attrs.MathMLStringRepresentation);
|
|
49
50
|
}
|
|
50
|
-
dom.
|
|
51
|
+
dom.setAttribute('data-tex-representation', equationNode.attrs.TeXRepresentation);
|
|
52
|
+
dom.innerHTML = equationNode.attrs.SVGStringRepresentation;
|
|
51
53
|
return dom;
|
|
52
54
|
},
|
|
53
55
|
};
|
|
@@ -17,10 +17,11 @@
|
|
|
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) figcaption',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
|
-
|
|
23
|
+
suppressCaption: { default: true },
|
|
24
|
+
suppressTitle: { default: undefined },
|
|
24
25
|
dataTracked: { default: null },
|
|
25
26
|
comments: { default: null },
|
|
26
27
|
},
|
|
@@ -28,7 +29,7 @@ exports.equationElement = {
|
|
|
28
29
|
group: 'block element',
|
|
29
30
|
parseDOM: [
|
|
30
31
|
{
|
|
31
|
-
tag: '
|
|
32
|
+
tag: 'figure.equation',
|
|
32
33
|
getAttrs: (p) => {
|
|
33
34
|
const dom = p;
|
|
34
35
|
return {
|
|
@@ -40,7 +41,7 @@ exports.equationElement = {
|
|
|
40
41
|
toDOM: (node) => {
|
|
41
42
|
const equationElementNode = node;
|
|
42
43
|
return [
|
|
43
|
-
'
|
|
44
|
+
'figure',
|
|
44
45
|
{
|
|
45
46
|
class: 'equation',
|
|
46
47
|
id: equationElementNode.attrs.id,
|
|
@@ -16,13 +16,14 @@
|
|
|
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");
|
|
19
20
|
exports.inlineEquation = {
|
|
20
21
|
attrs: {
|
|
21
|
-
dataTracked: { default: null },
|
|
22
|
-
comments: { default: null },
|
|
23
22
|
id: { default: '' },
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
MathMLRepresentation: { default: '' },
|
|
24
|
+
SVGRepresentation: { default: '' },
|
|
25
|
+
TeXRepresentation: { default: '' },
|
|
26
|
+
dataTracked: { default: null },
|
|
26
27
|
},
|
|
27
28
|
atom: true,
|
|
28
29
|
inline: true,
|
|
@@ -30,27 +31,28 @@ exports.inlineEquation = {
|
|
|
30
31
|
group: 'inline',
|
|
31
32
|
parseDOM: [
|
|
32
33
|
{
|
|
33
|
-
tag: `span.
|
|
34
|
+
tag: `span.${json_schema_1.ObjectTypes.InlineMathFragment}`,
|
|
34
35
|
getAttrs: (p) => {
|
|
35
36
|
const dom = p;
|
|
36
37
|
return {
|
|
37
|
-
format: dom.getAttribute('data-equation-format'),
|
|
38
38
|
id: dom.getAttribute('id'),
|
|
39
|
-
|
|
39
|
+
MathMLRepresentation: dom.getAttribute('data-mathml-representation') || '',
|
|
40
|
+
SVGRepresentation: dom.innerHTML || '',
|
|
41
|
+
TeXRepresentation: dom.getAttribute('data-tex-representation') || '',
|
|
40
42
|
};
|
|
41
43
|
},
|
|
42
44
|
},
|
|
43
45
|
],
|
|
44
46
|
toDOM: (node) => {
|
|
45
47
|
const inlineEquationNode = node;
|
|
46
|
-
const { id, contents, format } = inlineEquationNode.attrs;
|
|
47
48
|
const dom = document.createElement('span');
|
|
48
|
-
dom.
|
|
49
|
-
dom.
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
dom.classList.add(json_schema_1.ObjectTypes.InlineMathFragment);
|
|
50
|
+
dom.setAttribute('id', inlineEquationNode.attrs.id);
|
|
51
|
+
dom.setAttribute('data-tex-representation', inlineEquationNode.attrs.TeXRepresentation);
|
|
52
|
+
if (inlineEquationNode.attrs.MathMLRepresentation) {
|
|
53
|
+
dom.setAttribute('data-mathml-representation', inlineEquationNode.attrs.MathMLRepresentation);
|
|
52
54
|
}
|
|
53
|
-
dom.innerHTML =
|
|
55
|
+
dom.innerHTML = inlineEquationNode.attrs.SVGRepresentation;
|
|
54
56
|
return dom;
|
|
55
57
|
},
|
|
56
58
|
};
|
|
@@ -15,20 +15,78 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.tableHeader = exports.tableCell = exports.tableRow = exports.table = void 0;
|
|
19
|
+
const prosemirror_tables_1 = require("prosemirror-tables");
|
|
20
|
+
const tableOptions = {
|
|
21
|
+
cellContent: 'inline*',
|
|
22
|
+
cellAttributes: {
|
|
23
|
+
placeholder: {
|
|
24
|
+
default: 'Data',
|
|
25
|
+
getFromDOM(dom) {
|
|
26
|
+
return dom.getAttribute('data-placeholder-text') || '';
|
|
27
|
+
},
|
|
28
|
+
setDOMAttr(value, attrs) {
|
|
29
|
+
if (value) {
|
|
30
|
+
attrs['data-placeholder-text'] = value;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
valign: {
|
|
35
|
+
default: null,
|
|
36
|
+
getFromDOM(dom) {
|
|
37
|
+
return dom.getAttribute('valign');
|
|
38
|
+
},
|
|
39
|
+
setDOMAttr(value, attrs) {
|
|
40
|
+
if (value) {
|
|
41
|
+
attrs['valign'] = value;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
align: {
|
|
46
|
+
default: null,
|
|
47
|
+
getFromDOM(dom) {
|
|
48
|
+
return dom.getAttribute('align');
|
|
49
|
+
},
|
|
50
|
+
setDOMAttr(value, attrs) {
|
|
51
|
+
if (value) {
|
|
52
|
+
attrs['align'] = value;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
scope: {
|
|
57
|
+
default: null,
|
|
58
|
+
getFromDOM(dom) {
|
|
59
|
+
return dom.getAttribute('scope');
|
|
60
|
+
},
|
|
61
|
+
setDOMAttr(value, attrs) {
|
|
62
|
+
if (value) {
|
|
63
|
+
attrs['scope'] = value;
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
style: {
|
|
68
|
+
default: null,
|
|
69
|
+
getFromDOM(dom) {
|
|
70
|
+
return dom.getAttribute('style');
|
|
71
|
+
},
|
|
72
|
+
setDOMAttr(value, attrs) {
|
|
73
|
+
if (value) {
|
|
74
|
+
attrs['style'] = value;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
const tableNodes = (0, prosemirror_tables_1.tableNodes)(tableOptions);
|
|
19
81
|
exports.table = {
|
|
20
|
-
content: 'table_colgroup? table_body',
|
|
21
|
-
tableRole: 'table',
|
|
22
|
-
isolating: true,
|
|
23
|
-
group: 'block',
|
|
24
|
-
selectable: false,
|
|
25
82
|
attrs: {
|
|
26
83
|
id: { default: '' },
|
|
27
|
-
headerRows: { default: 1 },
|
|
28
|
-
footerRows: { default: 1 },
|
|
29
84
|
dataTracked: { default: null },
|
|
30
|
-
comments: { default: null },
|
|
31
85
|
},
|
|
86
|
+
content: 'table_row+',
|
|
87
|
+
tableRole: 'table',
|
|
88
|
+
isolating: true,
|
|
89
|
+
group: 'block',
|
|
32
90
|
parseDOM: [
|
|
33
91
|
{
|
|
34
92
|
tag: 'table',
|
|
@@ -36,35 +94,20 @@ exports.table = {
|
|
|
36
94
|
const dom = p;
|
|
37
95
|
return {
|
|
38
96
|
id: dom.getAttribute('id'),
|
|
39
|
-
headerRows: dom.dataset && dom.dataset['header-rows'],
|
|
40
|
-
footerRows: dom.dataset && dom.dataset['footer-rows'],
|
|
41
97
|
};
|
|
42
98
|
},
|
|
43
99
|
},
|
|
44
100
|
],
|
|
45
|
-
toDOM
|
|
46
|
-
const tableNode = node;
|
|
101
|
+
toDOM(node) {
|
|
47
102
|
return [
|
|
48
103
|
'table',
|
|
49
104
|
{
|
|
50
|
-
id:
|
|
51
|
-
'data-header-rows': String(node.attrs.headerRows),
|
|
52
|
-
'data-footer-rows': String(node.attrs.footerRows),
|
|
105
|
+
id: node.attrs.id,
|
|
53
106
|
},
|
|
54
|
-
0,
|
|
107
|
+
['tbody', 0],
|
|
55
108
|
];
|
|
56
109
|
},
|
|
57
110
|
};
|
|
58
|
-
exports.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
tableRole: 'table',
|
|
62
|
-
parseDOM: [
|
|
63
|
-
{
|
|
64
|
-
tag: 'tbody',
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
toDOM() {
|
|
68
|
-
return ['tbody', 0];
|
|
69
|
-
},
|
|
70
|
-
};
|
|
111
|
+
exports.tableRow = Object.assign(Object.assign({}, tableNodes.table_row), { attrs: Object.assign(Object.assign({}, tableNodes.table_row.attrs), { dataTracked: { default: null } }) });
|
|
112
|
+
exports.tableCell = Object.assign(Object.assign({}, tableNodes.table_cell), { attrs: Object.assign(Object.assign({}, tableNodes.table_cell.attrs), { dataTracked: { default: null } }) });
|
|
113
|
+
exports.tableHeader = Object.assign(Object.assign({}, tableNodes.table_header), { attrs: Object.assign(Object.assign({}, tableNodes.table_header.attrs), { dataTracked: { default: null } }) });
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.tableElement = void 0;
|
|
19
19
|
exports.tableElement = {
|
|
20
|
-
content: '(table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
20
|
+
content: 'table_colgroup? (table | placeholder) table_element_footer? figcaption? (listing | placeholder)',
|
|
21
21
|
attrs: {
|
|
22
22
|
id: { default: '' },
|
|
23
23
|
paragraphStyle: { default: '' },
|
|
@@ -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;
|
|
@@ -566,13 +569,19 @@ class Decoder {
|
|
|
566
569
|
[json_schema_1.ObjectTypes.TableElement]: (data) => {
|
|
567
570
|
const model = data;
|
|
568
571
|
const table = this.createTable(model);
|
|
572
|
+
const tableColGroup = this.createTableColGroup(model);
|
|
569
573
|
const tableElementFooter = this.createTableElementFooter(model);
|
|
570
574
|
const figcaption = this.getFigcaption(model);
|
|
571
575
|
const comments = this.createCommentNodes(model);
|
|
572
576
|
comments.forEach((c) => this.comments.set(c.attrs.id, c));
|
|
573
|
-
const content =
|
|
574
|
-
|
|
575
|
-
|
|
577
|
+
const content = [table];
|
|
578
|
+
if (tableColGroup) {
|
|
579
|
+
content.unshift(tableColGroup);
|
|
580
|
+
}
|
|
581
|
+
if (tableElementFooter) {
|
|
582
|
+
content.push(tableElementFooter);
|
|
583
|
+
}
|
|
584
|
+
content.push(figcaption);
|
|
576
585
|
if (model.listingID) {
|
|
577
586
|
const listing = this.createListing(model.listingID);
|
|
578
587
|
content.push(listing);
|
|
@@ -786,6 +795,16 @@ class Decoder {
|
|
|
786
795
|
}
|
|
787
796
|
return table;
|
|
788
797
|
}
|
|
798
|
+
createTableColGroup(model) {
|
|
799
|
+
const tableId = model.containedObjectID;
|
|
800
|
+
const tableModel = this.getModel(tableId);
|
|
801
|
+
if (!tableModel || !tableModel.contents.includes('<colgroup>')) {
|
|
802
|
+
return undefined;
|
|
803
|
+
}
|
|
804
|
+
return this.parseContents(tableModel.contents, undefined, [], {
|
|
805
|
+
topNode: schema_1.schema.nodes.table_colgroup.create(),
|
|
806
|
+
});
|
|
807
|
+
}
|
|
789
808
|
createTableElementFooter(model) {
|
|
790
809
|
const tableElementFooterID = model.tableElementFooterID;
|
|
791
810
|
if (!tableElementFooterID) {
|
|
@@ -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':
|
|
@@ -109,8 +115,9 @@ function buildTableColGroup(cols) {
|
|
|
109
115
|
}
|
|
110
116
|
const tableContents = (node, parent) => {
|
|
111
117
|
const input = serializer.serializeNode(node);
|
|
118
|
+
const parentInput = serializer.serializeNode(parent);
|
|
112
119
|
const output = document.createElement('table');
|
|
113
|
-
const colgroup = buildTableColGroup(Array.from(
|
|
120
|
+
const colgroup = buildTableColGroup(Array.from(parentInput.querySelectorAll('col')));
|
|
114
121
|
if (colgroup) {
|
|
115
122
|
output.appendChild(colgroup);
|
|
116
123
|
}
|
|
@@ -347,13 +354,20 @@ const encoders = {
|
|
|
347
354
|
: false,
|
|
348
355
|
}),
|
|
349
356
|
equation: (node) => ({
|
|
350
|
-
|
|
351
|
-
|
|
357
|
+
MathMLStringRepresentation: node.attrs.MathMLStringRepresentation || undefined,
|
|
358
|
+
TeXRepresentation: node.attrs.TeXRepresentation,
|
|
359
|
+
SVGStringRepresentation: node.attrs.SVGStringRepresentation,
|
|
352
360
|
}),
|
|
353
361
|
equation_element: (node) => ({
|
|
354
362
|
containedObjectID: attributeOfNodeType(node, 'equation', 'id'),
|
|
355
|
-
|
|
356
|
-
|
|
363
|
+
caption: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption),
|
|
364
|
+
title: inlineContentOfChildNodeType(node, node.type.schema.nodes.figcaption, node.type.schema.nodes.caption_title, false),
|
|
365
|
+
elementType: 'p',
|
|
366
|
+
suppressCaption: Boolean(node.attrs.suppressCaption) || undefined,
|
|
367
|
+
suppressTitle: node.attrs.suppressTitle === undefined ||
|
|
368
|
+
node.attrs.suppressTitle === true
|
|
369
|
+
? undefined
|
|
370
|
+
: false,
|
|
357
371
|
}),
|
|
358
372
|
figure: (node) => ({
|
|
359
373
|
contentType: node.attrs.contentType || undefined,
|
|
@@ -400,6 +414,12 @@ const encoders = {
|
|
|
400
414
|
.map((childNode) => childNode.attrs.id)
|
|
401
415
|
.filter((id) => id),
|
|
402
416
|
}),
|
|
417
|
+
inline_equation: (node, parent) => ({
|
|
418
|
+
containingObject: parent.attrs.id,
|
|
419
|
+
TeXRepresentation: node.attrs.TeXRepresentation,
|
|
420
|
+
SVGRepresentation: node.attrs.SVGRepresentation,
|
|
421
|
+
SVGGlyphs: svgDefs(node.attrs.SVGRepresentation),
|
|
422
|
+
}),
|
|
403
423
|
keyword: (node, parent) => ({
|
|
404
424
|
containedGroup: parent.attrs.id,
|
|
405
425
|
name: keywordContents(node),
|
|
@@ -573,7 +593,8 @@ const encode = (node) => {
|
|
|
573
593
|
if (placeholderTypes.includes(child.type)) {
|
|
574
594
|
return;
|
|
575
595
|
}
|
|
576
|
-
if (parent.type === schema_1.schema.nodes.paragraph
|
|
596
|
+
if (parent.type === schema_1.schema.nodes.paragraph &&
|
|
597
|
+
child.type !== schema_1.schema.nodes.inline_equation) {
|
|
577
598
|
return;
|
|
578
599
|
}
|
|
579
600
|
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,28 +33,6 @@ const chooseContentType = (graphicNode) => {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
|
-
const getEquationContent = (p) => {
|
|
35
|
-
var _a;
|
|
36
|
-
const element = p;
|
|
37
|
-
const id = element.getAttribute('id');
|
|
38
|
-
const container = (_a = element.querySelector('alternatives')) !== null && _a !== void 0 ? _a : element;
|
|
39
|
-
let contents = '';
|
|
40
|
-
let format = '';
|
|
41
|
-
for (const child of container.childNodes) {
|
|
42
|
-
const nodeName = child.nodeName.replace(/^[a-z]:/, '');
|
|
43
|
-
switch (nodeName) {
|
|
44
|
-
case 'tex-math':
|
|
45
|
-
contents = child.innerHTML;
|
|
46
|
-
format = 'tex';
|
|
47
|
-
break;
|
|
48
|
-
case 'mml:math':
|
|
49
|
-
contents = child.outerHTML;
|
|
50
|
-
format = 'mathml';
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return { id, format, contents };
|
|
55
|
-
};
|
|
56
36
|
const marks = [
|
|
57
37
|
{
|
|
58
38
|
tag: 'bold',
|
|
@@ -161,26 +141,91 @@ const nodes = [
|
|
|
161
141
|
tag: 'inline-formula',
|
|
162
142
|
node: 'inline_equation',
|
|
163
143
|
getAttrs: (node) => {
|
|
144
|
+
var _a, _b, _c, _d, _e;
|
|
164
145
|
const element = node;
|
|
165
|
-
|
|
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;
|
|
166
175
|
},
|
|
167
176
|
},
|
|
168
177
|
{
|
|
169
178
|
tag: 'disp-formula',
|
|
170
179
|
node: 'equation_element',
|
|
171
180
|
getAttrs: (node) => {
|
|
172
|
-
var _a, _b;
|
|
173
181
|
const element = node;
|
|
182
|
+
const caption = element.querySelector('figcaption');
|
|
174
183
|
return {
|
|
175
184
|
id: element.getAttribute('id'),
|
|
176
|
-
|
|
185
|
+
suppressCaption: !caption,
|
|
177
186
|
};
|
|
178
187
|
},
|
|
179
188
|
getContent: (node, schema) => {
|
|
189
|
+
var _a, _b, _c, _d, _e;
|
|
180
190
|
const element = node;
|
|
181
|
-
const attrs =
|
|
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();
|
|
182
221
|
return Fragment.from([
|
|
183
|
-
schema.nodes.equation.createChecked(
|
|
222
|
+
schema.nodes.equation.createChecked(attrs),
|
|
223
|
+
caption
|
|
224
|
+
?
|
|
225
|
+
jatsBodyDOMParser.parse(caption, {
|
|
226
|
+
topNode: figcaption,
|
|
227
|
+
})
|
|
228
|
+
: figcaption,
|
|
184
229
|
]);
|
|
185
230
|
},
|
|
186
231
|
},
|
|
@@ -479,10 +524,6 @@ const nodes = [
|
|
|
479
524
|
};
|
|
480
525
|
},
|
|
481
526
|
},
|
|
482
|
-
{
|
|
483
|
-
tag: 'tbody',
|
|
484
|
-
skip: true,
|
|
485
|
-
},
|
|
486
527
|
{
|
|
487
528
|
tag: 'tfoot',
|
|
488
529
|
skip: true,
|
|
@@ -517,12 +558,12 @@ const nodes = [
|
|
|
517
558
|
},
|
|
518
559
|
{
|
|
519
560
|
tag: 'th',
|
|
520
|
-
node: '
|
|
561
|
+
node: 'table_header',
|
|
521
562
|
getAttrs: (node) => {
|
|
522
563
|
const element = node;
|
|
523
564
|
const colspan = element.getAttribute('colspan');
|
|
524
565
|
const rowspan = element.getAttribute('rowspan');
|
|
525
|
-
return Object.assign(Object.assign(Object.assign({
|
|
566
|
+
return Object.assign(Object.assign(Object.assign({}, (colspan && { colspan })), (rowspan && { rowspan })), { valign: element.getAttribute('valign'), align: element.getAttribute('align'), scope: element.getAttribute('scope'), style: element.getAttribute('style') });
|
|
526
567
|
},
|
|
527
568
|
},
|
|
528
569
|
{
|
|
@@ -247,19 +247,6 @@ export const jatsBodyTransformations = {
|
|
|
247
247
|
}
|
|
248
248
|
table.insertBefore(colgroup, table.firstChild);
|
|
249
249
|
}
|
|
250
|
-
const tbody = table.querySelector('tbody');
|
|
251
|
-
if (tbody) {
|
|
252
|
-
const headerRow = table.querySelector('thead > tr');
|
|
253
|
-
if (!headerRow) {
|
|
254
|
-
const tr = createElement('tr');
|
|
255
|
-
tbody.insertBefore(tr, tbody.firstElementChild);
|
|
256
|
-
}
|
|
257
|
-
const footerRow = table.querySelector('tfoot > tr');
|
|
258
|
-
if (!footerRow) {
|
|
259
|
-
const tr = createElement('tr');
|
|
260
|
-
tbody.appendChild(tr);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
250
|
});
|
|
264
251
|
},
|
|
265
252
|
moveFloatsGroupToBody(doc, body, createElement) {
|