Documentation
¶
Overview ¶
Package helpers provides HTML node manipulation utilities for vuego.
Index ¶
- func AppendAttr(n *html.Node, key, value string)
- func CloneNode(n *html.Node) *html.Node
- func CompareHTML(tb testing.TB, want, got, template, data []byte) bool
- func ContainsPipe(expr string) bool
- func CountChildren(n *html.Node) int
- func DeepCloneNode(n *html.Node) *html.Node
- func GetAttr(n *html.Node, key string) string
- func GetBodyNode() *html.Node
- func HasAttr(n *html.Node, key string) bool
- func IsComplexExpr(expr string) bool
- func IsFunctionCall(expr string) bool
- func IsIdentifier(s string) bool
- func IsIdentifierChar(ch rune) bool
- func IsTruthy(val any) bool
- func NeedsHTMLEscape(s string) bool
- func NewNode() *html.Node
- func NormalizeComparisonOperators(expr string) string
- func RemoveAttr(n *html.Node, key string)
- func SetAttr(n *html.Node, key, value string)
- func ShallowCloneWithAttrs(n *html.Node) *html.Node
- func SignificantChildren(root *html.Node) []*html.Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendAttr ¶
AppendAttr appends a value to an attribute on a node. If the attribute exists, the new value replaces it. If it doesn't exist, it is added.
func CloneNode ¶
CloneNode creates a shallow copy of a node without sharing children or siblings. Attributes are shared (not copied) to avoid unnecessary allocations.
func CompareHTML ¶
CompareHTML parses two HTML strings and returns true if their DOMs match. It ignores pure-whitespace text nodes and compares attributes order-insensitively.
func ContainsPipe ¶
ContainsPipe checks if an expression contains a pipe operator.
func CountChildren ¶
CountChildren counts the number of child nodes of the given node. This is useful for preallocating slices with the correct capacity.
func DeepCloneNode ¶
DeepCloneNode creates a deep copy of a node including all children.
func GetBodyNode ¶
GetBodyNode returns a cached body element suitable for html.ParseFragment.
func IsComplexExpr ¶
IsComplexExpr checks if an expression contains operators like ==, ===, !=, <, >, etc.
func IsFunctionCall ¶
IsFunctionCall checks if an expression looks like a function call.
func IsIdentifier ¶
IsIdentifier checks if a string is a valid identifier (starts with letter or underscore, followed by letters, digits, or underscores).
func IsIdentifierChar ¶
IsIdentifierChar checks if a rune is valid in an identifier (letter, digit, or underscore).
func IsTruthy ¶
IsTruthy converts a value to boolean following Vue semantics. For bound attributes, false values should not render the attribute.
func NeedsHTMLEscape ¶
NeedsHTMLEscape checks if a string contains characters that need HTML escaping. Returns true if the string contains &, <, >, ", or ' characters. This avoids calling html.EscapeString which always allocates a new string.
func NewNode ¶
NewNode creates or reuses a node from the pool, clearing any previous state. This reduces memory allocations and GC pressure during template rendering.
func NormalizeComparisonOperators ¶
NormalizeComparisonOperators coalesces strict comparison operators (=== and !==) to loose operators (== and !=). This is needed because the underlying expr evaluator supports == and != but not === and !==.
func RemoveAttr ¶
RemoveAttr removes an attribute from a node by key.
func SetAttr ¶
SetAttr sets or updates an attribute on a node. If the attribute exists, its value is replaced. If it doesn't exist, it is added.
func ShallowCloneWithAttrs ¶
ShallowCloneWithAttrs creates a shallow copy of a node and copies its attributes. This is useful when you need a new node with the same attributes but will replace its children.
Types ¶
This section is empty.