From 9cdb44d919e12f1cc89f227e853ff318adecfe57 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Sun, 14 Oct 2018 23:11:52 +0800 Subject: [PATCH] Added ability to handle strikethrough after slackdown parsing. (Updated html2md pkg.) --- gateway/gateway.go | 10 ++++++++++ go.mod | 2 +- go.sum | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gateway/gateway.go b/gateway/gateway.go index baa98b2f..1b69c272 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -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 diff --git a/go.mod b/go.mod index 79a0003c..873f409e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index c7c9de11..ac35492c 100644 --- a/go.sum +++ b/go.sum @@ -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=