-
Notifications
You must be signed in to change notification settings - Fork 0
/
fragmentnode.go
31 lines (27 loc) · 1 KB
/
fragmentnode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package smetana
// Sometimes we want to combine multiple nodes at the same level of a
// document to treat them as a single unit. In some cases it may be
// acceptable to wrap them in another node such as a "div" or "span"
// but this is often undesirable as it alters the generated markup.
// In these cases, the children nodes can instead be wrapped in a
// [FragmentNode] to treat them as a single entity but without adding
// an extra layer to the generated markup.
type FragmentNode struct {
Children Children
}
// Convert a [FragmentNode] to HTML.
func (node FragmentNode) ToHtml(builder *Builder) {
builder.writeChildren(node.Children)
}
// Create a [FragmentNode] with the given children.
func Fragment(children ...Node) FragmentNode {
return FragmentNode{children}
}
// Append more children to the end of a [FragmentNode].
func (node *FragmentNode) AssignChildren(children Children) {
if len(node.Children) < 1 {
node.Children = children
} else {
node.Children = append(node.Children, children...)
}
}