Skip to content

Commit

Permalink
Twitter widget properly unescapes HTML entities
Browse files Browse the repository at this point in the history
  • Loading branch information
senorprogrammer committed Aug 30, 2018
1 parent 0e797fe commit 2af0fe5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions twitter/widget.go
Expand Up @@ -2,6 +2,7 @@ package twitter

import (
"fmt"
"html"
"regexp"

"github.com/dustin/go-humanize"
Expand Down Expand Up @@ -66,9 +67,12 @@ func (widget *Widget) displayName(tweet Tweet) string {
return tweet.User.ScreenName
}

func (widget *Widget) highlightText(text string) string {
func (widget *Widget) formatText(text string) string {
result := text

// Convert HTML entities
result = html.UnescapeString(result)

// RT indicator
rtRegExp := regexp.MustCompile(`^RT`)
result = rtRegExp.ReplaceAllString(result, "[olive]${0}[white::-]")
Expand All @@ -89,7 +93,7 @@ func (widget *Widget) highlightText(text string) string {
}

func (widget *Widget) format(tweet Tweet) string {
body := widget.highlightText(tweet.Text)
body := widget.formatText(tweet.Text)
name := widget.displayName(tweet)

var attribution string
Expand Down

0 comments on commit 2af0fe5

Please sign in to comment.