Added ability to handle strikethrough after slackdown parsing. (Updated html2md pkg.)

This commit is contained in:
Patrick Connolly
2018-10-14 23:11:52 +08:00
parent 3253bf2d47
commit 9cdb44d919
3 changed files with 15 additions and 1 deletions

View File

@@ -380,6 +380,16 @@ func (gw *Gateway) handleMessage(msg config.Message, dest *bridge.Bridge) []*BrM
stripped, _ := htmltags.Strip(text, allowableTags, false)
text = stripped.ToString()
html2md.AddRule("del", &html2md.Rule{
Patterns: []string{"del"},
Replacement: func(innerHTML string, attrs []string) string {
if len(attrs) > 1 {
// Extra spaces so that Slack will process, even though Chinese characters don't get spaces
return html2md.WrapInlineTag(attrs[1], " ~", "~ ")
}
return ""
},
})
text := html2md.Convert(text)
// colons: revert temp token

2
go.mod
View File

@@ -48,7 +48,7 @@ require (
github.com/nlopes/slack v0.3.1-0.20180805133408-21749ab136a8
github.com/onsi/ginkgo v1.6.0 // indirect
github.com/onsi/gomega v1.4.1 // indirect
github.com/patcon/html2md v0.0.0-20181014121949-a471df9ca0b1
github.com/patcon/html2md v0.0.0-20181014143736-370b673716b2
github.com/paulrosania/go-charset v0.0.0-20151028000031-621bb39fcc83
github.com/pborman/uuid v0.0.0-20160216163710-c55201b03606 // indirect
github.com/pelletier/go-toml v0.0.0-20180228233631-05bcc0fb0d3e // indirect

4
go.sum
View File

@@ -112,6 +112,10 @@ github.com/patcon/html2md v0.0.0-20180317074532-13aaeeae9fb2 h1:2R8DHpwHLIrC5RFT
github.com/patcon/html2md v0.0.0-20180317074532-13aaeeae9fb2/go.mod h1:lPwXvF3BqK5Y9DLUOOnt8DrL3tnfHL01ScB1y60aKIw=
github.com/patcon/html2md v0.0.0-20181014121949-a471df9ca0b1 h1:FXqX1+5vKCerDSVU8FHLwOYct5HDa7ju/UqaXA3vT+g=
github.com/patcon/html2md v0.0.0-20181014121949-a471df9ca0b1/go.mod h1:lPwXvF3BqK5Y9DLUOOnt8DrL3tnfHL01ScB1y60aKIw=
github.com/patcon/html2md v0.0.0-20181014143505-919a839dda6f h1:+NUzuuLINRJwP3Xp54noXFoUtDQHPtgnZLw1juw8vZU=
github.com/patcon/html2md v0.0.0-20181014143505-919a839dda6f/go.mod h1:lPwXvF3BqK5Y9DLUOOnt8DrL3tnfHL01ScB1y60aKIw=
github.com/patcon/html2md v0.0.0-20181014143736-370b673716b2 h1:Xgh4a4ltKx6L0swVSy6PosfxWOqlMyFtFggJlJ92exc=
github.com/patcon/html2md v0.0.0-20181014143736-370b673716b2/go.mod h1:lPwXvF3BqK5Y9DLUOOnt8DrL3tnfHL01ScB1y60aKIw=
github.com/paulrosania/go-charset v0.0.0-20151028000031-621bb39fcc83 h1:XQonH5Iv5rbyIkMJOQ4xKmKHQTh8viXtRSmep5Ca5I4=
github.com/paulrosania/go-charset v0.0.0-20151028000031-621bb39fcc83/go.mod h1:YnNlZP7l4MhyGQ4CBRwv6ohZTPrUJJZtEv4ZgADkbs4=
github.com/pborman/uuid v0.0.0-20160216163710-c55201b03606 h1:/CPgDYrfeK2LMK6xcUhvI17yO9SlpAdDIJGkhDEgO8A=