1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Twitter widget properly unescapes HTML entities

This commit is contained in:
Chris Cummer 2018-08-30 08:27:20 -07:00
parent 0e797fea3d
commit 2af0fe51c6

View File

@ -2,6 +2,7 @@ package twitter
import ( import (
"fmt" "fmt"
"html"
"regexp" "regexp"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
@ -66,9 +67,12 @@ func (widget *Widget) displayName(tweet Tweet) string {
return tweet.User.ScreenName return tweet.User.ScreenName
} }
func (widget *Widget) highlightText(text string) string { func (widget *Widget) formatText(text string) string {
result := text result := text
// Convert HTML entities
result = html.UnescapeString(result)
// RT indicator // RT indicator
rtRegExp := regexp.MustCompile(`^RT`) rtRegExp := regexp.MustCompile(`^RT`)
result = rtRegExp.ReplaceAllString(result, "[olive]${0}[white::-]") result = rtRegExp.ReplaceAllString(result, "[olive]${0}[white::-]")
@ -89,7 +93,7 @@ func (widget *Widget) highlightText(text string) string {
} }
func (widget *Widget) format(tweet Tweet) string { func (widget *Widget) format(tweet Tweet) string {
body := widget.highlightText(tweet.Text) body := widget.formatText(tweet.Text)
name := widget.displayName(tweet) name := widget.displayName(tweet)
var attribution string var attribution string