@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
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
17
|
-
import { schema } from '../../schema';
|
|
18
16
|
import { generateID, nodeTypesMap } from '../../transformer';
|
|
19
17
|
export const updateDocumentIDs = (node, replacements) => {
|
|
20
18
|
const warnings = [];
|
|
@@ -28,10 +26,6 @@ function recurseDoc(node, fn) {
|
|
|
28
26
|
node.descendants((n) => fn(n));
|
|
29
27
|
}
|
|
30
28
|
const updateNodeID = (node, replacements, warnings) => {
|
|
31
|
-
if (node.type === schema.nodes.inline_equation) {
|
|
32
|
-
node.attrs = Object.assign(Object.assign({}, node.attrs), { id: `InlineMathFragment:${uuidv4()}` });
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
29
|
if (!('id' in node.attrs)) {
|
|
36
30
|
return;
|
|
37
31
|
}
|
|
@@ -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
|
+
'th',
|
|
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,20 +683,22 @@ export class JATSExporter {
|
|
|
679
683
|
},
|
|
680
684
|
doc: () => '',
|
|
681
685
|
equation: (node) => {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
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;
|
|
695
700
|
},
|
|
701
|
+
equation_element: (node) => createFigureElement(node, 'fig', node.type.schema.nodes.equation, 'equation'),
|
|
696
702
|
figcaption: (node) => {
|
|
697
703
|
if (!node.textContent) {
|
|
698
704
|
return '';
|
|
@@ -742,6 +748,28 @@ export class JATSExporter {
|
|
|
742
748
|
},
|
|
743
749
|
hard_break: () => '',
|
|
744
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
|
+
},
|
|
745
773
|
inline_footnote: (node) => {
|
|
746
774
|
const xref = this.document.createElement('xref');
|
|
747
775
|
xref.setAttribute('ref-type', 'fn');
|
|
@@ -842,9 +870,8 @@ export class JATSExporter {
|
|
|
842
870
|
element.setAttribute('position', 'anchor');
|
|
843
871
|
return element;
|
|
844
872
|
},
|
|
845
|
-
table_body: () => ['tbody', 0],
|
|
846
873
|
table_cell: (node) => [
|
|
847
|
-
|
|
874
|
+
'td',
|
|
848
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 })),
|
|
849
876
|
0,
|
|
850
877
|
],
|
|
@@ -925,6 +952,26 @@ export class JATSExporter {
|
|
|
925
952
|
element.appendChild(this.serializeNode(childNode));
|
|
926
953
|
}
|
|
927
954
|
};
|
|
955
|
+
const appendTable = (element, node) => {
|
|
956
|
+
const tableNode = findChildNodeOfType(node, node.type.schema.nodes.table);
|
|
957
|
+
const colGroupNode = findChildNodeOfType(node, node.type.schema.nodes.table_colgroup);
|
|
958
|
+
if (!tableNode) {
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
const table = this.serializeNode(tableNode);
|
|
962
|
+
const tbodyElement = this.document.createElement('tbody');
|
|
963
|
+
while (table.firstChild) {
|
|
964
|
+
const child = table.firstChild;
|
|
965
|
+
table.removeChild(child);
|
|
966
|
+
tbodyElement.appendChild(child);
|
|
967
|
+
}
|
|
968
|
+
table.appendChild(tbodyElement);
|
|
969
|
+
if (colGroupNode) {
|
|
970
|
+
const colGroup = this.serializeNode(colGroupNode);
|
|
971
|
+
table.insertBefore(colGroup, table.firstChild);
|
|
972
|
+
}
|
|
973
|
+
element.appendChild(table);
|
|
974
|
+
};
|
|
928
975
|
const createFigureElement = (node, nodeName, contentNodeType, figType) => {
|
|
929
976
|
const element = createElement(node, nodeName);
|
|
930
977
|
if (figType) {
|
|
@@ -945,7 +992,7 @@ export class JATSExporter {
|
|
|
945
992
|
const element = createElement(node, nodeName);
|
|
946
993
|
appendLabels(element, node);
|
|
947
994
|
appendChildNodeOfType(element, node, node.type.schema.nodes.figcaption);
|
|
948
|
-
|
|
995
|
+
appendTable(element, node);
|
|
949
996
|
appendChildNodeOfType(element, node, node.type.schema.nodes.table_element_footer);
|
|
950
997
|
if (isExecutableNodeType(node.type)) {
|
|
951
998
|
processExecutableNode(node, element);
|
|
@@ -1558,21 +1605,6 @@ export class JATSExporter {
|
|
|
1558
1605
|
this.citationTexts.set(id, output);
|
|
1559
1606
|
});
|
|
1560
1607
|
}
|
|
1561
|
-
createEquation(node, isInline = false) {
|
|
1562
|
-
if (node.attrs.format === 'tex') {
|
|
1563
|
-
const texMath = this.document.createElement('tex-math');
|
|
1564
|
-
texMath.innerHTML = node.attrs.contents;
|
|
1565
|
-
return texMath;
|
|
1566
|
-
}
|
|
1567
|
-
else {
|
|
1568
|
-
const math = this.nodeFromJATS(node.attrs.contents);
|
|
1569
|
-
const mathml = math;
|
|
1570
|
-
if (!isInline) {
|
|
1571
|
-
mathml.setAttribute('id', normalizeID(node.attrs.id));
|
|
1572
|
-
}
|
|
1573
|
-
return mathml;
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
1608
|
buildKeywords(articleMeta) {
|
|
1577
1609
|
const keywords = [...this.modelMap.values()].filter((model) => model.objectType === ObjectTypes.Keyword);
|
|
1578
1610
|
const keywordGroups = new Map();
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { HTMLDocument } from 'mathjax-full/js/handlers/html/HTMLDocument';
|
|
19
|
+
import { TeX } from 'mathjax-full/js/input/tex';
|
|
20
|
+
import { SVG } from 'mathjax-full/js/output/svg';
|
|
21
|
+
import { xmlSerializer } from '../transformer';
|
|
22
|
+
import { packages } from './mathjax-packages';
|
|
23
|
+
class ManuscriptsHTMLAdaptor extends HTMLAdaptor {
|
|
24
|
+
setAttribute(node, name, value, ns) {
|
|
25
|
+
if (name !== 'xmlns') {
|
|
26
|
+
ns ? node.setAttributeNS(ns, name, value) : node.setAttribute(name, value);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const InputJax = new TeX({
|
|
31
|
+
packages,
|
|
32
|
+
});
|
|
33
|
+
const OutputJax = new SVG({
|
|
34
|
+
fontCache: 'none',
|
|
35
|
+
});
|
|
36
|
+
const adaptor = new ManuscriptsHTMLAdaptor(window);
|
|
37
|
+
const doc = new HTMLDocument(document, adaptor, {
|
|
38
|
+
InputJax,
|
|
39
|
+
OutputJax,
|
|
40
|
+
});
|
|
41
|
+
doc.addStyleSheet();
|
|
42
|
+
export const convertTeXToSVG = (tex, display) => {
|
|
43
|
+
const item = doc.convert(tex, {
|
|
44
|
+
display,
|
|
45
|
+
em: 16,
|
|
46
|
+
ex: 8,
|
|
47
|
+
containerWidth: 1000000,
|
|
48
|
+
lineWidth: 1000000,
|
|
49
|
+
scale: 1,
|
|
50
|
+
});
|
|
51
|
+
if (!item || !item.firstChild) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return xmlSerializer.serializeToString(item.firstChild);
|
|
55
|
+
};
|
package/dist/es/schema/index.js
CHANGED
|
@@ -66,11 +66,10 @@ import { sectionLabel } from './nodes/section_label';
|
|
|
66
66
|
import { sectionTitle } from './nodes/section_title';
|
|
67
67
|
import { supplement } from './nodes/supplement';
|
|
68
68
|
import { supplements } from './nodes/supplements';
|
|
69
|
-
import { table,
|
|
69
|
+
import { table, tableCell, tableHeader, tableRow } from './nodes/table';
|
|
70
70
|
import { tableCol, tableColGroup } from './nodes/table_col';
|
|
71
71
|
import { tableElement } from './nodes/table_element';
|
|
72
72
|
import { tableElementFooter } from './nodes/table_element_footer';
|
|
73
|
-
import { tableCell, tableRow } from './nodes/table_row';
|
|
74
73
|
import { text } from './nodes/text';
|
|
75
74
|
import { title } from './nodes/title';
|
|
76
75
|
import { tocElement } from './nodes/toc_element';
|
|
@@ -100,6 +99,7 @@ export * from './nodes/footnotes_section';
|
|
|
100
99
|
export * from './nodes/graphical_abstract_section';
|
|
101
100
|
export * from './nodes/hard_break';
|
|
102
101
|
export * from './nodes/highlight_marker';
|
|
102
|
+
export * from './nodes/inline_equation';
|
|
103
103
|
export * from './nodes/inline_footnote';
|
|
104
104
|
export * from './nodes/keyword';
|
|
105
105
|
export * from './nodes/keywords_element';
|
|
@@ -119,7 +119,6 @@ export * from './nodes/section_title';
|
|
|
119
119
|
export * from './nodes/table';
|
|
120
120
|
export * from './nodes/table_col';
|
|
121
121
|
export * from './nodes/table_element';
|
|
122
|
-
export * from './nodes/table_row';
|
|
123
122
|
export * from './nodes/text';
|
|
124
123
|
export * from './nodes/toc_element';
|
|
125
124
|
export * from './nodes/toc_section';
|
|
@@ -195,7 +194,6 @@ export const schema = new Schema({
|
|
|
195
194
|
section_title: sectionTitle,
|
|
196
195
|
section_title_plain: sectionTitle,
|
|
197
196
|
table,
|
|
198
|
-
table_body: tableBody,
|
|
199
197
|
table_cell: tableCell,
|
|
200
198
|
table_element: tableElement,
|
|
201
199
|
table_row: tableRow,
|
|
@@ -212,5 +210,6 @@ export const schema = new Schema({
|
|
|
212
210
|
contributors,
|
|
213
211
|
supplements,
|
|
214
212
|
supplement,
|
|
213
|
+
table_header: tableHeader,
|
|
215
214
|
},
|
|
216
215
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ©
|
|
2
|
+
* © 2019 Atypon Systems LLC
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -17,8 +17,9 @@ import { ObjectTypes } from '@manuscripts/json-schema';
|
|
|
17
17
|
export const equation = {
|
|
18
18
|
attrs: {
|
|
19
19
|
id: { default: '' },
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
MathMLStringRepresentation: { default: '' },
|
|
21
|
+
SVGStringRepresentation: { default: '' },
|
|
22
|
+
TeXRepresentation: { default: '' },
|
|
22
23
|
dataTracked: { default: null },
|
|
23
24
|
},
|
|
24
25
|
group: 'block',
|
|
@@ -26,25 +27,26 @@ export const equation = {
|
|
|
26
27
|
{
|
|
27
28
|
tag: `div.${ObjectTypes.Equation}`,
|
|
28
29
|
getAttrs: (p) => {
|
|
29
|
-
const
|
|
30
|
+
const dom = p;
|
|
30
31
|
return {
|
|
31
|
-
id:
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
id: dom.getAttribute('id'),
|
|
33
|
+
MathMLStringRepresentation: dom.getAttribute('data-mathml-string-representation'),
|
|
34
|
+
SVGStringRepresentation: dom.innerHTML,
|
|
35
|
+
TeXRepresentation: dom.getAttribute('data-tex-representation'),
|
|
34
36
|
};
|
|
35
37
|
},
|
|
36
38
|
},
|
|
37
39
|
],
|
|
38
40
|
toDOM: (node) => {
|
|
39
41
|
const equationNode = node;
|
|
40
|
-
const { id, contents, format } = equationNode.attrs;
|
|
41
42
|
const dom = document.createElement('div');
|
|
43
|
+
dom.setAttribute('id', equationNode.attrs.id);
|
|
42
44
|
dom.classList.add(ObjectTypes.Equation);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
dom.setAttribute('data-equation-format', format);
|
|
45
|
+
if (equationNode.attrs.MathMLStringRepresentation) {
|
|
46
|
+
dom.setAttribute('data-mathml-string-representation', equationNode.attrs.MathMLStringRepresentation);
|
|
46
47
|
}
|
|
47
|
-
dom.
|
|
48
|
+
dom.setAttribute('data-tex-representation', equationNode.attrs.TeXRepresentation);
|
|
49
|
+
dom.innerHTML = equationNode.attrs.SVGStringRepresentation;
|
|
48
50
|
return dom;
|
|
49
51
|
},
|
|
50
52
|
};
|
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
export const equationElement = {
|
|
17
|
-
content: '(equation | placeholder)',
|
|
17
|
+
content: '(equation | placeholder) figcaption',
|
|
18
18
|
attrs: {
|
|
19
19
|
id: { default: '' },
|
|
20
|
-
|
|
20
|
+
suppressCaption: { default: true },
|
|
21
|
+
suppressTitle: { default: undefined },
|
|
21
22
|
dataTracked: { default: null },
|
|
22
23
|
comments: { default: null },
|
|
23
24
|
},
|
|
@@ -25,7 +26,7 @@ export const equationElement = {
|
|
|
25
26
|
group: 'block element',
|
|
26
27
|
parseDOM: [
|
|
27
28
|
{
|
|
28
|
-
tag: '
|
|
29
|
+
tag: 'figure.equation',
|
|
29
30
|
getAttrs: (p) => {
|
|
30
31
|
const dom = p;
|
|
31
32
|
return {
|
|
@@ -37,7 +38,7 @@ export const equationElement = {
|
|
|
37
38
|
toDOM: (node) => {
|
|
38
39
|
const equationElementNode = node;
|
|
39
40
|
return [
|
|
40
|
-
'
|
|
41
|
+
'figure',
|
|
41
42
|
{
|
|
42
43
|
class: 'equation',
|
|
43
44
|
id: equationElementNode.attrs.id,
|
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import { ObjectTypes } from '@manuscripts/json-schema';
|
|
16
17
|
export const inlineEquation = {
|
|
17
18
|
attrs: {
|
|
18
|
-
dataTracked: { default: null },
|
|
19
|
-
comments: { default: null },
|
|
20
19
|
id: { default: '' },
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
MathMLRepresentation: { default: '' },
|
|
21
|
+
SVGRepresentation: { default: '' },
|
|
22
|
+
TeXRepresentation: { default: '' },
|
|
23
|
+
dataTracked: { default: null },
|
|
23
24
|
},
|
|
24
25
|
atom: true,
|
|
25
26
|
inline: true,
|
|
@@ -27,27 +28,28 @@ export const inlineEquation = {
|
|
|
27
28
|
group: 'inline',
|
|
28
29
|
parseDOM: [
|
|
29
30
|
{
|
|
30
|
-
tag: `span.
|
|
31
|
+
tag: `span.${ObjectTypes.InlineMathFragment}`,
|
|
31
32
|
getAttrs: (p) => {
|
|
32
33
|
const dom = p;
|
|
33
34
|
return {
|
|
34
|
-
format: dom.getAttribute('data-equation-format'),
|
|
35
35
|
id: dom.getAttribute('id'),
|
|
36
|
-
|
|
36
|
+
MathMLRepresentation: dom.getAttribute('data-mathml-representation') || '',
|
|
37
|
+
SVGRepresentation: dom.innerHTML || '',
|
|
38
|
+
TeXRepresentation: dom.getAttribute('data-tex-representation') || '',
|
|
37
39
|
};
|
|
38
40
|
},
|
|
39
41
|
},
|
|
40
42
|
],
|
|
41
43
|
toDOM: (node) => {
|
|
42
44
|
const inlineEquationNode = node;
|
|
43
|
-
const { id, contents, format } = inlineEquationNode.attrs;
|
|
44
45
|
const dom = document.createElement('span');
|
|
45
|
-
dom.
|
|
46
|
-
dom.
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
dom.classList.add(ObjectTypes.InlineMathFragment);
|
|
47
|
+
dom.setAttribute('id', inlineEquationNode.attrs.id);
|
|
48
|
+
dom.setAttribute('data-tex-representation', inlineEquationNode.attrs.TeXRepresentation);
|
|
49
|
+
if (inlineEquationNode.attrs.MathMLRepresentation) {
|
|
50
|
+
dom.setAttribute('data-mathml-representation', inlineEquationNode.attrs.MathMLRepresentation);
|
|
49
51
|
}
|
|
50
|
-
dom.innerHTML =
|
|
52
|
+
dom.innerHTML = inlineEquationNode.attrs.SVGRepresentation;
|
|
51
53
|
return dom;
|
|
52
54
|
},
|
|
53
55
|
};
|