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.--- el/elements_test.go | 12 ++++++------ el/simple_test.go | 36 ++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 18 deletions(-) (limited to 'el') diff --git a/el/elements_test.go b/el/elements_test.go index e90be9f..adce6df 100644 --- a/el/elements_test.go +++ b/el/elements_test.go @@ -17,7 +17,7 @@ func (w *erroringWriter) Write(p []byte) (n int, err error) { func TestDocument(t *testing.T) { t.Run("returns doctype and children", func(t *testing.T) { - assert.Equal(t, `
`, el.Document(g.El("html"))) + assert.Equal(t, ``, el.Document(g.El("html"))) }) t.Run("errors on write error in Render", func(t *testing.T) { @@ -28,13 +28,13 @@ func TestDocument(t *testing.T) { func TestForm(t *testing.T) { t.Run("returns a form element with action and method attributes", func(t *testing.T) { - assert.Equal(t, ``, el.Form("/", "post")) + assert.Equal(t, ``, el.Form("/", "post")) }) } func TestInput(t *testing.T) { t.Run("returns an input element with attributes type and name", func(t *testing.T) { - assert.Equal(t, ``, el.Input("text", "hat")) + assert.Equal(t, ``, el.Input("text", "hat")) }) } @@ -52,7 +52,7 @@ func TestOption(t *testing.T) { func TestProgress(t *testing.T) { t.Run("returns a progress element with attributes value and max", func(t *testing.T) { - assert.Equal(t, ``, el.Progress(5.5, 10)) + assert.Equal(t, ``, el.Progress(5.5, 10)) }) } @@ -65,7 +65,7 @@ func TestSelect(t *testing.T) { func TestTextarea(t *testing.T) { t.Run("returns a textarea element with attribute name", func(t *testing.T) { - assert.Equal(t, ``, el.Textarea("hat")) + assert.Equal(t, ``, el.Textarea("hat")) }) } @@ -77,6 +77,6 @@ func TestA(t *testing.T) { func TestImg(t *testing.T) { t.Run("returns an img element with href and alt attributes", func(t *testing.T) { - assert.Equal(t, `