Documentation
¶
Overview ¶
Package dom provides virtual DOM structures and operations for HTML parsing and manipulation.
Package dom provides virtual DOM structures and operations for HTML parsing and manipulation.
Index ¶
- func GetAttribute(element *VElement, name string) string
- func GetInnerText(node VNode, normalizeSpaces bool) string
- func GetLinkDensity(element *VElement) float64
- func GetTextDensity(element *VElement) float64
- func HasAncestorTag(node VNode, tagName string, maxDepth int) bool
- func IsProbablyVisible(node *VElement) bool
- func IsVElement(node VNode) bool
- func IsVText(node VNode) bool
- type ReadabilityData
- type VDocument
- type VElement
- func AsVElement(node VNode) (*VElement, bool)
- func CreateElement(tagName string) *VElement
- func GetElementsByTagName(element *VElement, tagName string) []*VElement
- func GetElementsByTagNames(element *VElement, tagNames []string) []*VElement
- func GetNodeAncestors(node *VElement, maxDepth int) []*VElement
- func NewVElement(tagName string) *VElement
- func (e *VElement) AppendChild(child VNode)
- func (e *VElement) ClassName() string
- func (e *VElement) GetAttribute(name string) string
- func (n *VElement) GetReadabilityData() *ReadabilityData
- func (e *VElement) HasAttribute(name string) bool
- func (e *VElement) ID() string
- func (n *VElement) Parent() *VElement
- func (e *VElement) SetAttribute(name, value string)
- func (n *VElement) SetParent(parent *VElement)
- func (n *VElement) SetReadabilityData(data *ReadabilityData)
- func (n *VElement) Type() VNodeType
- type VNode
- type VNodeType
- type VText
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAttribute ¶
GetAttribute gets the value of an attribute on an element. Returns an empty string if the attribute doesn't exist.
func GetInnerText ¶
GetInnerText returns the inner text of an element or text node. If normalizeSpaces is true, consecutive whitespace is normalized to a single space.
func GetLinkDensity ¶
GetLinkDensity calculates the ratio of link text to all text in an element. Returns a value between 0 and 1, where higher values indicate more links.
func GetTextDensity ¶
GetTextDensity calculates the ratio of text to child elements in an element. Returns a value where higher values indicate more text-dense content.
func HasAncestorTag ¶
HasAncestorTag checks if a node has an ancestor with the specified tag name. If maxDepth is less than or equal to 0, all ancestors are checked.
func IsProbablyVisible ¶
IsProbablyVisible checks if an element is likely to be visible based on its attributes.
Types ¶
type ReadabilityData ¶
type ReadabilityData struct {
ContentScore float64
}
ReadabilityData stores readability-specific information for a node.
type VDocument ¶
type VDocument struct {
DocumentElement *VElement
Body *VElement
BaseURI string
DocumentURI string
}
VDocument represents a virtual DOM document.
func NewVDocument ¶
NewVDocument creates a new virtual DOM document with the given document element and body.
type VElement ¶
type VElement struct {
TagName string
Attributes map[string]string
Children []VNode
// contains filtered or unexported fields
}
VElement represents an element node in the virtual DOM.
func AsVElement ¶
AsVElement attempts to convert a VNode to a VElement. Returns the VElement and true if successful, otherwise nil and false.
func CreateElement ¶
CreateElement creates a new element with the given tag name.
func GetElementsByTagName ¶
GetElementsByTagName returns all elements with the specified tag name(s) in the element tree. If tagName is "*", it returns all elements.
func GetElementsByTagNames ¶
GetElementsByTagNames returns all elements with any of the specified tag names in the element tree.
func GetNodeAncestors ¶
GetNodeAncestors returns the ancestor elements of a node up to a specified depth. If maxDepth is less than or equal to 0, all ancestors are returned.
func NewVElement ¶
NewVElement creates a new element node with the given tag name.
func (*VElement) AppendChild ¶
AppendChild adds a child node to this element.
func (*VElement) ClassName ¶
ClassName returns the class attribute of this element, or an empty string if it has no class.
func (*VElement) GetAttribute ¶
GetAttribute gets the value of an attribute on this element.
func (*VElement) GetReadabilityData ¶
func (n *VElement) GetReadabilityData() *ReadabilityData
GetReadabilityData returns the readability-specific data for this node.
func (*VElement) HasAttribute ¶
HasAttribute checks if this element has the specified attribute.
func (*VElement) ID ¶
ID returns the id attribute of this element, or an empty string if it has no id.
func (*VElement) Parent ¶
func (n *VElement) Parent() *VElement
Parent returns the parent element of this node.
func (*VElement) SetAttribute ¶
SetAttribute sets an attribute on this element.
func (*VElement) SetParent ¶
func (n *VElement) SetParent(parent *VElement)
SetParent sets the parent element of this node.
func (*VElement) SetReadabilityData ¶
func (n *VElement) SetReadabilityData(data *ReadabilityData)
SetReadabilityData sets the readability-specific data for this node.
type VNode ¶
type VNode interface {
// Type returns the node type.
Type() VNodeType
// Parent returns the parent element of this node, or nil if it has no parent.
Parent() *VElement
// SetParent sets the parent element of this node.
SetParent(parent *VElement)
// GetReadabilityData returns the readability-specific data for this node.
GetReadabilityData() *ReadabilityData
// SetReadabilityData sets the readability-specific data for this node.
SetReadabilityData(data *ReadabilityData)
}
VNode is the interface for all virtual DOM nodes.
type VText ¶
type VText struct {
TextContent string
// contains filtered or unexported fields
}
VText represents a text node in the virtual DOM.
func AsVText ¶
AsVText attempts to convert a VNode to a VText. Returns the VText and true if successful, otherwise nil and false.
func CreateTextNode ¶
CreateTextNode creates a new text node with the given content.
func (*VText) GetReadabilityData ¶
func (n *VText) GetReadabilityData() *ReadabilityData
GetReadabilityData returns the readability-specific data for this node.
func (*VText) Parent ¶
func (n *VText) Parent() *VElement
Parent returns the parent element of this node.
func (*VText) SetParent ¶
func (n *VText) SetParent(parent *VElement)
SetParent sets the parent element of this node.
func (*VText) SetReadabilityData ¶
func (n *VText) SetReadabilityData(data *ReadabilityData)
SetReadabilityData sets the readability-specific data for this node.