Skip to content

Commit f55b25e

Browse files
committed
fix self-closing tags
1 parent 1fb1d15 commit f55b25e

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

compiler/nodes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,14 @@ func (n *ElementNode) Source(tw *templateWriter) error {
512512
return err
513513
}
514514
// close the tag
515+
if n.isSelfClosing {
516+
// add a "/" to the end of the tag as long as it's not in the list of tags that shouldn't get it
517+
if !slices.Contains(selfClosedTags, strings.ToLower(n.tag)) {
518+
if _, err := tw.WriteStringLiteral("/"); err != nil {
519+
return err
520+
}
521+
}
522+
}
515523
if _, err := tw.WriteStringLiteral(">"); err != nil {
516524
return err
517525
}

examples/tags/selfclosing.goht

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ package tags
2424
@slim SlimSelfClosing() {
2525
img{src: "logo.png", alt: "logo"}
2626
p
27-
A paragraph is not self closing.
27+
|A paragraph is not self closing.
2828
img{src: "logo.png", alt: "logo"}
2929
}
3030

examples/tags/selfclosing.goht.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<isNowSelfClosing>
1+
<isNowSelfClosing/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<isNowSelfClosing>
1+
<isNowSelfClosing/>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<img src="logo.png" alt="logo"><p>
2-
<A>paragraph is not self closing.</A>
2+
A paragraph is not self closing.
33
<img src="logo.png" alt="logo"></p>

0 commit comments

Comments
 (0)