From f3d9d34f3ca6534590a4e1e31a144a618790008a Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sun, 26 May 2024 15:07:34 +0100 Subject: [PATCH] fix: content missing when displaying Status This commit fixes the issue where the contents of a status is not shown when displayed on screen. For statuses made in GTS the Text field is populated with the plain text version of the content however this is unfortunately not the case for Mastodon statuses, therefore the Content field is used instead and the contents is processed with StripHTMLTags function to remove the HTML tags before printing. --- internal/model/status.go | 6 ++---- internal/model/timeline.go | 6 +++--- internal/utilities/utilities.go | 19 ++++++++++++++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/internal/model/status.go b/internal/model/status.go index 29dd695..81df7d7 100644 --- a/internal/model/status.go +++ b/internal/model/status.go @@ -158,7 +158,6 @@ func (s Status) String() string { %s %s - %s %s @@ -179,10 +178,9 @@ func (s Status) String() string { return fmt.Sprintf( format, - utilities.DisplayNameFormat(s.Account.DisplayName), - s.Account.Username, + utilities.DisplayNameFormat(s.Account.DisplayName), s.Account.Username, utilities.HeaderFormat("CONTENT:"), - utilities.WrapLines(s.Text, "\n ", 80), + utilities.WrapLines(utilities.StripHTMLTags(s.Content), "\n ", 80), utilities.HeaderFormat("STATUS ID:"), s.ID, utilities.HeaderFormat("CREATED AT:"), diff --git a/internal/model/timeline.go b/internal/model/timeline.go index 7f3480f..a150e81 100644 --- a/internal/model/timeline.go +++ b/internal/model/timeline.go @@ -16,11 +16,11 @@ func (t Timeline) String() string { separator := "────────────────────────────────────────────────────────────────────────────────" - builder.WriteString(t.Name + "\n" + separator + "\n") + builder.WriteString(utilities.HeaderFormat(t.Name) + "\n\n") for _, status := range t.Statuses { - builder.WriteString(utilities.DisplayNameFormat(status.Account.DisplayName) + " (@" + status.Account.Username + ")\n\n") - builder.WriteString(utilities.WrapLines(status.Text, "\n", 80) + "\n\n") + builder.WriteString(utilities.DisplayNameFormat(status.Account.DisplayName) + " (@" + status.Account.Username + ")\n") + builder.WriteString(utilities.WrapLines(utilities.StripHTMLTags(status.Content), "\n", 80) + "\n\n") builder.WriteString(utilities.FieldFormat("ID:") + " " + status.ID + "\t" + utilities.FieldFormat("Created at:") + " " + utilities.FormatTime(status.CreatedAt) + "\n") builder.WriteString(separator + "\n") } diff --git a/internal/utilities/utilities.go b/internal/utilities/utilities.go index d3fc812..e2e4b0e 100644 --- a/internal/utilities/utilities.go +++ b/internal/utilities/utilities.go @@ -43,17 +43,26 @@ func StripHTMLTags(text string) string { case html.ErrorToken: return builder.String() case html.TextToken: - text := token.Token().String() + text := token.Token().Data builder.WriteString(text) - case html.StartTagToken: + case html.StartTagToken, html.EndTagToken: tag := token.Token().String() - if tag == "
" { - builder.WriteString("\n") - } + builder.WriteString(transformTag(tag)) } } } +func transformTag(tag string) string { + switch tag { + case "
": + return "\n" + case "

", "

": + return "\n" + } + + return "" +} + func WrapLines(text, separator string, charLimit int) string { lines := strings.Split(text, "\n")