From 1f0c261fd2d3da250f62040236f7629f603f0b03 Mon Sep 17 00:00:00 2001 From: tobi Date: Wed, 7 May 2025 11:48:21 +0000 Subject: [bugfix] Fix indentation on multi-line alt text in web view (#4149) This pull request closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3403 by searching for alt or title attributes in HTML, looking for the shortest indent (if any) at the start of multiline content of said attributes, and remove that shortest indent from each line. This is a bit more fiddly than the "easy" way of doing it, but it has the advantage that it preserves user-added indents at the start of lines of alt text. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4149 Co-authored-by: tobi Co-committed-by: tobi --- internal/router/template_test.go | 46 ++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'internal/router/template_test.go') diff --git a/internal/router/template_test.go b/internal/router/template_test.go index 19bf759e0..1c82d3ba4 100644 --- a/internal/router/template_test.go +++ b/internal/router/template_test.go @@ -22,10 +22,19 @@ import ( "testing" ) -func TestOutdentPre(t *testing.T) { +func TestOutdentPreformatted(t *testing.T) { const html = template.HTML(`
-
+

Here's a bunch of HTML, read it and weep, weep then!

<section class="about-user">
                     <div class="col-header">
@@ -67,7 +76,15 @@ func TestOutdentPre(t *testing.T) {
             
-
+

Here's a bunch of HTML, read it and weep, weep then!

<section class="about-user">
                     <div class="col-header">
@@ -112,7 +129,16 @@ func TestOutdentPre(t *testing.T) {
 
 	const expected = template.HTML(`
         
-
+

Here's a bunch of HTML, read it and weep, weep then!

<section class="about-user">
     <div class="col-header">
@@ -154,7 +180,15 @@ func TestOutdentPre(t *testing.T) {
             
-
+

Here's a bunch of HTML, read it and weep, weep then!

<section class="about-user">
     <div class="col-header">
@@ -197,7 +231,7 @@ func TestOutdentPre(t *testing.T) {
         
`) - out := outdentPre(html) + out := outdentPreformatted(html) if out != expected { t.Fatalf("unexpected output:\n`%s`\n", out) } -- cgit v1.2.3