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(want, got []byte) bool
- func ContainsPipe(expr string) bool
- func CountChildren(n *html.Node) int
- func DeepCloneNode(n *html.Node) *html.Node
- func EqualHTML(tb testing.TB, want, got, template, data []byte) bool
- func FilterAttrs(attrs []html.Attribute, excludeKey string) []html.Attribute
- func FormatAttr(val string) string
- 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, first bool) 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 EqualHTML ¶ added in v0.4.0
EqualHTML parses two HTML strings and returns true if their DOMs match. It ignores pure-whitespace text nodes and compares attributes order-insensitively. If DOMs don't match, it logs template and data context for debugging.
func FilterAttrs ¶ added in v0.2.2
FilterAttrs returns a new attribute slice excluding the specified key. This is useful for creating a copy of attributes without a specific key.
func FormatAttr ¶ added in v0.3.0
FormatAttr formats an attribute value by trimming whitespace, replacing newlines with spaces, and reducing repeated spaces to single spaces.
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 reports whether s is a valid ASCII identifier. An identifier must be non-empty, start with a letter (A–Z, a–z) or underscore, and may contain only letters, digits, or underscores thereafter.
func IsIdentifierChar ¶
IsIdentifierChar reports whether ch is valid in an identifier. If first is true, digits are not allowed.
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.