Skip to content

Commit 35989dc

Browse files
committed
Add Additional Text Formatting and Structure Elements
1 parent eb0260b commit 35989dc

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,27 @@ In this example, if `isAdmin` is `true`, the `Admin Panel` link is rendered. Oth
9191
`elem` provides utility functions for creating common HTML elements:
9292

9393
- `A`: Anchor `<a>`
94+
- `Blockquote`: Blockquote `<blockquote>`
9495
- `Body`: Body `<body>`
96+
- `Br`: Break `<br>`
9597
- `Button`: Button `<button>`
98+
- `Code`: Code `<code>`
9699
- `Div`: Division `<div>`
100+
- `Em`: Emphasis `<em>`
97101
- `H1`: Heading 1 `<h1>`
98102
- `H2`: Heading 2 `<h2>`
99103
- `H3`: Heading 3 `<h3>`
100104
- `Head`: Head `<head>`
101105
- `Html`: HTML `<html>`
106+
- `Hr`: Horizontal Rule `<hr>`
102107
- `Img`: Image `<img>`
103108
- `Li`: List Item `<li>`
104109
- `Meta`: Meta `<meta>`
105110
- `P`: Paragraph `<p>`
111+
- `Pre`: Preformatted Text `<pre>`
106112
- `Script`: Script `<script>`
107113
- `Span`: Span `<span>`
114+
- `Strong`: Strong `<strong>`
108115
- `Title`: Title `<title>`
109116
- `Ul`: Unordered List `<ul>`
110117

elements.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,26 @@ func A(props Attrs, children ...interface{}) *Element {
2424
return NewElement("a", props, children...)
2525
}
2626

27+
func Br(props Attrs) *Element {
28+
return NewElement("br", props)
29+
}
30+
31+
func Blockquote(props Attrs, children ...interface{}) *Element {
32+
return NewElement("blockquote", props, children...)
33+
}
34+
35+
func Code(props Attrs, children ...interface{}) *Element {
36+
return NewElement("code", props, children...)
37+
}
38+
2739
func Div(props Attrs, children ...interface{}) *Element {
2840
return NewElement("div", props, children...)
2941
}
3042

43+
func Em(props Attrs, children ...interface{}) *Element {
44+
return NewElement("em", props, children...)
45+
}
46+
3147
func H1(props Attrs, children ...interface{}) *Element {
3248
return NewElement("h1", props, children...)
3349
}
@@ -40,14 +56,26 @@ func H3(props Attrs, children ...interface{}) *Element {
4056
return NewElement("h3", props, children...)
4157
}
4258

59+
func Hr(props Attrs) *Element {
60+
return NewElement("hr", props)
61+
}
62+
4363
func P(props Attrs, children ...interface{}) *Element {
4464
return NewElement("p", props, children...)
4565
}
4666

67+
func Pre(props Attrs, children ...interface{}) *Element {
68+
return NewElement("pre", props, children...)
69+
}
70+
4771
func Span(props Attrs, children ...interface{}) *Element {
4872
return NewElement("span", props, children...)
4973
}
5074

75+
func Strong(props Attrs, children ...interface{}) *Element {
76+
return NewElement("strong", props, children...)
77+
}
78+
5179
func Text(content string) string {
5280
return content
5381
}

elements_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,36 @@ func TestA(t *testing.T) {
3838
assert.Equal(t, expected, el.Render())
3939
}
4040

41+
func TestBlockquote(t *testing.T) {
42+
expected := `<blockquote>Quote text</blockquote>`
43+
el := Blockquote(nil, Text("Quote text"))
44+
assert.Equal(t, expected, el.Render())
45+
}
46+
47+
func TestBr(t *testing.T) {
48+
expected := `<br>`
49+
el := Br(nil)
50+
assert.Equal(t, expected, el.Render())
51+
}
52+
53+
func TestCode(t *testing.T) {
54+
expected := `<code>Code snippet</code>`
55+
el := Code(nil, Text("Code snippet"))
56+
assert.Equal(t, expected, el.Render())
57+
}
58+
4159
func TestDiv(t *testing.T) {
4260
expected := `<div class="container">Hello, Elem!</div>`
4361
el := Div(Attrs{attrs.Class: "container"}, Text("Hello, Elem!"))
4462
assert.Equal(t, expected, el.Render())
4563
}
4664

65+
func TestEm(t *testing.T) {
66+
expected := `<em>Italic text</em>`
67+
el := Em(nil, Text("Italic text"))
68+
assert.Equal(t, expected, el.Render())
69+
}
70+
4771
func TestH1(t *testing.T) {
4872
expected := `<h1 class="title">Hello, Elem!</h1>`
4973
el := H1(Attrs{attrs.Class: "title"}, Text("Hello, Elem!"))
@@ -62,18 +86,36 @@ func TestH3(t *testing.T) {
6286
assert.Equal(t, expected, el.Render())
6387
}
6488

89+
func TestHr(t *testing.T) {
90+
expected := `<hr>`
91+
el := Hr(nil)
92+
assert.Equal(t, expected, el.Render())
93+
}
94+
6595
func TestP(t *testing.T) {
6696
expected := `<p>Hello, Elem!</p>`
6797
el := P(nil, Text("Hello, Elem!"))
6898
assert.Equal(t, expected, el.Render())
6999
}
70100

101+
func TestPre(t *testing.T) {
102+
expected := `<pre>Preformatted text</pre>`
103+
el := Pre(nil, Text("Preformatted text"))
104+
assert.Equal(t, expected, el.Render())
105+
}
106+
71107
func TestSpan(t *testing.T) {
72108
expected := `<span class="highlight">Hello, Elem!</span>`
73109
el := Span(Attrs{attrs.Class: "highlight"}, Text("Hello, Elem!"))
74110
assert.Equal(t, expected, el.Render())
75111
}
76112

113+
func TestStrong(t *testing.T) {
114+
expected := `<strong>Bold text</strong>`
115+
el := Strong(nil, Text("Bold text"))
116+
assert.Equal(t, expected, el.Render())
117+
}
118+
77119
// ========== Lists ==========
78120

79121
func TestLi(t *testing.T) {

0 commit comments

Comments
 (0)