diff options
author | Sebastian P <5564491+s3lph@users.noreply.github.com> | 2020-10-01 22:50:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-01 22:50:56 +0200 |
commit | 214a6a13861b9fd495797386f36507373728e577 (patch) | |
tree | a2eb9541924b432ecf7a0807f42281296fa144a4 /vendor/layeh.com/gumble/gumbleutil/textmessage.go | |
parent | e7781dc79c0c556f60eb64a93a95a5da494dcf2d (diff) | |
download | matterbridge-msglm-214a6a13861b9fd495797386f36507373728e577.tar.gz matterbridge-msglm-214a6a13861b9fd495797386f36507373728e577.tar.bz2 matterbridge-msglm-214a6a13861b9fd495797386f36507373728e577.zip |
Add Mumble support (#1245)
Diffstat (limited to 'vendor/layeh.com/gumble/gumbleutil/textmessage.go')
-rw-r--r-- | vendor/layeh.com/gumble/gumbleutil/textmessage.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/vendor/layeh.com/gumble/gumbleutil/textmessage.go b/vendor/layeh.com/gumble/gumbleutil/textmessage.go new file mode 100644 index 00000000..1ccb62b4 --- /dev/null +++ b/vendor/layeh.com/gumble/gumbleutil/textmessage.go @@ -0,0 +1,45 @@ +package gumbleutil + +import ( + "bytes" + "encoding/xml" + "strings" + + "layeh.com/gumble/gumble" +) + +// PlainText returns the Message string without HTML tags or entities. +func PlainText(tm *gumble.TextMessage) string { + d := xml.NewDecoder(strings.NewReader(tm.Message)) + d.Strict = false + d.AutoClose = xml.HTMLAutoClose + d.Entity = xml.HTMLEntity + + var b bytes.Buffer + newline := false + for { + t, _ := d.Token() + if t == nil { + break + } + switch node := t.(type) { + case xml.CharData: + if len(node) > 0 { + b.Write(node) + newline = false + } + case xml.StartElement: + switch node.Name.Local { + case "address", "article", "aside", "audio", "blockquote", "canvas", "dd", "div", "dl", "fieldset", "figcaption", "figure", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "header", "hgroup", "hr", "noscript", "ol", "output", "p", "pre", "section", "table", "tfoot", "ul", "video": + if !newline { + b.WriteByte('\n') + newline = true + } + case "br": + b.WriteByte('\n') + newline = true + } + } + } + return b.String() +} |