-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.test.js
134 lines (129 loc) · 4.28 KB
/
index.test.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"use strict";
const vows = require('vows');
const assert = require('assert');
const { Remarkable, utils } = require('remarkable');
const plugin = require('./index.js');
const mdWithDollar = new Remarkable();
mdWithDollar.use(plugin);
const mdWithAt = new Remarkable();
mdWithAt.use(plugin, {delimiter: '@'});
vows.describe('KatexPlugin').addBatch({
'Config empty delimiter': {
topic() {
const md = new Remarkable();
md.use(plugin, {delimiter: ''});
return md;
},
'Uses default delimiter': function(topic) {
assert.equal(topic.renderer.rules.katex.delimiter, '$');
}
},
'Multi-char delimiter': {
topic() {
return () => {
const md = new Remarkable();
md.use(plugin, {delimiter: '$$'});
return md;
};
},
'Throws exception': function(topic) {
assert.throws(topic);
}
},
'Render plain text': {
topic: mdWithDollar.render('This is a test.'),
'Nothing done': function(topic) {
assert.equal(topic, '<p>This is a test.</p>\n');
}
},
'Render with single $ in text': {
topic: mdWithDollar.render('The car cost $20,000 new.'),
'Nothing done': function(topic) {
assert.equal(topic, '<p>The car cost $20,000 new.</p>\n');
}
},
'Render $...$ in text': {
topic: mdWithDollar.render('Equation $x + y$.'),
'Starts with "<p>Equation "': function(topic) {
assert.isTrue(topic.startsWith('<p>Equation '));
},
'Ends with ".</p>"': function(topic) {
assert.isTrue(topic.endsWith('</span>.</p>\n'));
},
'Contains math span': function(topic) {
assert.notEqual(topic.indexOf('<span class="katex">'), -1);
}
},
'Render $...$ in text with embedded {$...$}': {
topic: mdWithDollar.render('Equation $\\colorbox{aqua}{$F=ma$}$.'),
'Starts with "<p>Equation "': function(topic) {
assert.isTrue(topic.startsWith('<p>Equation '));
},
'Ends with ".</p>"': function(topic) {
assert.isTrue(topic.endsWith('</span>.</p>\n'));
},
'Contains math span': function(topic) {
assert.notEqual(topic.indexOf('<span class="katex">'), -1);
}
},
'Render $...$ in text with embedded {': {
topic: mdWithDollar.render('Equation $\\left\\{ hi \\right.$.'),
'Starts with "<p>Equation "': function(topic) {
assert.isTrue(topic.startsWith('<p>Equation '));
},
'Ends with ".</p>"': function(topic) {
assert.isTrue(topic.endsWith('</span>.</p>\n'));
},
'Contains math span': function(topic) {
assert.notEqual(topic.indexOf('<span class="katex">'), -1);
}
},
'Render $...$ in text with embedded }': {
topic: mdWithDollar.render('Equation $\\left\\{ hi \\right\\}$.'),
'Starts with "<p>Equation "': function(topic) {
assert.isTrue(topic.startsWith('<p>Equation '));
},
'Ends with ".</p>"': function(topic) {
assert.isTrue(topic.endsWith('</span>.</p>\n'));
},
'Contains math span': function(topic) {
assert.notEqual(topic.indexOf('<span class="katex">'), -1);
}
},
'Render @...@ in text': {
topic: mdWithAt.render('Equation @x + y@.'),
'Starts with "<p>Equation "': function(topic) {
assert.isTrue(topic.startsWith('<p>Equation '));
},
'Ends with ".</p>"': function(topic) {
assert.isTrue(topic.endsWith('</span>.</p>\n'));
},
'Contains math span': function(topic) {
assert.notEqual(topic.indexOf('<span class="katex">'), -1);
}
},
'Render $$...$$ in text': {
topic: mdWithDollar.render('Before\n$$\nx + y\n$$\nafter.'),
'Starts with "<p>Before "': function(topic) {
assert.isTrue(topic.startsWith('<p>Before\n'));
},
'Ends with "after.</p>"': function(topic) {
assert.isTrue(topic.endsWith('</span>\nafter.</p>\n'));
},
'Contains math span': function(topic) {
assert.notEqual(topic.indexOf('<span class="katex-display">'), -1);
}
},
'Render @@...@@ in text': {
topic: mdWithAt.render('Before @@x + y@@ after.'),
'Starts with "<p>Before "': function(topic) {
assert.isTrue(topic.startsWith('<p>Before '));
},
'Ends with "after.</p>"': function(topic) {
assert.isTrue(topic.endsWith('</span> after.</p>\n'));
},
'Contains math span': function(topic) {
assert.notEqual(topic.indexOf('<span class="katex-display">'), -1);
}
}
}).export(module);