-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
95 lines (90 loc) · 3.09 KB
/
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
const assert = require('assert');
const markdownIt = require('markdown-it');
var markdownItReplacements = require('.');
var test = function(text, options, typographer) {
var md;
if (typographer == null) {
typographer = true;
}
md = markdownIt({
typographer: typographer
}).use(markdownItReplacements, options);
return md.renderInline(text);
};
describe('markdown-it-replacements', function() {
it('blank values', function() {
return assert.equal('', test(''));
});
it('override (c) replacement behavior', function() {
return assert.equal('(c)', test('(c)'));
});
it('ndash', function() {
return assert.equal('1\u20139', test('1--9'));
});
it('mdash', function() {
return assert.equal('yes\u2014or no', test('yes---or no'));
});
it('ellipsis', function() {
return assert.equal('yes\u2026', test('yes...'));
});
it('plus minus', function() {
return assert.equal('1 \u00b1 100', test('1 +- 100'));
});
it('override ndash', function() {
return assert.equal('1--9', test('1--9', {
ndash: false
}));
});
it('override mdash', function() {
return assert.equal('yes---or no', test('yes---or no', {
mdash: false
}));
});
it('override ellipsis', function() {
return assert.equal('yes...', test('yes...', {
ellipsis: false
}));
});
it('override plus minus', function() {
return assert.equal('1 +- 100', test('1 +- 100', {
plusminus: false
}));
});
it('runs even with typographer set to false', function() {
return assert.equal('1\u20139', test('1--9', {}, false));
});
it('custom replacement, no default', function() {
markdownItReplacements.replacements.push({
name: 'allcaps',
re: /[a-z]/g,
sub: function(s) {
return s.toUpperCase();
}
});
return assert.equal('HELLO', test('hello'));
});
it('custom replacement, default true', function() {
markdownItReplacements.replacements[markdownItReplacements.replacements.length - 1]['default'] = true;
return assert.equal('HELLO', test('hello'));
});
it('custom replacement, default false', function() {
markdownItReplacements.replacements[markdownItReplacements.replacements.length - 1]['default'] = false;
return assert.equal('hello', test('hello'));
});
it('custom replacement, html', function() {
markdownItReplacements.replacements.push({
name: 'html',
re: /[a-z]+/g,
html: true,
sub: function(s) {
return `<span>${s.toUpperCase()}</span>`;
}
});
return assert.equal('<span>HELLO</span>', test('hello'));
});
it('custom replacement, html false', function() {
markdownItReplacements.replacements[markdownItReplacements.replacements.length - 1]['html'] = false;
return assert.equal('<span>HELLO</span>', test('hello'));
});
return;
});