From 86843d61f63ac1c41c32ca37474084893cbf6b56 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 9 Mar 2025 16:55:47 +0200 Subject: [PATCH] web/preferences: add option to disable inline images --- pkg/hicli/html.go | 34 +++++++++++++++----- pkg/hicli/sync.go | 2 +- web/src/api/types/preferences/preferences.ts | 6 ++++ web/src/ui/StylePreferences.tsx | 9 ++++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/pkg/hicli/html.go b/pkg/hicli/html.go index 31425b5..a2134ee 100644 --- a/pkg/hicli/html.go +++ b/pkg/hicli/html.go @@ -414,24 +414,42 @@ var HTMLSanitizerImgSrcTemplate = "mxc://%s/%s" func writeImg(w *strings.Builder, attr []html.Attribute) id.ContentURI { src, alt, title, isCustomEmoji, width, height := parseImgAttributes(attr) + mxc := id.ContentURIString(src).ParseOrIgnore() + if !mxc.IsValid() { + w.WriteString("") + writeEscapedString(w, alt) + w.WriteString("") + return id.ContentURI{} + } + url := fmt.Sprintf(HTMLSanitizerImgSrcTemplate, mxc.Homeserver, mxc.FileID) + + w.WriteString("") + writeEscapedString(w, alt) + w.WriteString("") + w.WriteString("({ + displayName: "Show inline images", + description: "If disabled, custom emojis and other inline images will not be rendered and the alt attribute will be shown instead.", + allowedContexts: anyContext, + defaultValue: true, + }), code_block_line_wrap: new Preference({ displayName: "Code block line wrap", description: "Whether to wrap long lines in code blocks instead of scrolling horizontally.", diff --git a/web/src/ui/StylePreferences.tsx b/web/src/ui/StylePreferences.tsx index 8c2da2b..d474259 100644 --- a/web/src/ui/StylePreferences.tsx +++ b/web/src/ui/StylePreferences.tsx @@ -117,6 +117,15 @@ const StylePreferences = ({ client, activeRoom }: StylePreferencesProps) => { --timeline-status-size: 2rem; } `, [preferences.display_read_receipts]) + useStyle(() => !preferences.show_inline_images && css` + a.hicli-inline-img-fallback { + display: inline !important; + } + + img.hicli-inline-img { + display: none; + } + `, [preferences.show_inline_images]) useAsyncStyle(() => preferences.code_block_theme === "auto" ? ` @import url("_gomuks/codeblock/github.css") (prefers-color-scheme: light); @import url("_gomuks/codeblock/github-dark.css") (prefers-color-scheme: dark);