From 794c3b26acbd3931b7973ff7e09a42b0ac414b1c Mon Sep 17 00:00:00 2001 From: Markus Wüstenberg Date: Mon, 16 Nov 2020 12:38:24 +0100 Subject: Render correct HTML5 (#44) Previously, elements of kind void and empty elements generally would be rendered auto-closing (with a final `/` character in the start tag), which is allowed sometimes but arguably wrong. See https://dev.w3.org/html5/spec-LC/syntax.html#end-tags This created problems with for example `textarea` and `script`, which cannot be auto-closing, or the browser renders it wrong. Also clarified in the docs that this library outputs HTML5. Fixes #42.--- README.md | 6 ++-- attr/attributes_test.go | 2 +- attr/boolean_test.go | 2 +- attr/simple_test.go | 2 +- components/documents_test.go | 4 +-- el/elements_test.go | 12 ++++---- el/simple_test.go | 36 ++++++++++++++++-------- gomponents.go | 66 +++++++++++++++++++++++++------------------- gomponents_test.go | 45 ++++++++++++++++++------------ 9 files changed, 103 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 118a1c7..cba1e66 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [](https://godoc.org/github.com/maragudk/gomponents) [](https://codecov.io/gh/maragudk/gomponents) -gomponents are declarative view components in Go, that can render to HTML. -gomponents aims to make it easy to build HTML pages of reusable components, +gomponents are declarative view components in Go, that can render to HTML5. +gomponents aims to make it easy to build HTML5 pages of reusable components, without the use of a template language. Think server-side-rendered React, but without the virtual DOM and diffing. @@ -15,7 +15,7 @@ for background. ## Features -- Write declarative HTML in Go without all the strings, so you get +- Write declarative HTML5 in Go without all the strings, so you get - Type safety - Auto-completion - Nice formatting with `gofmt` diff --git a/attr/attributes_test.go b/attr/attributes_test.go index efb7044..da04a20 100644 --- a/attr/attributes_test.go +++ b/attr/attributes_test.go @@ -20,7 +20,7 @@ func TestClasses(t *testing.T) { t.Run("renders as attribute in an element", func(t *testing.T) { e := g.El("div", attr.Classes{"hat": true}) - assert.Equal(t, `
`, e) + assert.Equal(t, ``, e) }) t.Run("also works with fmt", func(t *testing.T) { diff --git a/attr/boolean_test.go b/attr/boolean_test.go index 4e6bb37..309b025 100644 --- a/attr/boolean_test.go +++ b/attr/boolean_test.go @@ -26,7 +26,7 @@ func TestBooleanAttributes(t *testing.T) { for name, fn := range cases { t.Run(fmt.Sprintf("should output %v", name), func(t *testing.T) { n := g.El("div", fn()) - assert.Equal(t, fmt.Sprintf(``, name), n) + assert.Equal(t, fmt.Sprintf(``, name), n) }) } } diff --git a/attr/simple_test.go b/attr/simple_test.go index eb2cfe3..6181322 100644 --- a/attr/simple_test.go +++ b/attr/simple_test.go @@ -43,7 +43,7 @@ func TestSimpleAttributes(t *testing.T) { for name, fn := range cases { t.Run(fmt.Sprintf(`should output %v="hat"`, name), func(t *testing.T) { n := g.El("div", fn("hat")) - assert.Equal(t, fmt.Sprintf(``, name), n) + assert.Equal(t, fmt.Sprintf(``, name), n) }) } } diff --git a/components/documents_test.go b/components/documents_test.go index 2aabd5a..863ac96 100644 --- a/components/documents_test.go +++ b/components/documents_test.go @@ -20,7 +20,7 @@ func TestHTML5(t *testing.T) { Body: []g.Node{el.Div()}, }) - assert.Equal(t, ``, e) + assert.Equal(t, `