-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
61 lines (54 loc) · 1.75 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
var test = require('tape')
var assertHtml = require('assert-html')
var html = require('bel')
test('render html', function (t) {
var Markdown = require('./')
var md = Markdown()
var dom = html`<p><strong>Hello</strong> <em>world</em></p>`
var mdDom = md`**Hello** _world_`
assertHtml(t, dom.toString(), mdDom)
t.end()
})
test('render html with argumetns', function (t) {
var Markdown = require('./')
var md = Markdown()
var friend = 'Peter'
var friendLastName = 'Pan'
var dom = html`<p><strong>Hello</strong> <em>${friend} ${friendLastName}</em></p>`
var mdDom = md`**Hello** _${friend} ${friendLastName}_`
assertHtml(t, dom.toString(), mdDom)
t.end()
})
test('allow access to override rules', function (t) {
var defaultRender = function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options)
}
function link_open (tokens, idx, options, env, self) { // eslint-disable-line camelcase
var aIndex = tokens[idx].attrIndex('target')
if (aIndex < 0) {
tokens[idx].attrPush(['target', '_blank'])
} else {
tokens[idx].attrs[aIndex][1] = '_blank'
}
return defaultRender(tokens, idx, options, env, self)
}
var marli = require('./')({ rules: { link_open } })
var dom = html`<p><a href="www.google.com" target="_blank">google</a></p>`
var mdDom = marli`[google](www.google.com)`
assertHtml(t, dom.toString(), mdDom)
t.end()
})
test('allow passing plugins to Markdown-it', function (t) {
var Markdown = require('./')
var md = Markdown({plugins: [require('markdown-it-meta')]})
md`---
title: Welcome to Markdown-it-meta
keywords: markdown-it-meta
---
## Hello World`
t.deepEqual(md._md.meta, {
title: 'Welcome to Markdown-it-meta',
keywords: 'markdown-it-meta'
})
t.end()
})