diff --git a/attrs/attrs.go b/attrs/attrs.go index aae7848..b366b34 100644 --- a/attrs/attrs.go +++ b/attrs/attrs.go @@ -32,6 +32,9 @@ const ( Width = "width" IsMap = "ismap" + // Semantic Text Attributes + DateTime = "datetime" + // Form/Input Attributes Accept = "accept" Action = "action" @@ -57,6 +60,9 @@ const ( Type = "type" Value = "value" + // Interactive Attributes + Open = "open" + // Miscellaneous Attributes DataPrefix = "data-" // Used for custom data attributes e.g., "data-custom" Download = "download" diff --git a/elem.go b/elem.go index 491ea38..72e7248 100644 --- a/elem.go +++ b/elem.go @@ -41,6 +41,7 @@ var booleanAttrs = map[string]struct{}{ attrs.IsMap: {}, attrs.Multiple: {}, attrs.NoValidate: {}, + attrs.Open: {}, attrs.Readonly: {}, attrs.Required: {}, attrs.Selected: {}, diff --git a/elements.go b/elements.go index fd97ddb..27c0826 100644 --- a/elements.go +++ b/elements.go @@ -162,6 +162,8 @@ func Script(props Attrs, children ...Node) *Element { // ========== Semantic Elements ========== +// --- Semantic Sectioning Elements --- + func Article(props Attrs, children ...Node) *Element { return NewElement("article", props, children...) } @@ -190,6 +192,36 @@ func Section(props Attrs, children ...Node) *Element { return NewElement("section", props, children...) } +// --- Semantic Text Content Elements --- + +func Address(props Attrs, children ...Node) *Element { + return NewElement("address", props, children...) +} + +func Details(props Attrs, children ...Node) *Element { + return NewElement("details", props, children...) +} + +func FigCaption(props Attrs, children ...Node) *Element { + return NewElement("figcaption", props, children...) +} + +func Figure(props Attrs, children ...Node) *Element { + return NewElement("figure", props, children...) +} + +func Mark(props Attrs, children ...Node) *Element { + return NewElement("mark", props, children...) +} + +func Summary(props Attrs, children ...Node) *Element { + return NewElement("summary", props, children...) +} + +func Time(props Attrs, children ...Node) *Element { + return NewElement("time", props, children...) +} + // ========== Tables ========== func Table(props Attrs, children ...Node) *Element { diff --git a/elements_test.go b/elements_test.go index d41da69..899498d 100644 --- a/elements_test.go +++ b/elements_test.go @@ -251,6 +251,8 @@ func TestScript(t *testing.T) { // ========== Semantic Elements ========== +// --- Semantic Sectioning Elements --- + func TestArticle(t *testing.T) { expected := `

Article Title

Article content.

` el := Article(nil, H2(nil, Text("Article Title")), P(nil, Text("Article content."))) @@ -293,6 +295,62 @@ func TestSection(t *testing.T) { assert.Equal(t, expected, el.Render()) } +// --- Semantic Text Content Elements --- + +func TestAddress(t *testing.T) { + expected := `
123 Example St.
` + el := Address(nil, Text("123 Example St.")) + assert.Equal(t, expected, el.Render()) +} + +func TestDetails(t *testing.T) { + expected := `
More Info

Details content here.

` + el := Details(nil, Summary(nil, Text("More Info")), P(nil, Text("Details content here."))) + assert.Equal(t, expected, el.Render()) +} + +func TestDetailsWithOpenFalse(t *testing.T) { + expected := `
More Info

Details content here.

` + el := Details(Attrs{attrs.Open: "false"}, Summary(nil, Text("More Info")), P(nil, Text("Details content here."))) + assert.Equal(t, expected, el.Render()) +} + +func TestDetailsWithOpenTrue(t *testing.T) { + expected := `
More Info

Details content here.

` + el := Details(Attrs{attrs.Open: "true"}, Summary(nil, Text("More Info")), P(nil, Text("Details content here."))) + assert.Equal(t, expected, el.Render()) +} + +func TestFigCaption(t *testing.T) { + expected := `
Description of the figure.
` + el := FigCaption(nil, Text("Description of the figure.")) + assert.Equal(t, expected, el.Render()) +} + +func TestFigure(t *testing.T) { + expected := `
An image
An image
` + el := Figure(nil, Img(Attrs{attrs.Src: "image.jpg", attrs.Alt: "An image"}), FigCaption(nil, Text("An image"))) + assert.Equal(t, expected, el.Render()) +} + +func TestMark(t *testing.T) { + expected := `

You must highlight this word.

` + el := P(nil, Text("You must "), Mark(nil, Text("highlight")), Text(" this word.")) + assert.Equal(t, expected, el.Render()) +} + +func TestSummary(t *testing.T) { + expected := `
Summary Title
` + el := Details(nil, Summary(nil, Text("Summary Title"))) + assert.Equal(t, expected, el.Render()) +} + +func TestTime(t *testing.T) { + expected := `` + el := Time(Attrs{attrs.DateTime: "2023-01-01T00:00:00Z"}, Text("New Year's Day")) + assert.Equal(t, expected, el.Render()) +} + // ========== Tables ========== func TestTr(t *testing.T) {