Skip to content

Commit

Permalink
Merge pull request #115 from ahmed-hany94/text-context-elements
Browse files Browse the repository at this point in the history
Add missing text content elements
  • Loading branch information
chasefleming authored Feb 8, 2024
2 parents 864d379 + 2cf9bf3 commit 4fe6ee8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
20 changes: 20 additions & 0 deletions elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,26 @@ func Strong(attrs attrs.Props, children ...Node) *Element {
return newElement("strong", attrs, children...)
}

// Sub creates a <sub> element.
func Sub(attrs attrs.Props, children ...Node) *Element {
return newElement("sub", attrs, children...)
}

// Sup creates a <sub> element.
func Sup(attrs attrs.Props, children ...Node) *Element {
return newElement("sup", attrs, children...)
}

// B creates a <b> element.
func B(attrs attrs.Props, children ...Node) *Element {
return newElement("b", attrs, children...)
}

// U creates a <u> element.
func U(attrs attrs.Props, children ...Node) *Element {
return newElement("u", attrs, children...)
}

// Text creates a TextNode.
func Text(content string) TextNode {
return TextNode(content)
Expand Down
24 changes: 24 additions & 0 deletions elements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ func TestStrong(t *testing.T) {
assert.Equal(t, expected, el.Render())
}

func TestSub(t *testing.T) {
expected := `<sub>2</sub>`
el := Sub(nil, Text("2"))
assert.Equal(t, expected, el.Render())
}

func TestSup(t *testing.T) {
expected := `<sup>2</sup>`
el := Sup(nil, Text("2"))
assert.Equal(t, expected, el.Render())
}

func TestB(t *testing.T) {
expected := `<b>Important text</b>`
el := B(nil, Text("Important text"))
assert.Equal(t, expected, el.Render())
}

func TestU(t *testing.T) {
expected := `<u>Unarticulated text</u>`
el := U(nil, Text("Unarticulated text"))
assert.Equal(t, expected, el.Render())
}

// ========== Comments ==========
func TestComment(t *testing.T) {
expected := `<!-- this is a comment -->`
Expand Down

0 comments on commit 4fe6ee8

Please sign in to comment.