forked from jGleitz/markdown-it-prism
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
142 lines (122 loc) · 4.3 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
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
135
136
137
138
139
140
141
142
/* eslint-env mocha */
import chai, {expect} from 'chai';
import chaiString from 'chai-string';
import markdownit from 'markdown-it';
import markdownItPrism from './index';
import fs from 'fs';
chai.use(chaiString);
const read = path => fs.readFileSync(`testdata/${path}`).toString();
describe('markdown-it-prism', () => {
it('highlights fenced code blocks with language specification using Prism', () => {
expect(markdownit()
.use(markdownItPrism)
.render(read('input/fenced-with-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-language.html'));
});
it('throws for unknown plugins', () => {
expect(() => markdownit()
.use(markdownItPrism, {
plugins: ['foo']
})).to.throw(Error, /plugin/);
});
it('throws for unknown defaultLanguage', () => {
expect(() => markdownit()
.use(markdownItPrism, {
defaultLanguage: 'i-dont-exist'
})).to.throw(Error, /defaultLanguage.*i-dont-exist/);
});
it('throws for unknown defaultLanguageForUnknown', () => {
expect(() => markdownit()
.use(markdownItPrism, {
defaultLanguageForUnknown: 'i-dont-exist'
})).to.throw(Error, /defaultLanguageForUnknown.*i-dont-exist/);
});
it('throws for unknown defaultLanguageForUnspecified', () => {
expect(() => markdownit()
.use(markdownItPrism, {
defaultLanguageForUnspecified: 'i-dont-exist'
})).to.throw(Error, /defaultLanguageForUnspecified.*i-dont-exist/);
});
it('offers an init function for further initialisation', () => {
let called = false;
markdownit()
.use(markdownItPrism, {
init: prism => {
expect(prism).to.have.ownProperty('plugins');
called = true;
}
});
expect(called).to.be.true;
});
it('does not add classes to fenced code blocks without language specification', () => {
expect(markdownit()
.use(markdownItPrism)
.render(read('input/fenced-without-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-without-language.html'));
});
it('falls back to defaultLanguageForUnspecified if no language is specified', () => {
expect(markdownit()
.use(markdownItPrism, {
defaultLanguageForUnspecified: 'java'
})
.render(read('input/fenced-without-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-language.html'));
});
it('falls back to defaultLanguage if no language and no defaultLanguageForUnspecified is specified', () => {
expect(markdownit()
.use(markdownItPrism, {
defaultLanguage: 'java'
})
.render(read('input/fenced-without-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-language.html'));
});
it('does not add classes to indented code blocks', () => {
expect(markdownit()
.use(markdownItPrism)
.render(read('input/indented.md'))
).to.equalIgnoreSpaces(read('expected/indented.html'));
});
it('adds classes even if the language is unknown', () => {
expect(markdownit()
.use(markdownItPrism)
.render(read('input/fenced-with-unknown-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-unknown-language.html'));
});
it('falls back to defaultLanguageForUnknown if the specified language is unknown', () => {
expect(markdownit()
.use(markdownItPrism, {
defaultLanguageForUnknown: 'java'
})
.render(read('input/fenced-with-unknown-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-language.html'));
});
it('falls back to defaultLanguage if the specified language is unknown and no defaultLanguageForUnknown is specified', () => {
expect(markdownit()
.use(markdownItPrism, {
defaultLanguage: 'java'
})
.render(read('input/fenced-with-unknown-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-language.html'));
});
it('respects markdown-it’s langPrefix setting', () => {
expect(
markdownit({
langPrefix: 'test-'
})
.use(markdownItPrism)
.render(read('input/fenced-with-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-language-prefix.html'));
});
// This test must be the last one, as the plugins get loaded into Prism and cannot be unloaded!
it('allows to use Prism plugins', () => {
expect(markdownit()
.use(markdownItPrism, {
plugins: [
'highlight-keywords',
'show-language'
]
})
.render(read('input/fenced-with-language.md'))
).to.equalIgnoreSpaces(read('expected/fenced-with-language-plugins.html'));
});
});