Skip to content

Commit 1d10c80

Browse files
authored
Merge pull request #9 from gochore/dev
2 parents 050d66d + 14ca0a7 commit 1d10c80

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

htmlt/html.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ func (e Html) Render(writer io.Writer, themes ...style.Theme) error {
2626
}
2727

2828
// T return a html element with specified tag
29-
func T(tag string, format string, a ...interface{}) Html {
29+
func T(tag string, format Html, a ...interface{}) Html {
3030
return Sprintf(fmt.Sprintf("<%s>%s</%s>", tag, format, tag), a...)
3131
}
3232

3333
// H return a html element <h>
34-
func H(level int, format string, a ...interface{}) Html {
34+
func H(level int, format Html, a ...interface{}) Html {
3535
if level < 1 {
3636
level = 1
3737
}
@@ -47,22 +47,22 @@ func Hr() Html {
4747
}
4848

4949
// P return a html element <p>
50-
func P(format string, a ...interface{}) Html {
50+
func P(format Html, a ...interface{}) Html {
5151
return T("p", format, a...)
5252
}
5353

5454
// Pre return a html element <pre>
55-
func Pre(format string, a ...interface{}) Html {
55+
func Pre(format Html, a ...interface{}) Html {
5656
return T("pre", format, a...)
5757
}
5858

5959
// A return a html element <a>
60-
func A(href, format string, a ...interface{}) Html {
60+
func A(href string, format Html, a ...interface{}) Html {
6161
return Sprintf(fmt.Sprintf(`<a href="%s">%s</a>`, href, format), a...)
6262
}
6363

6464
// B return a html element <b>
65-
func B(format string, a ...interface{}) Html {
65+
func B(format Html, a ...interface{}) Html {
6666
return T("b", format, a...)
6767
}
6868

@@ -72,41 +72,41 @@ func Br() Html {
7272
}
7373

7474
// Code return a html element <code>
75-
func Code(format string, a ...interface{}) Html {
75+
func Code(format Html, a ...interface{}) Html {
7676
return T("code", format, a...)
7777
}
7878

7979
// Em return a html element <em>
80-
func Em(format string, a ...interface{}) Html {
80+
func Em(format Html, a ...interface{}) Html {
8181
return T("em", format, a...)
8282
}
8383

8484
// I return a html element <i>
85-
func I(format string, a ...interface{}) Html {
85+
func I(format Html, a ...interface{}) Html {
8686
return T("i", format, a...)
8787
}
8888

8989
// Small return a html element <small>
90-
func Small(format string, a ...interface{}) Html {
90+
func Small(format Html, a ...interface{}) Html {
9191
return T("small", format, a...)
9292
}
9393

9494
// Strong return a html element <strong>
95-
func Strong(format string, a ...interface{}) Html {
95+
func Strong(format Html, a ...interface{}) Html {
9696
return T("strong", format, a...)
9797
}
9898

9999
// Img return a html element <img>
100-
func Img(src, alt, format string, a ...interface{}) Html {
100+
func Img(src, alt string, format Html, a ...interface{}) Html {
101101
return Sprintf(fmt.Sprintf(`<a src="%s" alt="%s">%s</a>`, src, alt, format), a...)
102102
}
103103

104104
// Del return a html element <del>
105-
func Del(format string, a ...interface{}) Html {
105+
func Del(format Html, a ...interface{}) Html {
106106
return T("del", format, a...)
107107
}
108108

109109
// Ins return a html element <ins>
110-
func Ins(format string, a ...interface{}) Html {
110+
func Ins(format Html, a ...interface{}) Html {
111111
return T("ins", format, a...)
112112
}

htmlt/html_test.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
func TestT(t *testing.T) {
1515
type args struct {
1616
tag string
17-
format string
17+
format Html
1818
a []interface{}
1919
}
2020
tests := []struct {
@@ -44,7 +44,7 @@ func TestT(t *testing.T) {
4444
func TestH(t *testing.T) {
4545
type args struct {
4646
level int
47-
format string
47+
format Html
4848
a []interface{}
4949
}
5050
tests := []struct {
@@ -110,7 +110,7 @@ func TestHr(t *testing.T) {
110110

111111
func TestP(t *testing.T) {
112112
type args struct {
113-
format string
113+
format Html
114114
a []interface{}
115115
}
116116
tests := []struct {
@@ -138,7 +138,7 @@ func TestP(t *testing.T) {
138138

139139
func TestPre(t *testing.T) {
140140
type args struct {
141-
format string
141+
format Html
142142
a []interface{}
143143
}
144144
tests := []struct {
@@ -167,7 +167,7 @@ func TestPre(t *testing.T) {
167167
func TestA(t *testing.T) {
168168
type args struct {
169169
href string
170-
format string
170+
format Html
171171
a []interface{}
172172
}
173173
tests := []struct {
@@ -196,7 +196,7 @@ func TestA(t *testing.T) {
196196

197197
func TestB(t *testing.T) {
198198
type args struct {
199-
format string
199+
format Html
200200
a []interface{}
201201
}
202202
tests := []struct {
@@ -243,7 +243,7 @@ func TestBr(t *testing.T) {
243243

244244
func TestCode(t *testing.T) {
245245
type args struct {
246-
format string
246+
format Html
247247
a []interface{}
248248
}
249249
tests := []struct {
@@ -271,7 +271,7 @@ func TestCode(t *testing.T) {
271271

272272
func TestDel(t *testing.T) {
273273
type args struct {
274-
format string
274+
format Html
275275
a []interface{}
276276
}
277277
tests := []struct {
@@ -299,7 +299,7 @@ func TestDel(t *testing.T) {
299299

300300
func TestEm(t *testing.T) {
301301
type args struct {
302-
format string
302+
format Html
303303
a []interface{}
304304
}
305305
tests := []struct {
@@ -398,7 +398,7 @@ func TestHtml_Render(t *testing.T) {
398398

399399
func TestI(t *testing.T) {
400400
type args struct {
401-
format string
401+
format Html
402402
a []interface{}
403403
}
404404
tests := []struct {
@@ -428,7 +428,7 @@ func TestImg(t *testing.T) {
428428
type args struct {
429429
src string
430430
alt string
431-
format string
431+
format Html
432432
a []interface{}
433433
}
434434
tests := []struct {
@@ -458,7 +458,7 @@ func TestImg(t *testing.T) {
458458

459459
func TestIns(t *testing.T) {
460460
type args struct {
461-
format string
461+
format Html
462462
a []interface{}
463463
}
464464
tests := []struct {
@@ -486,7 +486,7 @@ func TestIns(t *testing.T) {
486486

487487
func TestSmall(t *testing.T) {
488488
type args struct {
489-
format string
489+
format Html
490490
a []interface{}
491491
}
492492
tests := []struct {
@@ -542,7 +542,7 @@ func TestSprintf(t *testing.T) {
542542

543543
func TestStrong(t *testing.T) {
544544
type args struct {
545-
format string
545+
format Html
546546
a []interface{}
547547
}
548548
tests := []struct {
@@ -567,3 +567,11 @@ func TestStrong(t *testing.T) {
567567
})
568568
}
569569
}
570+
571+
func TestHtml_Str(t *testing.T) {
572+
var want Html = `<a href="/a"><b><code><del><em><h1><i><p>hello</p></i></h1></em></del></code></b></a>`
573+
got := A("/a", B(Code(Del(Em(H(1, I(P("hello"))))))))
574+
if got != want {
575+
t.Errorf("Sprintf() = %v, want %v", got, want)
576+
}
577+
}

0 commit comments

Comments
 (0)