forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex.spec.ts
115 lines (92 loc) · 3.26 KB
/
latex.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import expect = require('expect.js');
import {
removeMath, replaceMath, typeset
} from '@jupyterlab/rendermime';
describe('jupyter-ui', () => {
describe('removeMath()', () => {
it('should split the text into text and math', () => {
let input = 'hello, $ /alpha $, there';
let { text, math } = removeMath(input);
expect(text).to.be('hello, @@0@@, there');
expect(math).to.eql(['$ /alpha $'])
});
it('should handle code spans', () => {
let input = '`$foo` and `$bar` are variables';
let { text, math } = removeMath(input);
expect(text).to.be(input);
expect(math).to.eql([]);
});
it('should handle math markers', () => {
let input = ' @@0@@ hello, $ /alpha $, there';
let { text, math } = removeMath(input);
expect(text).to.be(' @@0@@ hello, @@1@@, there');
expect(math).to.eql([ '@@0@@', '$ /alpha $' ])
});
it('should handle unbalanced braces', () => {
let input = 'hello, $ /alpha { $, there';
let { text, math } = removeMath(input);
expect(text).to.be('hello, @@0@@, there');
expect(math).to.eql(['$ /alpha { $' ])
});
it('should handle balanced braces', () => {
let input = 'hello, $ /alpha { } $, there';
let { text, math } = removeMath(input);
expect(text).to.be('hello, @@0@@, there');
expect(math).to.eql(['$ /alpha { } $' ])
});
it('should handle math blocks', () => {
let input = 'hello, $$\nfoo\n$$, there';
let { text, math } = removeMath(input);
expect(text).to.be('hello, @@0@@, there');
expect(math).to.eql(['$$\nfoo\n$$' ])
});
it('should handle begin statements', () => {
let input = 'hello, \\begin{align} \\end{align}, there';
let { text, math } = removeMath(input);
expect(text).to.be('hello, @@0@@, there');
expect(math).to.eql(['\\begin{align} \\end{align}'])
});
it('should handle `\\(` delimiters in GFM', () => {
let input = `
\`\`\`
Some \\(text
\'\'\'
**bold**
## header
`;
let { text, math } = removeMath(input);
expect(text).to.be(input);
expect(math).to.eql([]);
});
it('should handle `\\\\\(` delimiters for math', () => {
let input = `hello, \\\\\(
/alpha
\\\\\), there`;
let { text, math } = removeMath(input);
expect(text).to.be('hello, @@0@@, there');
expect(math).to.eql(['\\\\(\n /alpha\n \\\\)']);
});
it('should handle `\\\\\[` delimiters for math', () => {
let input = `hello, \\\\\[
/alpha
\\\\\], there`;
let { text, math } = removeMath(input);
expect(text).to.be('hello, @@0@@, there');
expect(math).to.eql(['\\\\[\n /alpha\n \\\\]']);
});
});
describe('replaceMath()', () => {
it('should recombine text split with removeMath', () => {
let input = 'hello, $ /alpha $, there';
let { text, math } = removeMath(input);
expect(replaceMath(text, math)).to.be(input);
});
});
describe('typeset()', () => {
it('should be a no-op if MathJax is not defined', () => {
typeset(document.body);
});
});
});