-
Notifications
You must be signed in to change notification settings - Fork 7
/
strip_test.go
125 lines (86 loc) · 2.7 KB
/
strip_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package stripmd
import (
"fmt"
"testing"
)
func TestStripMarkdown(t *testing.T) {
// Same tests as github.com/stiang/remove-markdown
in := `## This is a heading ##
This is an _emphasized paragraph_ with [a link](http://www.disney.com/). Here's an _[emphasized link](https://write.as)_.
### This is another heading
In ` + "`Getting Started` we **set up** `something`" + ` __foo__.
* Some list
* With items
* Even indented`
out := `This is a heading
This is an emphasized paragraph with a link. Here's an emphasized link.
This is another heading
In Getting Started we set up something foo.
Some list
With items
Even indented`
if res := Strip(in); res != out {
t.Errorf("Original:\n\n%s\n\nGot:\n\n%s", in, res)
}
// More extensive tests
in = `# Markdown is simple
It lets you _italicize words_ and **bold them**, too. You can ~~cross things out~~ and add __emphasis__ to your writing.
But you can also link to stuff, like [Write.as](https://write.as)!
## Organize text with headers
Create sections in your text just like this.
### Use lists
You might already write lists like this:
* Get groceries
* Go for a walk
And sometimes you need to do things in a certain order:
1. Put on clothes
2. Put on shoes
3. Go for a walk
### Highlight text
You can quote interesting people:
> Live long and prosper.
You can even share ` + "`code stuff`."
out = `Markdown is simple
It lets you italicize words and bold them, too. You can cross things out and add emphasis to your writing.
But you can also link to stuff, like Write.as!
Organize text with headers
Create sections in your text just like this.
Use lists
You might already write lists like this:
Get groceries
Go for a walk
And sometimes you need to do things in a certain order:
Put on clothes
Put on shoes
Go for a walk
Highlight text
You can quote interesting people:
Live long and prosper.
You can even share code stuff.`
if res := Strip(in); res != out {
t.Errorf("Original:\n\n%s\n\nGot:\n\n%s", in, res)
}
in = "![] (https://write.as/favicon.ico)"
out = ""
if res := Strip(in); res != out {
t.Errorf("Original:\n\n%s\n\nGot:\n\n%s", in, res)
}
in = "![Some image] (https://write.as/favicon.ico)"
out = "Some image"
if res := Strip(in); res != out {
t.Errorf("Original:\n\n%s\n\nGot:\n\n%s", in, res)
}
in = "![Some image](https://write.as/favicon.ico)"
out = "Some image"
if res := Strip(in); res != out {
t.Errorf("Original:\n\n%s\n\nGot:\n\n%s", in, res)
}
}
func ExampleStrip() {
fmt.Println(Strip(`# Hello, world!
This is [a Go library](https://github.com/writeas/go-strip-markdown) for stripping **Markdown** from _any_ text.`))
// Output:
// Hello, world!
//
// This is a Go library for stripping Markdown from any text.
}