From 661656ac820d59c248fd774f17c18196f1f8989d Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Sun, 3 Mar 2024 14:11:23 -0800 Subject: [PATCH 1/2] Add <base> element --- elements.go | 7 ++++++- elements_test.go | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/elements.go b/elements.go index cfd255c..d37dc40 100644 --- a/elements.go +++ b/elements.go @@ -234,7 +234,12 @@ func Img(attrs attrs.Props) *Element { return newElement("img", attrs) } -// ========== Meta Elements ========== +// ========== Head Elements ========== + +// Base creates a <base> element. +func Base(attrs attrs.Props) *Element { + return newElement("base", attrs) +} // Link creates a <link> element. func Link(attrs attrs.Props) *Element { diff --git a/elements_test.go b/elements_test.go index 6a34c1b..98bf2ca 100644 --- a/elements_test.go +++ b/elements_test.go @@ -298,7 +298,13 @@ func TestImg(t *testing.T) { assert.Equal(t, expected, el.Render()) } -// ========== Meta Elements ========== +// ========== Head Elements ========== + +func TestBase(t *testing.T) { + expected := `<base href="https://example.com">` + el := Base(attrs.Props{attrs.Href: "https://example.com"}) + assert.Equal(t, expected, el.Render()) +} func TestLink(t *testing.T) { expected := `<link href="https://example.com/styles.css" rel="stylesheet">` From 4a383492a57e84084c1b7979c3f792f5a936d614 Mon Sep 17 00:00:00 2001 From: Chase Fleming <1666730+chasefleming@users.noreply.github.com> Date: Sun, 3 Mar 2024 14:21:55 -0800 Subject: [PATCH 2/2] Add `Base` to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 48e945a..05bbe53 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Additionally, `None` can be used to create an empty element, as in `elem.Div(nil `elem` provides utility functions for creating HTML elements: -- **Document Structure**: `Html`, `Head`, `Body`, `Title`, `Link`, `Meta`, `Style` +- **Document Structure**: `Html`, `Head`, `Body`, `Title`, `Link`, `Meta`, `Style`, `Base` - **Text Content**: `H1`, `H2`, `H3`, `H4`, `H5`, `H6`, `P`, `Blockquote`, `Pre`, `Code`, `I`, `Br`, `Hr`, `Small`, `Q`, `Cite`, `Abbr`, `Data`, `Time`, `Var`, `Samp`, `Kbd` - **Sectioning & Semantic Layout**: `Article`, `Aside`, `FigCaption`, `Figure`, `Footer`, `Header`, `Hgroup`, `Main`, `Mark`, `Nav`, `Section` - **Form Elements**: `Form`, `Input`, `Textarea`, `Button`, `Select`, `Optgroup`, `Option`, `Label`, `Fieldset`, `Legend`, `Datalist`, `Meter`, `Output`, `Progress`