mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-21 10:12:00 -08:00
Add StripMarkdown option (irc). (#1145)
Enable `StripMarkdown` to strip markdown for irc.
This commit is contained in:
parent
3c4a3e3f75
commit
ba0bfe70a8
@ -136,6 +136,7 @@ type Protocol struct {
|
|||||||
SkipTLSVerify bool // IRC, mattermost
|
SkipTLSVerify bool // IRC, mattermost
|
||||||
SkipVersionCheck bool // mattermost
|
SkipVersionCheck bool // mattermost
|
||||||
StripNick bool // all protocols
|
StripNick bool // all protocols
|
||||||
|
StripMarkdown bool // irc
|
||||||
SyncTopic bool // slack
|
SyncTopic bool // slack
|
||||||
TengoModifyMessage string // general
|
TengoModifyMessage string // general
|
||||||
Team string // mattermost, keybase
|
Team string // mattermost, keybase
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/42wim/matterbridge/bridge/helper"
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
"github.com/lrstanley/girc"
|
"github.com/lrstanley/girc"
|
||||||
|
stripmd "github.com/writeas/go-strip-markdown"
|
||||||
|
|
||||||
// We need to import the 'data' package as an implicit dependency.
|
// We need to import the 'data' package as an implicit dependency.
|
||||||
// See: https://godoc.org/github.com/paulrosania/go-charset/charset
|
// See: https://godoc.org/github.com/paulrosania/go-charset/charset
|
||||||
@ -156,6 +157,10 @@ func (b *Birc) Send(msg config.Message) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var msgLines []string
|
var msgLines []string
|
||||||
|
if b.GetBool("StripMarkdown") {
|
||||||
|
msg.Text = stripmd.Strip(msg.Text)
|
||||||
|
}
|
||||||
|
|
||||||
if b.GetBool("MessageSplit") {
|
if b.GetBool("MessageSplit") {
|
||||||
msgLines = helper.GetSubLines(msg.Text, b.MessageLength)
|
msgLines = helper.GetSubLines(msg.Text, b.MessageLength)
|
||||||
} else {
|
} else {
|
||||||
|
2
go.mod
2
go.mod
@ -49,6 +49,7 @@ require (
|
|||||||
github.com/spf13/viper v1.6.1
|
github.com/spf13/viper v1.6.1
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
|
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
|
||||||
|
github.com/writeas/go-strip-markdown v2.0.1+incompatible
|
||||||
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
|
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
|
||||||
github.com/yaegashi/msgraph.go v0.1.2
|
github.com/yaegashi/msgraph.go v0.1.2
|
||||||
github.com/zfjagann/golang-ring v0.0.0-20190106091943-a88bb6aef447
|
github.com/zfjagann/golang-ring v0.0.0-20190106091943-a88bb6aef447
|
||||||
@ -56,6 +57,7 @@ require (
|
|||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
||||||
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||||
|
github.com/writeas/go-strip-markdown v2.0.1+incompatible
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
2
go.sum
2
go.sum
@ -250,6 +250,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
|
|||||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||||
github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
|
github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
|
||||||
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||||
|
github.com/writeas/go-strip-markdown v2.0.1+incompatible h1:IIqxTM5Jr7RzhigcL6FkrCNfXkvbR+Nbu1ls48pXYcw=
|
||||||
|
github.com/writeas/go-strip-markdown v2.0.1+incompatible/go.mod h1:Rsyu10ZhbEK9pXdk8V6MVnZmTzRG0alMNLMwa0J01fE=
|
||||||
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
|
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
|
||||||
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
|
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
|
||||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||||
|
@ -103,6 +103,10 @@ ColorNicks=false
|
|||||||
#OPTIONAL (default empty)
|
#OPTIONAL (default empty)
|
||||||
RunCommands=["PRIVMSG user hello","PRIVMSG chanserv something"]
|
RunCommands=["PRIVMSG user hello","PRIVMSG chanserv something"]
|
||||||
|
|
||||||
|
#StripMarkdown strips markdown from messages
|
||||||
|
#OPTIONAL (default false)
|
||||||
|
StripMarkdown=false
|
||||||
|
|
||||||
#Nicks you want to ignore.
|
#Nicks you want to ignore.
|
||||||
#Regular expressions supported
|
#Regular expressions supported
|
||||||
#Messages from those users will not be sent to other bridges.
|
#Messages from those users will not be sent to other bridges.
|
||||||
|
3
vendor/github.com/writeas/go-strip-markdown/.gitignore
generated
vendored
Normal file
3
vendor/github.com/writeas/go-strip-markdown/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*~
|
||||||
|
*.swp
|
||||||
|
cmd/strip/strip
|
21
vendor/github.com/writeas/go-strip-markdown/LICENSE
generated
vendored
Normal file
21
vendor/github.com/writeas/go-strip-markdown/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Write.as
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
51
vendor/github.com/writeas/go-strip-markdown/README.md
generated
vendored
Normal file
51
vendor/github.com/writeas/go-strip-markdown/README.md
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# go-strip-markdown
|
||||||
|
|
||||||
|
[![GoDoc](https://godoc.org/github.com/writeas/go-strip-markdown?status.svg)](https://godoc.org/github.com/writeas/go-strip-markdown)
|
||||||
|
|
||||||
|
A Markdown stripper written in Go (golang).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
You could create a simple command-line utility:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/writeas/go-strip-markdown"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println(stripmd.Strip(os.Args[1]))
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
You could pass it Markdown and get pure, beauteous text in return:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./strip "# A Tale of Text Formatting
|
||||||
|
|
||||||
|
_One fateful day_ a developer was presented with [Markdown](https://daringfireball.net/projects/markdown/).
|
||||||
|
And they wanted **none of it**."
|
||||||
|
|
||||||
|
# A Tale of Text Formatting
|
||||||
|
#
|
||||||
|
# One fateful day a developer was presented with Markdown.
|
||||||
|
# And they wanted none of it.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Inspiration
|
||||||
|
This was largely based off of [remove-markdown](https://github.com/stiang/remove-markdown), a Markdown stripper written in Javascript.
|
||||||
|
|
||||||
|
## Used by
|
||||||
|
|
||||||
|
This library is used in these projects:
|
||||||
|
|
||||||
|
* [WriteFreely](https://github.com/writeas/writefreely)
|
||||||
|
|
||||||
|
## License
|
||||||
|
MIT.
|
66
vendor/github.com/writeas/go-strip-markdown/strip.go
generated
vendored
Normal file
66
vendor/github.com/writeas/go-strip-markdown/strip.go
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
// Package stripmd strips Markdown from text
|
||||||
|
package stripmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
listLeadersReg = regexp.MustCompile(`(?m)^([\s\t]*)([\*\-\+]|\d\.)\s+`)
|
||||||
|
|
||||||
|
headerReg = regexp.MustCompile(`\n={2,}`)
|
||||||
|
strikeReg = regexp.MustCompile(`~~`)
|
||||||
|
codeReg = regexp.MustCompile("`{3}" + `.*\n`)
|
||||||
|
|
||||||
|
htmlReg = regexp.MustCompile("<(.*?)>")
|
||||||
|
emphReg = regexp.MustCompile(`\*\*([^*]+)\*\*`)
|
||||||
|
emphReg2 = regexp.MustCompile(`\*([^*]+)\*`)
|
||||||
|
emphReg3 = regexp.MustCompile(`__([^_]+)__`)
|
||||||
|
emphReg4 = regexp.MustCompile(`_([^_]+)_`)
|
||||||
|
setextHeaderReg = regexp.MustCompile(`^[=\-]{2,}\s*$`)
|
||||||
|
footnotesReg = regexp.MustCompile(`\[\^.+?\](\: .*?$)?`)
|
||||||
|
footnotes2Reg = regexp.MustCompile(`\s{0,2}\[.*?\]: .*?$`)
|
||||||
|
imagesReg = regexp.MustCompile(`\!\[(.*?)\]\s?[\[\(].*?[\]\)]`)
|
||||||
|
linksReg = regexp.MustCompile(`\[(.*?)\][\[\(].*?[\]\)]`)
|
||||||
|
blockquoteReg = regexp.MustCompile(`>\s*`)
|
||||||
|
refLinkReg = regexp.MustCompile(`^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$`)
|
||||||
|
atxHeaderReg = regexp.MustCompile(`(?m)^\#{1,6}\s*([^#]+)\s*(\#{1,6})?$`)
|
||||||
|
atxHeaderReg2 = regexp.MustCompile(`([\*_]{1,3})(\S.*?\S)?P1`)
|
||||||
|
atxHeaderReg3 = regexp.MustCompile("(?m)(`{3,})" + `(.*?)?P1`)
|
||||||
|
atxHeaderReg4 = regexp.MustCompile(`^-{3,}\s*$`)
|
||||||
|
atxHeaderReg5 = regexp.MustCompile("`(.+?)`")
|
||||||
|
atxHeaderReg6 = regexp.MustCompile(`\n{2,}`)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Strip returns the given string sans any Markdown.
|
||||||
|
// Where necessary, elements are replaced with their best textual forms, so
|
||||||
|
// for example, hyperlinks are stripped of their URL and become only the link
|
||||||
|
// text, and images lose their URL and become only the alt text.
|
||||||
|
func Strip(s string) string {
|
||||||
|
res := s
|
||||||
|
res = listLeadersReg.ReplaceAllString(res, "$1")
|
||||||
|
|
||||||
|
res = headerReg.ReplaceAllString(res, "\n")
|
||||||
|
res = strikeReg.ReplaceAllString(res, "")
|
||||||
|
res = codeReg.ReplaceAllString(res, "")
|
||||||
|
|
||||||
|
res = emphReg.ReplaceAllString(res, "$1")
|
||||||
|
res = emphReg2.ReplaceAllString(res, "$1")
|
||||||
|
res = emphReg3.ReplaceAllString(res, "$1")
|
||||||
|
res = emphReg4.ReplaceAllString(res, "$1")
|
||||||
|
res = htmlReg.ReplaceAllString(res, "$1")
|
||||||
|
res = setextHeaderReg.ReplaceAllString(res, "")
|
||||||
|
res = footnotesReg.ReplaceAllString(res, "")
|
||||||
|
res = footnotes2Reg.ReplaceAllString(res, "")
|
||||||
|
res = imagesReg.ReplaceAllString(res, "$1")
|
||||||
|
res = linksReg.ReplaceAllString(res, "$1")
|
||||||
|
res = blockquoteReg.ReplaceAllString(res, " ")
|
||||||
|
res = refLinkReg.ReplaceAllString(res, "")
|
||||||
|
res = atxHeaderReg.ReplaceAllString(res, "$1")
|
||||||
|
res = atxHeaderReg2.ReplaceAllString(res, "$2")
|
||||||
|
res = atxHeaderReg3.ReplaceAllString(res, "$2")
|
||||||
|
res = atxHeaderReg4.ReplaceAllString(res, "")
|
||||||
|
res = atxHeaderReg5.ReplaceAllString(res, "$1")
|
||||||
|
res = atxHeaderReg6.ReplaceAllString(res, "\n\n")
|
||||||
|
return res
|
||||||
|
}
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -200,6 +200,8 @@ github.com/technoweenie/multipartstreamer
|
|||||||
github.com/valyala/bytebufferpool
|
github.com/valyala/bytebufferpool
|
||||||
# github.com/valyala/fasttemplate v1.1.0
|
# github.com/valyala/fasttemplate v1.1.0
|
||||||
github.com/valyala/fasttemplate
|
github.com/valyala/fasttemplate
|
||||||
|
# github.com/writeas/go-strip-markdown v2.0.1+incompatible
|
||||||
|
github.com/writeas/go-strip-markdown
|
||||||
# github.com/yaegashi/msgraph.go v0.1.2
|
# github.com/yaegashi/msgraph.go v0.1.2
|
||||||
github.com/yaegashi/msgraph.go/beta
|
github.com/yaegashi/msgraph.go/beta
|
||||||
github.com/yaegashi/msgraph.go/jsonx
|
github.com/yaegashi/msgraph.go/jsonx
|
||||||
|
Loading…
Reference in New Issue
Block a user