forked from gomarkdown/markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_renderer_test.go
56 lines (48 loc) · 1.14 KB
/
html_renderer_test.go
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
package markdown
import (
"io"
"testing"
"github.com/gomarkdown/markdown/ast"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
)
func renderHookEmpty(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
return ast.GoToNext, true
}
func TestRenderNodeHookEmpty(t *testing.T) {
tests := []string{
"[foo](gopher://foo.bar)",
"",
"[foo](mailto://bar/)\n",
"",
}
htmlParams := html.RendererOptions{
RenderNodeHook: renderHookEmpty,
}
params := TestParams{
RendererOptions: htmlParams,
}
doTestsParam(t, tests, params)
}
func renderHookCodeBlock(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
_, ok := node.(*ast.CodeBlock)
if !ok {
return ast.GoToNext, false
}
io.WriteString(w, "code_replacement")
return ast.GoToNext, true
}
func TestRenderNodeHookCode(t *testing.T) {
tests := []string{
"a\n```go\ncode\n```\nb",
"<p>a</p>\ncode_replacement\n<p>b</p>\n",
}
opts := html.RendererOptions{
RenderNodeHook: renderHookCodeBlock,
}
params := TestParams{
RendererOptions: opts,
extensions: parser.CommonExtensions,
}
doTestsParam(t, tests, params)
}