summaryrefslogtreecommitdiff
path: root/ui.go
diff options
context:
space:
mode:
authorDavid Schlachter <t480-debian-git@schlachter.ca>2026-01-09 01:41:29 -0500
committerDavid Schlachter <t480-debian-git@schlachter.ca>2026-01-09 01:41:29 -0500
commit07dea0730b6a1e39881e4b0e1c65531dabd03143 (patch)
tree140bf47aab2bf2e0e19ef0344000c81b6b7cd88e /ui.go
parent78986c0f6c054f0b87de9de12db36ad9e97f1fcb (diff)
Unescape all HTML entities in definition previews
Diffstat (limited to 'ui.go')
-rw-r--r--ui.go11
1 files changed, 6 insertions, 5 deletions
diff --git a/ui.go b/ui.go
index eea1269..3c4dbb7 100644
--- a/ui.go
+++ b/ui.go
@@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
+ "html"
"net/http"
"regexp"
"strings"
@@ -178,15 +179,15 @@ func formatDefinitionForDisplay(policy bluemonday.Policy, definition string, max
// Remove all HTML tags
str = policy.Sanitize(str)
+ // Some Wiktionary entries have HTML entities in them. That's okay for Anki,
+ // but it's not okay for displaying the plain text in the console interface.
+ str = html.UnescapeString(str)
// Add some colour to the start of each definition
str = strings.ReplaceAll(str, "\t- ", "\x1b[0;33;49m•\x1b[0m ")
- // Replace common HTML entities
- str = strings.ReplaceAll(str, "&#39;", "’")
- str = strings.ReplaceAll(str, "&amp;", "&")
-
- // Wrap
+ // Limit the width of the displayed definition to 80 characters, or the
+ // width of the viewport (whichever is smaller).
width := min(maxWidth, 80)
return wordwrap.String(str, width)
}