forked from valeriangalliat/markdown-it-anchor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
77 lines (63 loc) · 2.41 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { equal } from 'assert'
import md from 'markdown-it'
import anchor from './'
equal(
md().use(anchor).render('# H1\n\n## H2'),
'<h1 id="h1">H1</h1>\n<h2 id="h2">H2</h2>\n'
)
equal(
md().use(anchor, { level: 2 }).render('# H1\n\n## H2'),
'<h1>H1</h1>\n<h2 id="h2">H2</h2>\n'
)
equal(
md().use(anchor, { permalink: true }).render('# H1'),
'<h1 id="h1">H1 <a class="header-anchor" href="#h1" aria-hidden="true">¶</a></h1>\n'
)
equal(
md().use(anchor, { permalink: true, permalinkClass: 'test' }).render('# H1'),
'<h1 id="h1">H1 <a class="test" href="#h1" aria-hidden="true">¶</a></h1>\n'
)
equal(
md().use(anchor, { permalink: true, permalinkSymbol: 'P' }).render('# H1'),
'<h1 id="h1">H1 <a class="header-anchor" href="#h1" aria-hidden="true">P</a></h1>\n'
)
equal(
md().use(anchor, { permalink: true, permalinkSymbol: '<i class="icon"></i>' }).render('# H1'),
'<h1 id="h1">H1 <a class="header-anchor" href="#h1" aria-hidden="true"><i class="icon"></i></a></h1>\n'
)
equal(
md().use(anchor).render('# Title\n\n## Title'),
'<h1 id="title">Title</h1>\n<h2 id="title-2">Title</h2>\n'
)
equal(
md().use(anchor, { permalink: true, permalinkBefore: true }).render('# H1'),
'<h1 id="h1"><a class="header-anchor" href="#h1" aria-hidden="true">¶</a> H1</h1>\n'
)
equal(
md().use(anchor, { level: 2, permalink: true }).render('# H1\n\n## H2'),
'<h1>H1</h1>\n<h2 id="h2">H2 <a class="header-anchor" href="#h2" aria-hidden="true">¶</a></h2>\n'
)
equal(
md({ html: true }).use(anchor, { permalink: true }).render('# <span>H1</span>'),
'<h1 id="h1"><span>H1</span> <a class="header-anchor" href="#h1" aria-hidden="true">¶</a></h1>\n'
)
const calls = []
const callback = (token, info) => calls.push({ token, info })
equal(
md().use(anchor, { callback }).render('# First Heading\n\n## Second Heading'),
'<h1 id="first-heading">First Heading</h1>\n<h2 id="second-heading">Second Heading</h2>\n'
)
equal(
md().use(anchor, {
permalinkHref: (slug, state) => `${state.env.path}#${slug}`,
permalink: true
}).render('# H1', { path: 'file.html' }),
'<h1 id="h1">H1 <a class="header-anchor" href="file.html#h1" aria-hidden="true">¶</a></h1>\n'
)
equal(calls.length, 2)
equal(calls[0].token.tag, 'h1')
equal(calls[0].info.title, 'First Heading')
equal(calls[0].info.slug, 'first-heading')
equal(calls[1].token.tag, 'h2')
equal(calls[1].info.title, 'Second Heading')
equal(calls[1].info.slug, 'second-heading')