/
index.js
183 lines (149 loc) · 5.35 KB
/
index.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
'use strict';
var should = require('chai').should(); // eslint-disable-line
var util = require('hexo-util');
describe('Marked renderer', function() {
var ctx = {
config: {
marked: {}
}
};
var r = require('../lib/renderer').bind(ctx);
it('default', function() {
var code = 'console.log("Hello world");';
var body = [
'# Hello world',
'',
'```',
code,
'```',
'',
'## Hello world',
'',
'hello'
].join('\n');
var result = r({text: body});
result.should.eql([
'<h1 id="Hello-world"><a href="#Hello-world" class="headerlink" title="Hello world"></a>Hello world</h1>',
'<pre><code>' + util.highlight(code, {gutter: false, wrap: false}) + '</code></pre>',
'<h2 id="Hello-world-1"><a href="#Hello-world-1" class="headerlink" title="Hello world"></a>Hello world</h2>',
'<p>hello</p>'
].join('') + '\n');
});
it('should render headings with links', function() {
var body = [
'## [hexo-server]',
'',
'[hexo-server]: https://github.com/hexojs/hexo-server'
].join('\n');
var result = r({text: body});
result.should.eql([
'<h2 id="hexo-server"><a href="#hexo-server" class="headerlink" title="hexo-server"></a>',
'<a href="https://github.com/hexojs/hexo-server">hexo-server</a></h2>'
].join(''));
});
it('should handle chinese headers properly', function() {
var body = '# 中文';
var result = r({text: body});
result.should.eql('<h1 id="中文"><a href="#中文" class="headerlink" title="中文"></a>中文</h1>');
});
// Description List tests
it('should render description lists with a single space after the colon', function() {
var result = r({text: 'Description Term<br>: This is the Description'});
result.should.eql('<dl><dt>Description Term</dt><dd>This is the Description</dd></dl>');
});
it('should render description lists with multiple spaces after the colon', function() {
var result = r({text: 'Description Term<br>: This is the Description'});
result.should.eql('<dl><dt>Description Term</dt><dd>This is the Description</dd></dl>');
});
it('should render description lists with a tab after the colon', function() {
var result = r({text: 'Description Term<br>: This is the Description'});
result.should.eql('<dl><dt>Description Term</dt><dd>This is the Description</dd></dl>');
});
it('should render description lists with a carriage return after the colon', function() {
var result = r({text: 'Description Term<br>:\nThis is the Description'});
result.should.eql('<dl><dt>Description Term</dt><dd>This is the Description</dd></dl>');
});
it('should not render regular paragraphs as description lists', function() {
var result = r({text: 'Description Term<br>:This is the Description'});
result.should.eql('<p>Description Term<br>:This is the Description</p>\n');
});
describe('autolink option tests', function() {
var ctx = {
config: {
marked: {
autolink: true
}
}
};
var renderer = require('../lib/renderer');
var body = [
'Great website http://hexo.io',
'',
'[Hexo](http://hexo.io)'
].join('\n');
it('autolink enabled', function() {
var r = renderer.bind(ctx);
var result = r({text: body});
result.should.eql([
'<p>Great website <a href="http://hexo.io">http://hexo.io</a></p>\n',
'<p><a href="http://hexo.io">Hexo</a></p>\n'
].join(''));
});
it('autolink disabled', function() {
ctx.config.marked.autolink = false;
var r = renderer.bind(ctx);
var result = r({text: body});
result.should.eql([
'<p>Great website http://hexo.io</p>\n',
'<p><a href="http://hexo.io">Hexo</a></p>\n'
].join(''));
});
});
describe('modifyAnchors option tests', function() {
var body = [
'- [Example](#example)',
'',
'# Example'
].join('\n');
var renderer = require('../lib/renderer');
var ctx = {
config: {
marked: {
modifyAnchors: ''
}
}
};
it('should not modify anchors with default options', function() {
var r = renderer.bind(ctx);
var result = r({text: body});
result.should.eql([
'<ul>',
'<li><a href=\"#example\">Example</a></li>',
'</ul>',
'<h1 id=\"Example\"><a href=\"#Example\" class=\"headerlink\" title=\"Example\"></a>Example</h1>'
].join('\n'));
});
it('should set anchors to upperCase in case of modifyAnchors option is 2', function() {
ctx.config.marked.modifyAnchors = 2;
var r = renderer.bind(ctx);
var result = r({text: body});
result.should.eql([
'<ul>',
'<li><a href=\"#example\">Example</a></li>',
'</ul>',
'<h1 id=\"EXAMPLE\"><a href=\"#EXAMPLE\" class=\"headerlink\" title=\"Example\"></a>Example</h1>'
].join('\n'));
});
it('should set anchors to lowerCase in case of modifyAnchors option is 1', function() {
ctx.config.marked.modifyAnchors = 1;
var r = renderer.bind(ctx);
var result = r({text: body});
result.should.eql([
'<ul>',
'<li><a href=\"#example\">Example</a></li>',
'</ul>',
'<h1 id=\"example\"><a href=\"#example\" class=\"headerlink\" title=\"Example\"></a>Example</h1>'
].join('\n'));
});
});
});