-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.js
60 lines (52 loc) · 1.5 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
/**
* @import {Root} from 'hast'
*/
import assert from 'node:assert/strict'
import test from 'node:test'
import rehypeStringify from 'rehype-stringify'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'
import {visit} from 'unist-util-visit'
import rehypeRaw from 'rehype-raw'
test('rehypeRaw', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('rehype-raw')).sort(), [
'default'
])
})
await t.test('should work', async function () {
const file = await unified()
.use(remarkParse)
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeRaw)
.use(function () {
/**
* @param {Root} root
*/
return function (root) {
visit(root, 'raw', function () {
assert.fail()
})
}
})
.use(rehypeStringify).process(`<div class="note">
A mix of *markdown* and <em>HTML</em>.
</div>`)
assert.equal(
String(file),
`<div class="note">
<p>A mix of <em>markdown</em> and <em>HTML</em>.</p>
</div>`
)
})
await t.test('tagfilter', async function () {
const file = await unified()
.use(remarkParse)
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeRaw, {tagfilter: true})
.use(rehypeStringify)
.process('<script>alert(1)</script>')
assert.equal(String(file), '<script>alert(1)</script>')
})
})