-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown.test.js
97 lines (82 loc) · 2.34 KB
/
markdown.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
/**
* import modules
*/
import assert from 'assert';
import Handlebars from 'handlebars';
import markdown, {register} from '../src/markdown';
describe('{{#markdown}}...{{/markdown}}', () => {
let template = null,
templateRawContent = null;
before(() => {
const hbs = Handlebars.create();
hbs.registerHelper('markdown', markdown);
template = hbs.compile('{{#markdown}}{{content}}{{/markdown}}');
templateRawContent = hbs.compile('{{#markdown}}{{{content}}}{{/markdown}}');
});
it('should return empty string if "content" is empty value.', () => {
const contents = [
['', ''],
[[], ''],
[null, '']
];
contents.forEach(([content, expected]) => {
const result = template({content});
assert(typeof result === 'string');
assert(result === expected);
});
});
it('should return HTML string if "content" is markdown string.', () => {
const contents = [
[
`# heading
+ list 1
+ list 2
+ list 3 [link](https://google.com)
`,
`<h1 id="heading">heading</h1>
<ul>
<li>list 1</li>
<li>list 2</li>
<li>list 3 <a href="https://google.com">link</a></li>
</ul>
`
]
];
contents.forEach(([content, expected]) => {
const result = template({content});
assert(typeof result === 'string');
assert(result === expected);
});
});
it('should return highlighted HTML string if "content" is markdown string that include code block.', () => {
const contents = [
[
`# heading
\`\`\`html
<div class="hoge">
huga
</div>
\`\`\`
`,
`<h1 id="heading">heading</h1>
<pre><code class="hljs language-html"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"hoge"</span>></span>
huga
<span class="hljs-tag"></<span class="hljs-name">div</span>></span></code></pre>
`
]
];
contents.forEach(([content, expected]) => {
const result = templateRawContent({content});
assert(typeof result === 'string');
assert(result === expected);
});
});
describe('register', () => {
it('should be registered.', () => {
const hbs = Handlebars.create();
register(hbs);
hbs.registerHelper('viaRegisterHelper', markdown);
assert(hbs.helpers.markdown === hbs.helpers.viaRegisterHelper);
});
});
});