forked from helpers/handlebars-helpers
/
markdown.js
41 lines (33 loc) · 1.34 KB
/
markdown.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
'use strict';
require('mocha');
const assert = require('assert');
const fs = require('fs');
const hbs = require('handlebars').create();
const markdownHelpers = require('../lib/markdown');
hbs.registerHelper(markdownHelpers);
describe('markdown', function() {
describe('markdown', function() {
it('should render markdown using the block helper (very simple)', function() {
const template = hbs.compile('{{#markdownToHTML}}## {{../title}}{{/markdownToHTML}}');
assert.equal(template({title: 'Markdown Test'}), '<h2>Markdown Test</h2>\n');
});
it('should render markdown using the block helper (simple)', function() {
const templateMd = fs.readFileSync('test/fixtures/simple.md', 'utf8');
const expected = fs.readFileSync('test/expected/simple.html', 'utf8');
const template = hbs.compile(`{{#markdownToHTML}}${templateMd}{{/markdownToHTML}}`);
assert.equal(template({word: 'Awesome'}), expected);
});
it('should render markdown using an inline call', function() {
const templateMd = `## Some Markdown
- one
- two
- three
[Click here](http://github.com)
### Awesome!
`;
const expected = fs.readFileSync('test/expected/simple.html', 'utf8');
const template = hbs.compile('{{markdownToHTML md}}', {noEscape: true});
assert.equal(template({md: templateMd}), expected);
});
});
});