Skip to content

Commit

Permalink
Merge pull request #8 from WindowsSov8forUs/master
Browse files Browse the repository at this point in the history
add: 添加扩展元素、子元素与扩展属性动态设置方法
  • Loading branch information
WindowsSov8forUs authored Jun 19, 2024
2 parents 1c41123 + 5de5949 commit f73318c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/message/message_element.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (e *ChildrenMessageElement) GetChildren() []MessageElement {
return e.children
}

func (e *ChildrenMessageElement) SetChildren(children []MessageElement) *ChildrenMessageElement {
e.children = children
return e
}

type ExtendAttributes struct {
attributes map[string]string
}
Expand All @@ -72,6 +77,14 @@ func (e *ExtendAttributes) AddAttribute(key, value string) *ExtendAttributes {
return result
}

func (e *ExtendAttributes) DelAttribute(key string) *ExtendAttributes {
if e == nil {
return nil
}
delete(e.attributes, key)
return e
}

func (e *ExtendAttributes) Get(key string) (string, bool) {
if e == nil {
return "", false
Expand Down
2 changes: 1 addition & 1 deletion pkg/message/message_element_extend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (e *MessageElementExtend) Parse(n *html.Node) (MessageElement, error) {
return result, nil
}

func NewMessageElementExtend(tag string, attrs map[string]string, children ...MessageElement) MessageElement {
func NewMessageElementExtend(tag string, attrs map[string]string, children ...MessageElement) *MessageElementExtend {
result := &MessageElementExtend{
tag: tag,
}
Expand Down

0 comments on commit f73318c

Please sign in to comment.