forked from javascript-tutorial/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·212 lines (169 loc) · 6.45 KB
/
server.js
File metadata and controls
executable file
·212 lines (169 loc) · 6.45 KB
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
206
207
208
209
210
'use strict';
const should = require('should');
// introduce models for fixtures
require('tutorial').Article;
require('tutorial').Task;
const Parser = require('../serverParser');
const dataUtil = require('lib/dataUtil');
const path = require('path');
const stripYamlMetadata = require('../stripYamlMetadata');
// compares removing spaces between tags
should.Assertion.add('html', function(str) {
this.obj.should.be.a.String;
str.should.be.a.String;
this.obj.trim().replace(/>\s+</g, '><').should.equal(str.trim().replace(/>\s+</g, '><'));
}, false);
function* render(text) {
let tmp;
try {
tmp = stripYamlMetadata(text);
} catch (e) {
// bad metadata stops parsing immediately
return e.message;
}
text = tmp.text;
let env = {meta: tmp.meta};
const parser = new Parser({
resourceWebRoot: '/resources',
publicRoot: __dirname,
env
});
const tokens = await parser.parse(text);
let result = parser.render(tokens);
//console.log(env);
return result;
}
describe('MarkIt', function() {
before(function* () {
await dataUtil.loadModels(path.join(__dirname, './fixture/tutorial'), {reset: true});
});
describe('code', function() {
it(`[js src="1.js" height=300]`, function*() {
let result = await render(this.test.title);
result.should.be.html(`<div data-trusted="1" class="code-example" data-demo-height="300">
<div class="codebox code-example__codebox">
<div class="codebox__code" data-code="1">
<pre class="line-numbers language-javascript"><code class="language-javascript">let a = 5</code></pre>
</div>
</div>
</div>`);
});
it('```\ncode\n```', function*() {
let result = await render(this.test.title);
result.should.be.html(`<div data-trusted="1" class="code-example">
<div class="codebox code-example__codebox">
<div class="codebox__code" data-code="1">
<pre class="line-numbers language-none"><code class="language-none">code</code></pre>
</div>
</div>
</div>`);
});
it('```js\na = 5\n```\n', function*() {
let result = await render(this.test.title);
result.should.be.html(`<div data-trusted="1" class="code-example">
<div class="codebox code-example__codebox">
<div class="codebox__code" data-code="1">
<pre class="line-numbers language-javascript"><code class="language-javascript">a = 5</code></pre>
</div>
</div>
</div>`
);
});
});
it(`[iframe src="/path"]`, function*() {
let result = await render(this.test.title);
result.should.be.html(`<div class="code-result">
<div class="code-result__toolbar toolbar"></div>
<iframe class="code-result__iframe" data-trusted="1" style="height:300px" src="/path"></iframe>
</div>`
);
});
/*
it(`<info:task/task-1>`, function*() {
let result = await render(this.test.title);
result.trim().should.be.eql('<p><a href="/task/task-1">Task 1</a></p>');
});
it(`<info:article-1.2>`, function*() {
let result = await render(this.test.title);
result.trim().should.be.eql('<p><a href="/article-1.2">Article 1.2</a></p>');
});
*/
it(`notfigure `, function*() {
let result = await render(this.test.title);
result.trim().should.be.eql('<p>notfigure <img src="/url" alt="desc" height="100" width="200"></p>');
});
it(`notfigure `, function*() {
let result = await render(this.test.title);
result.trim().should.be.eql('<p>notfigure <img src="/resources/blank.png" alt="desc" width="3" height="2"></p>');
});
it(`notfigure `, function*() {
let result = await render(this.test.title);
result.trim().should.match(/^<p>notfigure <span class="markdown-error">.*?<\/p>$/);
});
it(`notfigure `, function*() {
let result = await render(this.test.title);
result.trim().should.match(/^<p>notfigure <span class="markdown-error">.*?<\/p>$/);
});
it(`notfigure `, function*() {
let result = await render(this.test.title);
result.trim().should.match(/^<p>notfigure <span class="markdown-error">.*?<\/p>$/);
});
it(``, function*() {
let result = await render(this.test.title);
result.trim().should.be.html(`<figure><div class="image" style="width:200px">
<div class="image__ratio" style="padding-top:50%"></div>
<img src="/url" alt="" height="100" width="200" class="image__image">
</div></figure>`);
});
it(`## Header [#anchor]`, function*() {
let result = await render(this.test.title);
result.trim().should.be.html('<h2><a class="main__anchor" name="anchor" href="#anchor">Header</a></h2>');
});
it(`## My header`, function*() {
let result = await render(this.test.title);
result.trim().should.be.html('<h2><a class="main__anchor" name="my-header" href="#my-header">My header</a></h2>');
});
it(`\`\`\`compare
- Полная интеграция с HTML/CSS.
- Простые вещи делаются просто.
- Поддерживается всеми распространёнными браузерами и включён по умолчанию.
\`\`\``, function*() {
let result = await render(this.test.title);
result.trim().should.be.html(`
<div class="balance balance_single">
<div class="balance__minuses">
<div class="balance__content">
<ul class="balance__list">
<li>Полная интеграция с HTML/CSS.</li>
<li>Простые вещи делаются просто.</li>
<li>Поддерживается всеми распространёнными браузерами и включён по умолчанию.</li>
</ul>
</div>
</div>
</div>`);
});
it(`\`\`\`compare
+ one
- two
\`\`\``, function*() {
let result = await render(this.test.title);
result.trim().should.be.html(`<div class="balance">
<div class="balance__pluses">
<div class="balance__content">
<div class="balance__title">Достоинства</div>
<ul class="balance__list">
<li>one</li>
</ul>
</div>
</div>
<div class="balance__minuses">
<div class="balance__content">
<div class="balance__title">Недостатки</div>
<ul class="balance__list">
<li>two</li>
</ul>
</div>
</div>
</div>`);
});
});