Welcome to anhgelus's logs. anhgelus.world
standard-site go markdown indie brutalist small-web atproto
1

Configure Feed

Select the types of activity you want to include in your feed.

fix(dom): remove trailing slash for void element

was never required for html

+31 -35
+5 -8
dom/html.go
··· 5 5 "html/template" 6 6 ) 7 7 8 - func render(tag string, attributes map[string]string, endSlash bool) template.HTML { 8 + func render(tag string, attributes map[string]string) template.HTML { 9 9 base := fmt.Sprintf(`<%s`, tag) 10 10 for k, v := range attributes { 11 - base += fmt.Sprintf(` %s="%s"`, k, v) 11 + base = fmt.Sprintf(`%s %s="%s"`, base, k, v) 12 12 } 13 - if !endSlash { 14 - return template.HTML(base + `>`) 15 - } 16 - return template.HTML(base + ` />`) 13 + return template.HTML(base + `>`) 17 14 } 18 15 19 16 type Element interface { ··· 58 55 59 56 func (e VoidElement) Render() template.HTML { 60 57 e.cl.set(e) 61 - return render(e.Tag, e.attributes, true) 58 + return render(e.Tag, e.attributes) 62 59 } 63 60 64 61 func (e VoidElement) HasAttribute(k string) bool { ··· 95 92 96 93 func (e ContentElement) Render() template.HTML { 97 94 e.cl.set(e) 98 - base := render(e.Tag, e.attributes, false) 95 + base := render(e.Tag, e.attributes) 99 96 for _, el := range e.Contents { 100 97 base += el.Render() 101 98 }
+12 -13
dom/html_test.go
··· 6 6 ) 7 7 8 8 func TestRender(t *testing.T) { 9 - fn := func(tag string, attributes map[string]string, endSlash bool, expected string) func(*testing.T) { 9 + fn := func(tag string, attributes map[string]string, expected string) func(*testing.T) { 10 10 return func(t *testing.T) { 11 11 t.Parallel() 12 - got := string(render(tag, attributes, endSlash)) 12 + got := string(render(tag, attributes)) 13 13 if got != expected { 14 14 t.Errorf("invalid value, got %s", got) 15 15 } 16 16 } 17 17 } 18 18 t.Run("render", func(t *testing.T) { 19 - t.Run("simple", fn("p", map[string]string{}, false, "<p>")) 20 - t.Run("endslash", fn("img", map[string]string{}, true, "<img />")) 21 - t.Run("attributes", fn("a", map[string]string{"href": "link"}, false, `<a href="link">`)) 19 + t.Run("simple", fn("p", map[string]string{}, "<p>")) 20 + t.Run("attributes", fn("a", map[string]string{"href": "link"}, `<a href="link">`)) 22 21 }) 23 22 } 24 23 ··· 55 54 } 56 55 } 57 56 t.Run("no_attributes", func(t *testing.T) { 58 - t.Run("simple1", fn("br", nil, "<br />")) 59 - t.Run("simple2", fn("img", nil, "<img />")) 57 + t.Run("simple1", fn("br", nil, "<br>")) 58 + t.Run("simple2", fn("img", nil, "<img>")) 60 59 }) 61 60 t.Run("attributes", func(t *testing.T) { 62 - t.Run("one", fn("img", map[string]string{"src": "link"}, `<img src="link" />`)) 63 - t.Run("two", fn("img", map[string]string{"src": "link", "alt": "well"}, `<img src="link" alt="well" />`)) 61 + t.Run("one", fn("img", map[string]string{"src": "link"}, `<img src="link">`)) 62 + t.Run("two", fn("img", map[string]string{"src": "link", "alt": "well"}, `<img src="link" alt="well">`)) 64 63 }) 65 64 } 66 65 ··· 87 86 t.Run("no_attributes", func(t *testing.T) { 88 87 t.Run("simple", fnLiteral("p", "", nil, `<p></p>`)) 89 88 t.Run("literal", fnLiteral("p", "content", nil, `<p>content</p>`)) 90 - t.Run("elements", fn("div", []Element{NewVoidElement("img"), NewVoidElement("br")}, nil, `<div><img /><br /></div>`)) 89 + t.Run("elements", fn("div", []Element{NewVoidElement("img"), NewVoidElement("br")}, nil, `<div><img><br></div>`)) 91 90 }) 92 91 t.Run("attributes", func(t *testing.T) { 93 92 t.Run("simple_one", fnLiteral("script", "", map[string]string{"src": "link"}, `<script src="link"></script>`)) ··· 113 112 } 114 113 } 115 114 t.Run("add", func(t *testing.T) { 116 - t.Run("empty", fn(NewVoidElement("img"), `<img />`)) 117 - t.Run("one", fn(NewVoidElement("img"), `<img class="bg" />`, "bg")) 118 - t.Run("two", fn(NewVoidElement("img"), `<img class="bg large" />`, "bg", "large")) 115 + t.Run("empty", fn(NewVoidElement("img"), `<img>`)) 116 + t.Run("one", fn(NewVoidElement("img"), `<img class="bg">`, "bg")) 117 + t.Run("two", fn(NewVoidElement("img"), `<img class="bg large">`, "bg", "large")) 119 118 }) 120 119 }
+2 -2
go.mod
··· 3 3 go 1.25.1 4 4 5 5 require ( 6 - github.com/go-chi/chi/v5 v5.2.3 6 + github.com/go-chi/chi/v5 v5.2.4 7 7 github.com/pelletier/go-toml/v2 v2.2.4 8 8 ) 9 9 10 - require github.com/mattn/go-sqlite3 v1.14.32 10 + require github.com/mattn/go-sqlite3 v1.14.33
+4 -4
go.sum
··· 1 - github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE= 2 - github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops= 3 - github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs= 4 - github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= 1 + github.com/go-chi/chi/v5 v5.2.4 h1:WtFKPHwlywe8Srng8j2BhOD9312j9cGUxG1SP4V2cR4= 2 + github.com/go-chi/chi/v5 v5.2.4/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0= 3 + github.com/mattn/go-sqlite3 v1.14.33 h1:A5blZ5ulQo2AtayQ9/limgHEkFreKj1Dv226a1K73s0= 4 + github.com/mattn/go-sqlite3 v1.14.33/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= 5 5 github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= 6 6 github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
+2 -2
markdown/ast_external_test.go
··· 8 8 t.Run("combo", test("Hey, [link](href)", `<p>Hey, <a href="href">link</a></p>`)) 9 9 }) 10 10 t.Run("image", func(t *testing.T) { 11 - t.Run("simple", test("![image alt](image src)", `<figure><img alt="image alt" src="image src" /></figure>`)) 11 + t.Run("simple", test("![image alt](image src)", `<figure><img alt="image alt" src="image src"></figure>`)) 12 12 t.Run("combo", test(` 13 13 Avant la source 14 14 ![image alt](image src) ··· 16 16 source 2 17 17 18 18 Hors de la source 19 - `, `<p>Avant la source</p><figure><img alt="image alt" src="image src" /><figcaption>source 1 source 2</figcaption></figure><p>Hors de la source</p>`)) 19 + `, `<p>Avant la source</p><figure><img alt="image alt" src="image src"><figcaption>source 1 source 2</figcaption></figure><p>Hors de la source</p>`)) 20 20 }) 21 21 }
+2 -2
markdown/ast_paragraph_test.go
··· 15 15 opt := &Option{Poem: true} 16 16 t.Run("simple", testWithOptions(opt, "bonsoir", `<p>bonsoir</p>`)) 17 17 t.Run("one_break", testWithOptions(opt, `bonsoir 18 - world`, `<p>bonsoir<br />world</p>`)) 18 + world`, `<p>bonsoir<br>world</p>`)) 19 19 t.Run("mult_break", testWithOptions(opt, `bonsoir 20 20 world 21 21 22 - new line`, `<p>bonsoir<br />world</p><p>new line</p>`)) 22 + new line`, `<p>bonsoir<br>world</p><p>new line</p>`)) 23 23 }) 24 24 }
+4 -4
markdown/ast_test.go
··· 40 40 <ol><li>et maintenant</li><li>elle l&#39;est</li></ol> 41 41 <ul><li>hehe</li></ul> 42 42 <figure> 43 - <img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg" /> 43 + <img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg"> 44 44 <figcaption><a href="https://now.anhgelus.world/" target="_blank" rel="noreferer">Ma pfp</a> hehe :D Elle est <b>magnifique</b>, n&#39;est-ce pas ?</figcaption> 45 45 </figure> 46 46 ` 47 47 48 48 var parsedPoem = ` 49 49 <h1>Je suis un titre</h1> 50 - <p>Avec une description classique,<br />sur plusieurs lignes !</p> 51 - <p>Et je peux mettre du texte en <b>gras</b>,<br />en <em>italique</em> et les <b><em>deux en même temps</em></b> !</p> 50 + <p>Avec une description classique,<br>sur plusieurs lignes !</p> 51 + <p>Et je peux mettre du texte en <b>gras</b>,<br>en <em>italique</em> et les <b><em>deux en même temps</em></b> !</p> 52 52 <div class="quote"><blockquote>Je suis une magnifique citation sur plusieurs lignes</blockquote><p>avec une source</p></div> 53 53 <div class="quote"><blockquote>qui recommence après !</blockquote><p>qui a elle aussi une source :D</p></div> 54 54 <ul><li>Ceci est une liste</li><li>pas ordonnée</li></ul> 55 55 <ol><li>et maintenant</li><li>elle l&#39;est</li></ol> 56 56 <ul><li>hehe</li></ul> 57 57 <figure> 58 - <img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg" /> 58 + <img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg"> 59 59 <figcaption><a href="https://now.anhgelus.world/" target="_blank" rel="noreferer">Ma pfp</a> hehe :D Elle est <b>magnifique</b>, n&#39;est-ce pas ?</figcaption> 60 60 </figure> 61 61 `