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.
This commit is contained in:
parent
7a3f2928de
commit
f3d9d34f3c
3 changed files with 19 additions and 12 deletions
|
@ -158,7 +158,6 @@ func (s Status) String() string {
|
||||||
|
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
|
|
||||||
%s
|
%s
|
||||||
%s
|
%s
|
||||||
|
|
||||||
|
@ -179,10 +178,9 @@ func (s Status) String() string {
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
format,
|
format,
|
||||||
utilities.DisplayNameFormat(s.Account.DisplayName),
|
utilities.DisplayNameFormat(s.Account.DisplayName), s.Account.Username,
|
||||||
s.Account.Username,
|
|
||||||
utilities.HeaderFormat("CONTENT:"),
|
utilities.HeaderFormat("CONTENT:"),
|
||||||
utilities.WrapLines(s.Text, "\n ", 80),
|
utilities.WrapLines(utilities.StripHTMLTags(s.Content), "\n ", 80),
|
||||||
utilities.HeaderFormat("STATUS ID:"),
|
utilities.HeaderFormat("STATUS ID:"),
|
||||||
s.ID,
|
s.ID,
|
||||||
utilities.HeaderFormat("CREATED AT:"),
|
utilities.HeaderFormat("CREATED AT:"),
|
||||||
|
|
|
@ -16,11 +16,11 @@ func (t Timeline) String() string {
|
||||||
|
|
||||||
separator := "────────────────────────────────────────────────────────────────────────────────"
|
separator := "────────────────────────────────────────────────────────────────────────────────"
|
||||||
|
|
||||||
builder.WriteString(t.Name + "\n" + separator + "\n")
|
builder.WriteString(utilities.HeaderFormat(t.Name) + "\n\n")
|
||||||
|
|
||||||
for _, status := range t.Statuses {
|
for _, status := range t.Statuses {
|
||||||
builder.WriteString(utilities.DisplayNameFormat(status.Account.DisplayName) + " (@" + status.Account.Username + ")\n\n")
|
builder.WriteString(utilities.DisplayNameFormat(status.Account.DisplayName) + " (@" + status.Account.Username + ")\n")
|
||||||
builder.WriteString(utilities.WrapLines(status.Text, "\n", 80) + "\n\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(utilities.FieldFormat("ID:") + " " + status.ID + "\t" + utilities.FieldFormat("Created at:") + " " + utilities.FormatTime(status.CreatedAt) + "\n")
|
||||||
builder.WriteString(separator + "\n")
|
builder.WriteString(separator + "\n")
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,17 +43,26 @@ func StripHTMLTags(text string) string {
|
||||||
case html.ErrorToken:
|
case html.ErrorToken:
|
||||||
return builder.String()
|
return builder.String()
|
||||||
case html.TextToken:
|
case html.TextToken:
|
||||||
text := token.Token().String()
|
text := token.Token().Data
|
||||||
builder.WriteString(text)
|
builder.WriteString(text)
|
||||||
case html.StartTagToken:
|
case html.StartTagToken, html.EndTagToken:
|
||||||
tag := token.Token().String()
|
tag := token.Token().String()
|
||||||
if tag == "<br>" {
|
builder.WriteString(transformTag(tag))
|
||||||
builder.WriteString("\n")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func transformTag(tag string) string {
|
||||||
|
switch tag {
|
||||||
|
case "<br>":
|
||||||
|
return "\n"
|
||||||
|
case "<p>", "</p>":
|
||||||
|
return "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func WrapLines(text, separator string, charLimit int) string {
|
func WrapLines(text, separator string, charLimit int) string {
|
||||||
lines := strings.Split(text, "\n")
|
lines := strings.Split(text, "\n")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue