aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dom/html.go13
-rw-r--r--dom/html_test.go25
-rw-r--r--go.mod4
-rw-r--r--go.sum8
-rw-r--r--markdown/ast_external_test.go4
-rw-r--r--markdown/ast_paragraph_test.go4
-rw-r--r--markdown/ast_test.go8
7 files changed, 31 insertions, 35 deletions
diff --git a/dom/html.go b/dom/html.go
index 3e8117f..7325b70 100644
--- a/dom/html.go
+++ b/dom/html.go
@@ -5,15 +5,12 @@ import (
"html/template"
)
-func render(tag string, attributes map[string]string, endSlash bool) template.HTML {
+func render(tag string, attributes map[string]string) template.HTML {
base := fmt.Sprintf(`<%s`, tag)
for k, v := range attributes {
- base += fmt.Sprintf(` %s="%s"`, k, v)
+ base = fmt.Sprintf(`%s %s="%s"`, base, k, v)
}
- if !endSlash {
- return template.HTML(base + `>`)
- }
- return template.HTML(base + ` />`)
+ return template.HTML(base + `>`)
}
type Element interface {
@@ -58,7 +55,7 @@ type VoidElement struct {
func (e VoidElement) Render() template.HTML {
e.cl.set(e)
- return render(e.Tag, e.attributes, true)
+ return render(e.Tag, e.attributes)
}
func (e VoidElement) HasAttribute(k string) bool {
@@ -95,7 +92,7 @@ type ContentElement struct {
func (e ContentElement) Render() template.HTML {
e.cl.set(e)
- base := render(e.Tag, e.attributes, false)
+ base := render(e.Tag, e.attributes)
for _, el := range e.Contents {
base += el.Render()
}
diff --git a/dom/html_test.go b/dom/html_test.go
index 39f6a1f..0fbd894 100644
--- a/dom/html_test.go
+++ b/dom/html_test.go
@@ -6,19 +6,18 @@ import (
)
func TestRender(t *testing.T) {
- fn := func(tag string, attributes map[string]string, endSlash bool, expected string) func(*testing.T) {
+ fn := func(tag string, attributes map[string]string, expected string) func(*testing.T) {
return func(t *testing.T) {
t.Parallel()
- got := string(render(tag, attributes, endSlash))
+ got := string(render(tag, attributes))
if got != expected {
t.Errorf("invalid value, got %s", got)
}
}
}
t.Run("render", func(t *testing.T) {
- t.Run("simple", fn("p", map[string]string{}, false, "<p>"))
- t.Run("endslash", fn("img", map[string]string{}, true, "<img />"))
- t.Run("attributes", fn("a", map[string]string{"href": "link"}, false, `<a href="link">`))
+ t.Run("simple", fn("p", map[string]string{}, "<p>"))
+ t.Run("attributes", fn("a", map[string]string{"href": "link"}, `<a href="link">`))
})
}
@@ -55,12 +54,12 @@ func TestVoidElement(t *testing.T) {
}
}
t.Run("no_attributes", func(t *testing.T) {
- t.Run("simple1", fn("br", nil, "<br />"))
- t.Run("simple2", fn("img", nil, "<img />"))
+ t.Run("simple1", fn("br", nil, "<br>"))
+ t.Run("simple2", fn("img", nil, "<img>"))
})
t.Run("attributes", func(t *testing.T) {
- t.Run("one", fn("img", map[string]string{"src": "link"}, `<img src="link" />`))
- t.Run("two", fn("img", map[string]string{"src": "link", "alt": "well"}, `<img src="link" alt="well" />`))
+ t.Run("one", fn("img", map[string]string{"src": "link"}, `<img src="link">`))
+ t.Run("two", fn("img", map[string]string{"src": "link", "alt": "well"}, `<img src="link" alt="well">`))
})
}
@@ -87,7 +86,7 @@ func TestContentElement(t *testing.T) {
t.Run("no_attributes", func(t *testing.T) {
t.Run("simple", fnLiteral("p", "", nil, `<p></p>`))
t.Run("literal", fnLiteral("p", "content", nil, `<p>content</p>`))
- t.Run("elements", fn("div", []Element{NewVoidElement("img"), NewVoidElement("br")}, nil, `<div><img /><br /></div>`))
+ t.Run("elements", fn("div", []Element{NewVoidElement("img"), NewVoidElement("br")}, nil, `<div><img><br></div>`))
})
t.Run("attributes", func(t *testing.T) {
t.Run("simple_one", fnLiteral("script", "", map[string]string{"src": "link"}, `<script src="link"></script>`))
@@ -113,8 +112,8 @@ func TestElement_ClassList(t *testing.T) {
}
}
t.Run("add", func(t *testing.T) {
- t.Run("empty", fn(NewVoidElement("img"), `<img />`))
- t.Run("one", fn(NewVoidElement("img"), `<img class="bg" />`, "bg"))
- t.Run("two", fn(NewVoidElement("img"), `<img class="bg large" />`, "bg", "large"))
+ t.Run("empty", fn(NewVoidElement("img"), `<img>`))
+ t.Run("one", fn(NewVoidElement("img"), `<img class="bg">`, "bg"))
+ t.Run("two", fn(NewVoidElement("img"), `<img class="bg large">`, "bg", "large"))
})
}
diff --git a/go.mod b/go.mod
index 57f1eb7..92fbe80 100644
--- a/go.mod
+++ b/go.mod
@@ -3,8 +3,8 @@ module git.anhgelus.world/anhgelus/small-web
go 1.25.1
require (
- github.com/go-chi/chi/v5 v5.2.3
+ github.com/go-chi/chi/v5 v5.2.4
github.com/pelletier/go-toml/v2 v2.2.4
)
-require github.com/mattn/go-sqlite3 v1.14.32
+require github.com/mattn/go-sqlite3 v1.14.33
diff --git a/go.sum b/go.sum
index 988c108..a5ff389 100644
--- a/go.sum
+++ b/go.sum
@@ -1,6 +1,6 @@
-github.com/go-chi/chi/v5 v5.2.3 h1:WQIt9uxdsAbgIYgid+BpYc+liqQZGMHRaUwp0JUcvdE=
-github.com/go-chi/chi/v5 v5.2.3/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
-github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
-github.com/mattn/go-sqlite3 v1.14.32/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
+github.com/go-chi/chi/v5 v5.2.4 h1:WtFKPHwlywe8Srng8j2BhOD9312j9cGUxG1SP4V2cR4=
+github.com/go-chi/chi/v5 v5.2.4/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
+github.com/mattn/go-sqlite3 v1.14.33 h1:A5blZ5ulQo2AtayQ9/limgHEkFreKj1Dv226a1K73s0=
+github.com/mattn/go-sqlite3 v1.14.33/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
diff --git a/markdown/ast_external_test.go b/markdown/ast_external_test.go
index ec9dd29..feec6b2 100644
--- a/markdown/ast_external_test.go
+++ b/markdown/ast_external_test.go
@@ -8,7 +8,7 @@ func TestExternal(t *testing.T) {
t.Run("combo", test("Hey, [link](href)", `<p>Hey, <a href="href">link</a></p>`))
})
t.Run("image", func(t *testing.T) {
- t.Run("simple", test("![image alt](image src)", `<figure><img alt="image alt" src="image src" /></figure>`))
+ t.Run("simple", test("![image alt](image src)", `<figure><img alt="image alt" src="image src"></figure>`))
t.Run("combo", test(`
Avant la source
![image alt](image src)
@@ -16,6 +16,6 @@ source 1
source 2
Hors de la source
-`, `<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>`))
+`, `<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>`))
})
}
diff --git a/markdown/ast_paragraph_test.go b/markdown/ast_paragraph_test.go
index c18dfc7..91e41f4 100644
--- a/markdown/ast_paragraph_test.go
+++ b/markdown/ast_paragraph_test.go
@@ -15,10 +15,10 @@ func TestParagraph(t *testing.T) {
opt := &Option{Poem: true}
t.Run("simple", testWithOptions(opt, "bonsoir", `<p>bonsoir</p>`))
t.Run("one_break", testWithOptions(opt, `bonsoir
-world`, `<p>bonsoir<br />world</p>`))
+world`, `<p>bonsoir<br>world</p>`))
t.Run("mult_break", testWithOptions(opt, `bonsoir
world
-new line`, `<p>bonsoir<br />world</p><p>new line</p>`))
+new line`, `<p>bonsoir<br>world</p><p>new line</p>`))
})
}
diff --git a/markdown/ast_test.go b/markdown/ast_test.go
index 5e5a4f9..034eeb8 100644
--- a/markdown/ast_test.go
+++ b/markdown/ast_test.go
@@ -40,22 +40,22 @@ var parsed = `
<ol><li>et maintenant</li><li>elle l&#39;est</li></ol>
<ul><li>hehe</li></ul>
<figure>
-<img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg" />
+<img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg">
<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>
</figure>
`
var parsedPoem = `
<h1>Je suis un titre</h1>
-<p>Avec une description classique,<br />sur plusieurs lignes !</p>
-<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>
+<p>Avec une description classique,<br>sur plusieurs lignes !</p>
+<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>
<div class="quote"><blockquote>Je suis une magnifique citation sur plusieurs lignes</blockquote><p>avec une source</p></div>
<div class="quote"><blockquote>qui recommence après !</blockquote><p>qui a elle aussi une source :D</p></div>
<ul><li>Ceci est une liste</li><li>pas ordonnée</li></ul>
<ol><li>et maintenant</li><li>elle l&#39;est</li></ol>
<ul><li>hehe</li></ul>
<figure>
-<img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg" />
+<img alt="Ceci est ma pfp :3" src="https://cdn.anhgelus.world/pfp.jpg">
<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>
</figure>
`