-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmarkdown_filter_test.go
70 lines (61 loc) · 1.41 KB
/
markdown_filter_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package pipeline
import (
"fmt"
"github.com/russross/blackfriday"
)
func ExampleMarkdownFilter() {
// Custom blackfriday HTML render options
renderer := blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{
Flags: blackfriday.UseXHTML |
blackfriday.NofollowLinks |
blackfriday.CompletePage,
})
// Custom blackfriday extensions
extensions := blackfriday.Tables |
blackfriday.FencedCode |
blackfriday.Autolink |
blackfriday.Strikethrough |
blackfriday.SpaceHeadings |
blackfriday.HardLineBreak |
blackfriday.NoEmptyLineBeforeBlock
pipe := NewPipeline([]Filter{
MarkdownFilter{
Opts: []blackfriday.Option{
blackfriday.WithRenderer(renderer),
blackfriday.WithExtensions(extensions),
},
},
SanitizationFilter{},
})
raw := `# Hello world
<script>alert;</script>
<style>body {}</style>
| Name | Location |
| ---- | --- |
| Jason | Chengdu |
This is [html-pipeline](https://github.com/longbridgeapp/html-pipeline) Markdown filter.`
out, _ := pipe.Call(raw)
fmt.Println(out)
// Output:
// <h1>Hello world</h1>
//
// <p>alert;<br/>
// body {}</p>
//
// <table>
// <thead>
// <tr>
// <th>Name</th>
// <th>Location</th>
// </tr>
// </thead>
//
// <tbody>
// <tr>
// <td>Jason</td>
// <td>Chengdu</td>
// </tr>
// </tbody>
// </table>
// <p>This is <a href="https://github.com/longbridgeapp/html-pipeline" rel="nofollow">html-pipeline</a> Markdown filter.</p>
}