forked from brechtcs/rehype-urls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
39 lines (32 loc) · 1.34 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
var rehype = require('rehype')
var tape = require('tape')
var urls = require('./')
tape('return', t => {
var href = '<a href="http://example.com/page.html">text</a>'
var src = '<img src="http://example.com/image.jpg">'
var p = rehype().use(urls, url => url.path).freeze()
t.equal(p.processSync(href).contents, wrap('<a href="/page.html">text</a>'), 'return href string')
t.equal(p.processSync(src).contents, wrap('<img src="/image.jpg">'), 'return src string')
t.end()
})
tape('mutate', t => {
var input = '<a href="/page.html">link</a>'
var p = rehype().use(urls, function (url, node) {
node.properties.target = '_blank'
url.protocol = 'http'
url.host = 'example.org'
})
t.equal(p.processSync(input).contents, wrap('<a href="http://example.org/page.html" target="_blank">link</a>'), 'mutate node & url object')
t.end()
})
tape('option object', t => {
var href = '<a href="http://example.com/page.html">text</a>'
var src = '<img src="http://example.com/image.jpg">'
var p = rehype().use(urls, { transform: url => url.path }).freeze()
t.equal(p.processSync(href).contents, wrap('<a href="/page.html">text</a>'), 'return href string')
t.equal(p.processSync(src).contents, wrap('<img src="/image.jpg">'), 'return src string')
t.end()
})
function wrap (html) {
return `<html><head></head><body>${html}</body></html>`
}