Skip to content

Commit

Permalink
add OmitEndTag setting
Browse files Browse the repository at this point in the history
  • Loading branch information
han2015 committed Dec 31, 2019
1 parent 0a105a7 commit 1b8494e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Body(children ...HTMLComponent) (r *HTMLTagBuilder) {

// "br": HTMLBRElement;
func Br() (r *HTMLTagBuilder) {
return Tag("br")
return Tag("br").OmitEndTag()
}

// "button": HTMLButtonElement;
Expand Down
8 changes: 7 additions & 1 deletion tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type tagAttr struct {

type HTMLTagBuilder struct {
tag string
omitEndTag bool
attrs []*tagAttr
styles []string
classNames []string
Expand All @@ -39,6 +40,11 @@ func (b *HTMLTagBuilder) Tag(v string) (r *HTMLTagBuilder) {
return b
}

func (b *HTMLTagBuilder) OmitEndTag() (r *HTMLTagBuilder) {
b.omitEndTag = true
return b
}

func (b *HTMLTagBuilder) Text(v string) (r *HTMLTagBuilder) {
b.Children(Text(v))
return b
Expand Down Expand Up @@ -327,7 +333,7 @@ func (b *HTMLTagBuilder) MarshalHTML(ctx context.Context) (r []byte, err error)

buf := bytes.NewBuffer(nil)
buf.WriteString(fmt.Sprintf("\n<%s%s>", b.tag, attrStr))
if b.tag != "br" {
if !b.omitEndTag {
if len(cs) > 0 {
// buf.WriteString("\n")
for _, c := range cs {
Expand Down

0 comments on commit 1b8494e

Please sign in to comment.