@pie-lib/math-rendering 3.2.2-next.4 → 3.3.0-beta.2
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/CHANGELOG.md +32 -36
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +5 -3
- package/src/__tests__/mml-to-latex.test.js +14 -0
- package/src/__tests__/normalization.test.js +51 -0
- package/src/__tests__/render-math.test.js +155 -0
- package/src/mml-to-latex.js +2 -2
- package/src/mstack/__tests__/__snapshots__/chtml.test.js.snap +9 -0
- package/src/mstack/__tests__/chtml.test.js +104 -0
- package/src/render-math.js +127 -71
- package/lib/index.js +0 -38
- package/lib/index.js.map +0 -1
- package/lib/mml-to-latex.js +0 -17
- package/lib/mml-to-latex.js.map +0 -1
- package/lib/mstack/chtml.js +0 -296
- package/lib/mstack/chtml.js.map +0 -1
- package/lib/mstack/index.js +0 -23
- package/lib/mstack/index.js.map +0 -1
- package/lib/mstack/mml.js +0 -109
- package/lib/mstack/mml.js.map +0 -1
- package/lib/normalization.js +0 -95
- package/lib/normalization.js.map +0 -1
- package/lib/render-math.js +0 -358
- package/lib/render-math.js.map +0 -1
- package/playground/demo.html +0 -958
- package/playground/demo.js +0 -108
- package/playground/main.html +0 -158
- package/playground/main.js +0 -16
- package/playground/webpack.config.js +0 -29
package/CHANGELOG.md
CHANGED
|
@@ -3,104 +3,100 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
# [3.3.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.2.1...@pie-lib/math-rendering@3.3.0-beta.2) (2025-07-20)
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
10
9
|
|
|
11
|
-
* revert mathml-to-latex version as it seems to break math rendering ([46e841c](https://github.com/pie-framework/pie-lib/commit/46e841c00c2a04ff0e3442625870b3b457571a8e))
|
|
12
10
|
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
|
|
14
|
+
# [3.3.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.2.1...@pie-lib/math-rendering@3.3.0-beta.1) (2025-07-20)
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
18
17
|
|
|
19
18
|
|
|
20
|
-
### Features
|
|
21
19
|
|
|
22
|
-
* update version ([f716545](https://github.com/pie-framework/pie-lib/commit/f716545d526dc856e2160619650787273a993f27))
|
|
23
20
|
|
|
24
21
|
|
|
22
|
+
# [3.3.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.2.1...@pie-lib/math-rendering@3.3.0-beta.1) (2025-07-20)
|
|
25
23
|
|
|
24
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
26
25
|
|
|
27
26
|
|
|
28
|
-
## [3.1.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.1.1...@pie-lib/math-rendering@3.1.2) (2023-09-27)
|
|
29
27
|
|
|
30
28
|
|
|
31
|
-
### Bug Fixes
|
|
32
29
|
|
|
33
|
-
|
|
30
|
+
# [3.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.2.1...@pie-lib/math-rendering@3.3.0-beta.0) (2025-07-20)
|
|
34
31
|
|
|
32
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
35
33
|
|
|
36
34
|
|
|
37
35
|
|
|
38
36
|
|
|
39
|
-
## [3.1.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.1.0...@pie-lib/math-rendering@3.1.1) (2023-09-25)
|
|
40
37
|
|
|
38
|
+
# [3.4.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.2.1...@pie-lib/math-rendering@3.4.0-beta.0) (2025-07-15)
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
43
41
|
|
|
44
|
-
|
|
42
|
+
# [3.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.2.1...@pie-lib/math-rendering@3.3.0-beta.0) (2025-07-15)
|
|
45
43
|
|
|
44
|
+
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
46
45
|
|
|
46
|
+
## [3.2.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.2.0...@pie-lib/math-rendering@3.2.1) (2023-10-01)
|
|
47
47
|
|
|
48
|
+
### Bug Fixes
|
|
48
49
|
|
|
50
|
+
- revert mathml-to-latex version as it seems to break math rendering ([46e841c](https://github.com/pie-framework/pie-lib/commit/46e841c00c2a04ff0e3442625870b3b457571a8e))
|
|
49
51
|
|
|
50
|
-
# [3.
|
|
51
|
-
|
|
52
|
+
# [3.2.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.1.2...@pie-lib/math-rendering@3.2.0) (2023-09-27)
|
|
52
53
|
|
|
53
54
|
### Features
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
- update version ([f716545](https://github.com/pie-framework/pie-lib/commit/f716545d526dc856e2160619650787273a993f27))
|
|
58
57
|
|
|
58
|
+
## [3.1.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.1.1...@pie-lib/math-rendering@3.1.2) (2023-09-27)
|
|
59
59
|
|
|
60
|
+
### Bug Fixes
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
- force publish ([489a242](https://github.com/pie-framework/pie-lib/commit/489a2421c109fb202b778680f1b57b942e49c86a))
|
|
62
63
|
|
|
64
|
+
## [3.1.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.1.0...@pie-lib/math-rendering@3.1.1) (2023-09-25)
|
|
63
65
|
|
|
64
66
|
### Bug Fixes
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
- update mathml-to-latex version PD-3182, PD-3184 ([c019296](https://github.com/pie-framework/pie-lib/commit/c0192965a3a045e13993a3301dfc35e7e314a592))
|
|
67
69
|
|
|
70
|
+
# [3.1.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@3.0.0...@pie-lib/math-rendering@3.1.0) (2023-09-20)
|
|
68
71
|
|
|
69
|
-
###
|
|
72
|
+
### Features
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
- use forked mathml-to-latex library, as it contains fixes PD-3011 ([8949ac2](https://github.com/pie-framework/pie-lib/commit/8949ac2ddf6664bf437a35dbe21555f18ac77426))
|
|
72
75
|
|
|
76
|
+
# [3.0.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.5.18...@pie-lib/math-rendering@3.0.0) (2023-09-20)
|
|
77
|
+
|
|
78
|
+
### Bug Fixes
|
|
73
79
|
|
|
80
|
+
- update mathml-to-latex version ([1d101d2](https://github.com/pie-framework/pie-lib/commit/1d101d22298bd480a5aec638e4c9708d5aa52ce4))
|
|
74
81
|
|
|
82
|
+
### BREAKING CHANGES
|
|
75
83
|
|
|
84
|
+
- updated mathml-to-latex version.
|
|
76
85
|
|
|
77
86
|
## [2.5.18](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.5.17...@pie-lib/math-rendering@2.5.18) (2023-09-14)
|
|
78
87
|
|
|
79
|
-
|
|
80
88
|
### Bug Fixes
|
|
81
89
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
- force v1.2.0 of mathml-to-latex, as v1.3.0 contains a braking change ([4792ed9](https://github.com/pie-framework/pie-lib/commit/4792ed965608ee5ff4c872e69dee9b3b59261cf0))
|
|
87
91
|
|
|
88
92
|
## [2.5.17](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.5.16...@pie-lib/math-rendering@2.5.17) (2023-06-24)
|
|
89
93
|
|
|
90
94
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
91
95
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
96
|
## [2.5.16](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.5.15...@pie-lib/math-rendering@2.5.16) (2023-06-13)
|
|
97
97
|
|
|
98
98
|
**Note:** Version bump only for package @pie-lib/math-rendering
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
100
|
## [2.5.15](https://github.com/pie-framework/pie-lib/compare/@pie-lib/math-rendering@2.5.14...@pie-lib/math-rendering@2.5.15) (2023-06-12)
|
|
105
101
|
|
|
106
102
|
### Bug Fixes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-rendering",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0-beta.2",
|
|
4
4
|
"description": "math rendering utilities",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
"author": "pie-framework developers",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"@pie-framework/mathml-to-latex": "1.4.4",
|
|
13
14
|
"debug": "^4.1.1",
|
|
14
15
|
"lodash": "^4.17.11",
|
|
15
16
|
"mathjax-full": "3.2.2",
|
|
16
|
-
"
|
|
17
|
+
"react": "^16.8.1",
|
|
18
|
+
"slate": "^0.36.2"
|
|
17
19
|
},
|
|
18
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453",
|
|
19
21
|
"scripts": {}
|
|
20
22
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import mmlToLatex from '../mml-to-latex';
|
|
3
|
+
|
|
4
|
+
describe('mmlToLatex', () => {
|
|
5
|
+
it('should work', () => {
|
|
6
|
+
const mml =
|
|
7
|
+
'<math xmlns="http://www.w3.org/1998/Math/MathML"> <mn>2</mn> <mi>x</mi> <mtext> </mtext> <mo>≤</mo> <mn>4</mn> <mi>y</mi> <mtext> </mtext> <mo>+</mo> <mtext> </mtext> <mn>8</mn> <msqrt> <mi>h</mi> </msqrt></math>';
|
|
8
|
+
// todo revisit this
|
|
9
|
+
// const latex = '2x\\text{ }\\leq4y\\text{ }+\\text{ }8\\sqrt{h}';
|
|
10
|
+
const latex = '2 x \\textrm{ } \\leq 4 y \\textrm{ } + \\textrm{ } 8 \\sqrt{h}';
|
|
11
|
+
|
|
12
|
+
expect(mmlToLatex(mml)).toEqual(latex);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
import { Data } from 'slate';
|
|
4
|
+
import { BracketTypes, wrapMath, unWrapMath } from '../normalization';
|
|
5
|
+
|
|
6
|
+
const log = debug('@pie-lib:math-rendering:test:normalization');
|
|
7
|
+
|
|
8
|
+
describe('normalization', () => {
|
|
9
|
+
describe('unWrapMath', () => {
|
|
10
|
+
const assertUnWrap = (html, expected, wrapType) => {
|
|
11
|
+
it(`innerHTML: ${html} is unWrapped to: ${expected} with wrapType: ${wrapType}`, () => {
|
|
12
|
+
const out = unWrapMath(html);
|
|
13
|
+
|
|
14
|
+
expect(out).toEqual({
|
|
15
|
+
unwrapped: expected,
|
|
16
|
+
wrapType: wrapType,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
assertUnWrap('$$<$$', '<', BracketTypes.DOLLAR);
|
|
22
|
+
assertUnWrap('$<$', '<', BracketTypes.DOLLAR);
|
|
23
|
+
assertUnWrap('\\(<\\)', '<', BracketTypes.ROUND_BRACKETS);
|
|
24
|
+
assertUnWrap('\\[<\\]', '<', BracketTypes.ROUND_BRACKETS);
|
|
25
|
+
assertUnWrap('latex', 'latex', BracketTypes.ROUND_BRACKETS);
|
|
26
|
+
assertUnWrap('\\displaystyle foo', 'foo', BracketTypes.ROUND_BRACKETS);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('wrapMath', () => {
|
|
30
|
+
const assertWrap = (latex, expectedHtml, wrapper) => {
|
|
31
|
+
wrapper = wrapper || BracketTypes.ROUND_BRACKETS;
|
|
32
|
+
it(`${latex} is wrapped to: ${expectedHtml}`, () => {
|
|
33
|
+
const out = wrapMath(latex, wrapper);
|
|
34
|
+
|
|
35
|
+
log('out: ', out);
|
|
36
|
+
|
|
37
|
+
expect(out).toEqual(expectedHtml);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
assertWrap('latex', '\\(latex\\)', BracketTypes.ROUND_BRACKETS);
|
|
42
|
+
assertWrap('latex', '\\(latex\\)', BracketTypes.SQUARE_BRACKETS);
|
|
43
|
+
assertWrap('latex', '$latex$', BracketTypes.DOLLAR);
|
|
44
|
+
assertWrap('latex', '$latex$', BracketTypes.DOUBLE_DOLLAR);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Note that when this is converted to html it get's escaped - but that's an issue with the slate html-serializer.
|
|
48
|
+
*/
|
|
49
|
+
assertWrap('<', '\\(<\\)');
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from 'enzyme';
|
|
3
|
+
import renderMath, { fixMathElement } from '../render-math';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
|
|
6
|
+
jest.mock(
|
|
7
|
+
'mathjax-full/js/mathjax',
|
|
8
|
+
() => ({
|
|
9
|
+
mathjax: {
|
|
10
|
+
document: jest.fn().mockReturnThis(),
|
|
11
|
+
findMath: jest.fn().mockReturnThis(),
|
|
12
|
+
compile: jest.fn().mockReturnThis(),
|
|
13
|
+
getMetrics: jest.fn().mockReturnThis(),
|
|
14
|
+
typeset: jest.fn().mockReturnThis(),
|
|
15
|
+
updateDocument: jest.fn().mockReturnThis(),
|
|
16
|
+
clear: jest.fn().mockReturnThis(),
|
|
17
|
+
handlers: {
|
|
18
|
+
handlesDocument: jest.fn().mockReturnThis(),
|
|
19
|
+
},
|
|
20
|
+
handleRetriesFor: jest.fn().mockImplementation((callback) => callback()),
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
{
|
|
24
|
+
virtual: false,
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
jest.mock('mathjax-full/js/input/mathml', () => {
|
|
29
|
+
const mock = jest.fn().mockReturnThis();
|
|
30
|
+
mock.setMmlFactory = jest.fn();
|
|
31
|
+
return {
|
|
32
|
+
MathML: () => mock,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
jest.mock('mathjax-full/js/input/tex', () => ({
|
|
37
|
+
TeX: jest.fn(),
|
|
38
|
+
}));
|
|
39
|
+
jest.mock('mathjax-full/js/core/MmlTree/MmlFactory', () => {
|
|
40
|
+
const instance = {
|
|
41
|
+
setMmlFactory: jest.fn(),
|
|
42
|
+
defaultNodes: {},
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
MmlFactory: () => instance,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const mockMathInstance = {
|
|
50
|
+
document: jest.fn().mockReturnThis(),
|
|
51
|
+
findMath: jest.fn().mockReturnThis(),
|
|
52
|
+
compile: jest.fn().mockReturnThis(),
|
|
53
|
+
enrich: jest.fn().mockReturnThis(),
|
|
54
|
+
addMenu: jest.fn().mockReturnThis(),
|
|
55
|
+
attachSpeech: jest.fn().mockReturnThis(),
|
|
56
|
+
assistiveMml: jest.fn().mockReturnThis(),
|
|
57
|
+
getMetrics: jest.fn().mockReturnThis(),
|
|
58
|
+
typeset: jest.fn().mockReturnThis(),
|
|
59
|
+
updateDocument: jest.fn().mockReturnValue({
|
|
60
|
+
math: {
|
|
61
|
+
list: undefined,
|
|
62
|
+
},
|
|
63
|
+
clear: jest.fn().mockReturnThis(),
|
|
64
|
+
}),
|
|
65
|
+
clear: jest.fn().mockReturnThis(),
|
|
66
|
+
handlers: {
|
|
67
|
+
handlesDocument: jest.fn().mockReturnThis(),
|
|
68
|
+
},
|
|
69
|
+
handleRetriesFor: jest.fn().mockImplementation((callback) => callback()),
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const mockHtml = {
|
|
73
|
+
findMath: jest.fn().mockReturnValue(mockMathInstance),
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const mockEnrichHandlerInstance = {
|
|
77
|
+
create: jest.fn().mockImplementation(() => mockHtml),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
jest.mock('mathjax-full/js/a11y/semantic-enrich', () => {
|
|
81
|
+
return {
|
|
82
|
+
EnrichHandler: () => mockEnrichHandlerInstance,
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
jest.mock('mathjax-full/js/a11y/assistive-mml', () => {
|
|
87
|
+
return {
|
|
88
|
+
AssistiveMmlHandler: () => {},
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
jest.mock('mathjax-full/js/ui/menu/MenuHandler', () => {
|
|
93
|
+
return {
|
|
94
|
+
MenuHandler: () => {},
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
jest.mock('mathjax-full/js/output/chtml', () => ({
|
|
99
|
+
CHTML: jest.fn(),
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
jest.mock('mathjax-full/js/adaptors/browserAdaptor', () => ({
|
|
103
|
+
browserAdaptor: jest.fn(),
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
jest.mock('mathjax-full/js/handlers/html', () => ({
|
|
107
|
+
RegisterHTMLHandler: jest.fn(),
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
jest.mock('mathjax-full/js/core/MmlTree/SerializedMmlVisitor', () => ({
|
|
111
|
+
SerializedMmlVisitor: jest.fn(),
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
describe('render-math', () => {
|
|
115
|
+
it('calls classFactory.create once', () => {
|
|
116
|
+
const div = document.createElement('div');
|
|
117
|
+
|
|
118
|
+
_.times(10).forEach((i) => renderMath(div));
|
|
119
|
+
|
|
120
|
+
expect(mockEnrichHandlerInstance.create).toHaveBeenCalledTimes(1);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('calls MathJax render', () => {
|
|
124
|
+
const div = document.createElement('div');
|
|
125
|
+
|
|
126
|
+
renderMath(div);
|
|
127
|
+
expect(mockEnrichHandlerInstance.create).toHaveBeenCalledTimes(1);
|
|
128
|
+
expect(mockHtml.findMath).toHaveBeenCalledWith({ elements: [div] });
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('call render math for an array of elements', () => {
|
|
132
|
+
const divOne = document.createElement('div');
|
|
133
|
+
const divTwo = document.createElement('div');
|
|
134
|
+
|
|
135
|
+
renderMath([divOne, divTwo]);
|
|
136
|
+
|
|
137
|
+
expect(mockEnrichHandlerInstance.create).toHaveBeenCalledTimes(1);
|
|
138
|
+
expect(mockHtml.findMath).toHaveBeenCalledWith({
|
|
139
|
+
elements: [divOne, divTwo],
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('wraps the math containing element the right way', () => {
|
|
144
|
+
const wrapper = mount(
|
|
145
|
+
<div>
|
|
146
|
+
<span data-latex="">{'420\\text{ cm}=4.2\\text{ meters}'}</span>
|
|
147
|
+
</div>,
|
|
148
|
+
);
|
|
149
|
+
const spanElem = wrapper.instance();
|
|
150
|
+
|
|
151
|
+
fixMathElement(spanElem);
|
|
152
|
+
|
|
153
|
+
expect(spanElem.textContent).toEqual('\\(420\\text{ cm}=4.2\\text{ meters}\\)');
|
|
154
|
+
});
|
|
155
|
+
});
|
package/src/mml-to-latex.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default (mathml) =>
|
|
1
|
+
import { MathMLToLaTeX } from '@pie-framework/mathml-to-latex';
|
|
2
|
+
export default (mathml) => MathMLToLaTeX.convert(mathml);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`chtml implicit one row 1`] = `"<table><tr><td></td><td>1</td></tr></table>"`;
|
|
4
|
+
|
|
5
|
+
exports[`chtml one row 1`] = `"<table><tr><td></td><td>1</td></tr></table>"`;
|
|
6
|
+
|
|
7
|
+
exports[`chtml two rows 1`] = `"<table><tr><td></td><td>1</td></tr><tr><td></td><td>2</td></tr></table>"`;
|
|
8
|
+
|
|
9
|
+
exports[`chtml two rows with operator 1`] = `"<table><tr><td></td><td>1</td></tr><tr><td class=\\"inner\\">mo:+</td><td>2</td></tr></table>"`;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getStackData, Line, Row, CHTMLmstack } from '../chtml';
|
|
2
|
+
// import { CHTMLWrapper, instance } from 'mathjax-full/js/output/chtml/Wrapper';
|
|
3
|
+
import { JSDOM } from 'jsdom';
|
|
4
|
+
|
|
5
|
+
jest.mock('mathjax-full/js/output/chtml/Wrapper', () => {
|
|
6
|
+
const instance = {
|
|
7
|
+
adaptor: {
|
|
8
|
+
document: {
|
|
9
|
+
createElement: jest.fn(),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
standardCHTMLnode: jest.fn(),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
instance,
|
|
17
|
+
CHTMLWrapper: class {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.adaptor = { document: { createElement: jest.fn() } };
|
|
20
|
+
this.document = {};
|
|
21
|
+
// return instance;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const node = (kind, extras) => ({ kind, childNodes: [], ...extras });
|
|
28
|
+
|
|
29
|
+
const textNode = (text) => node('text', { text, node: { kind: 'text', text } });
|
|
30
|
+
const mn = (text) => node('mn', { childNodes: [textNode(text)] });
|
|
31
|
+
const mo = (text) =>
|
|
32
|
+
node('mo', {
|
|
33
|
+
childNodes: [textNode(text)],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const mco = (text) => ({
|
|
37
|
+
...mo(text),
|
|
38
|
+
|
|
39
|
+
toCHTML: (n) => {
|
|
40
|
+
const t = `mo:${text}`;
|
|
41
|
+
n.textContent = t;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const msrow = (...childNodes) => node('msrow', { childNodes });
|
|
46
|
+
const mstack = (...rows) => node('mstack', { childNodes: rows });
|
|
47
|
+
const msline = () => node('msline');
|
|
48
|
+
describe('getStackData', () => {
|
|
49
|
+
it.each`
|
|
50
|
+
input | expected
|
|
51
|
+
${mstack(msrow(mo('+'), mn('111')))} | ${[new Row(['1', '1', '1'], mo('+'))]}
|
|
52
|
+
${mstack(msrow(mn('111')))} | ${[new Row(['1', '1', '1'])]}
|
|
53
|
+
${mstack(msrow(mn('1'), mn('1')))} | ${[new Row(['1', '1'])]}
|
|
54
|
+
${mstack(msrow(mn('1')), mn('1'))} | ${[new Row(['1']), new Row(['1'])]}
|
|
55
|
+
${mstack(msline())} | ${[new Line()]}
|
|
56
|
+
${mstack(mn('1'), msline(), msrow(mo('+'), mn('1')))} | ${[new Row(['1']), new Line(), new Row(['1'], mo('+'))]}
|
|
57
|
+
${mstack(mn('1'), mn('1'))} | ${[new Row(['1']), new Row(['1'])]}
|
|
58
|
+
`('$input => $expected', ({ input, expected }) => {
|
|
59
|
+
const d = getStackData(input);
|
|
60
|
+
// console.log('d:', d);
|
|
61
|
+
// console.log('e:', expected);
|
|
62
|
+
expect({ ...d }).toEqual({ ...expected });
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('Row', () => {
|
|
67
|
+
describe('pad', () => {
|
|
68
|
+
it.each`
|
|
69
|
+
cols | count | expected
|
|
70
|
+
${[]} | ${0} | ${[]}
|
|
71
|
+
${[1]} | ${1} | ${[1]}
|
|
72
|
+
${[1]} | ${2} | ${['__pad__', 1]}
|
|
73
|
+
${[1]} | ${3} | ${['__pad__', '__pad__', 1]}
|
|
74
|
+
`('pads to the right', ({ cols, count, expected }) => {
|
|
75
|
+
const r = new Row(cols);
|
|
76
|
+
const p = r.pad(count, 'right');
|
|
77
|
+
expect(p).toEqual(expected);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe.each`
|
|
83
|
+
label | tree
|
|
84
|
+
${'one row'} | ${[msrow(mn('1'))]}
|
|
85
|
+
${'implicit one row'} | ${[mn('1')]}
|
|
86
|
+
${'two rows'} | ${[msrow(mn('1')), msrow(mn('2'))]}
|
|
87
|
+
${'two rows with operator'} | ${[msrow(mn('1')), msrow(mco('+'), mn('2'))]}
|
|
88
|
+
`('chtml', ({ label, tree }) => {
|
|
89
|
+
let html;
|
|
90
|
+
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
const chtml = new CHTMLmstack({}, {});
|
|
93
|
+
const dom = new JSDOM(`<!DOCTYPE html><body></body>`);
|
|
94
|
+
chtml.standardCHTMLnode = (parent) => parent;
|
|
95
|
+
chtml.ce = dom.window.document.createElement.bind(dom.window.document);
|
|
96
|
+
chtml.childNodes = tree;
|
|
97
|
+
chtml.toCHTML(dom.window.document.body);
|
|
98
|
+
html = dom.window.document.body.innerHTML;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it(label, () => {
|
|
102
|
+
expect(html).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
});
|