forked from JohannesKaufmann/html-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrikethrough.go
More file actions
34 lines (27 loc) · 819 Bytes
/
strikethrough.go
File metadata and controls
34 lines (27 loc) · 819 Bytes
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
package plugin
import (
"strings"
md "github.com/JohannesKaufmann/html-to-markdown"
"github.com/PuerkitoBio/goquery"
)
// Strikethrough converts `<strike>`, `<s>`, and `<del>` elements
func Strikethrough(character string) md.Plugin {
return func(c *md.Converter) []md.Rule {
if character == "" {
character = "~~"
}
return []md.Rule{
{
Filter: []string{"del", "s", "strike"},
Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
// trim spaces so that the following does NOT happen: `~ and cake~`
content = strings.TrimSpace(content)
content = character + content + character
// always have a space to the side to recognize the delimiter
content = md.AddSpaceIfNessesary(selec, content)
return &content
},
},
}
}
}