-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.js
205 lines (185 loc) · 4.41 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
var assert = require('assert');
var Md = require('markdown-it');
var multiline = require('multiline');
var headerSections = require('./');
var origEqual = assert.equal;
assert.equal = function(actual, expected) {
var r = /\r/g
return origEqual(actual.replace(r, ''), expected.replace(r, ''));
}
describe('markdown-it-header-sections', function(){
var md;
var simpleSrc = multiline.stripIndent(function(){/*
# header
lorem
*/});
beforeEach(function(){
md = Md();
});
it('should add sections to headers', function(){
var expected = multiline.stripIndent(function(){/*
<section>
<h1>header</h1>
<p>lorem</p>
</section>
*/});
md.use(headerSections);
var res = md.render(simpleSrc);
assert.equal(res, expected);
});
it('should add header attributes from other plugins', function(){
var src = multiline.stripIndent(function(){/*
# header {.red}
lorem
*/});
var expected = multiline.stripIndent(function(){/*
<section class="red">
<h1 class="red">header</h1>
<p>lorem</p>
</section>
*/});
md.use(require('markdown-it-attrs'));
md.use(headerSections);
var res = md.render(src);
assert.equal(res, expected);
});
it('should close sections when a new header is of same or lower level', function(){
var src = multiline.stripIndent(function(){/*
# asdf
lorem
# fdsa
ipsum
*/});
var expected = multiline.stripIndent(function(){/*
<section>
<h1>asdf</h1>
<p>lorem</p>
</section>
<section>
<h1>fdsa</h1>
<p>ipsum</p>
</section>
*/});
md.use(headerSections);
var res = md.render(src);
assert.equal(res, expected);
});
it('should nest sections', function(){
var src = multiline.stripIndent(function(){/*
# Header 1
Text.
### Header 2
Lorem?
## Header 3
Ipsum.
# Last header
Markdown rules!
*/});
var expected = multiline.stripIndent(function(){/*
<section>
<h1>Header 1</h1>
<p>Text.</p>
<section>
<h3>Header 2</h3>
<p>Lorem?</p>
</section>
<section>
<h2>Header 3</h2>
<p>Ipsum.</p>
</section>
</section>
<section>
<h1>Last header</h1>
<p>Markdown rules!</p>
</section>
*/});
md.use(headerSections);
var res = md.render(src);
assert.equal(res, expected);
});
it('should parse incorrect order of headers', function(){
var src = multiline.stripIndent(function(){/*
#### Header 4
Text.
### Header 3
Hello!
*/});
var expected = multiline.stripIndent(function(){/*
<section>
<h4>Header 4</h4>
<p>Text.</p>
</section>
<section>
<h3>Header 3</h3>
<p>Hello!</p>
</section>
*/});
md.use(headerSections);
var res = md.render(src);
assert.equal(res, expected);
});
it('should handle sections in list', function(){
var src = multiline.stripIndent(function(){/*
- foo
### Header 2
Lorem?
- bar
## Last header
Markdown rules!
*/});
var expected = multiline.stripIndent(function(){/*
<ul>
<li>foo
<section>
<h3>Header 2</h3>
Lorem?</section>
</li>
<li>bar
<section>
<h2>Last header</h2>
Markdown rules!</section>
</li>
</ul>
*/});
md.use(headerSections);
var res = md.render(src);
assert.equal(res, expected);
});
it('should close sections when a new header is of same level', function(){
var src = multiline.stripIndent(function(){/*
### asdf
lorem
### fdsa
ipsum
*/});
var expected = multiline.stripIndent(function(){/*
<section>
<h3>asdf</h3>
<p>lorem</p>
</section>
<section>
<h3>fdsa</h3>
<p>ipsum</p>
</section>
*/});
md.use(headerSections);
var res = md.render(src);
assert.equal(res, expected);
});
it('should move, not copy, ID from header', function(){
var src = multiline.stripIndent(function(){/*
# asdf {#asdf}
qwerty
*/});
var expected = multiline.stripIndent(function(){/*
<section id="asdf">
<h1>asdf</h1>
<p>qwerty</p>
</section>
*/});
md.use(require('markdown-it-attrs'));
md.use(headerSections);
var res = md.render(src);
assert.equal(res, expected);
});
});