Documentation
¶
Overview ¶
A powerful and comprehensive HTML parser and DOM manipulation library for Go, bringing JavaScript-like DOM operations to the Go ecosystem.
Index ¶
- Constants
- Variables
- func Encode(w io.Writer, rootNode *Node)
- func IsVoidTag(tagName string) bool
- func NodeTreeToHTML(rootNode *Node) string
- type ClassList
- func (classList ClassList) AppendClass(className string)
- func (classList ClassList) Contains(className string) bool
- func (classList ClassList) DeleteClass(className string)
- func (classList ClassList) Encode() string
- func (classList ClassList) EncodeTo(node *Node)
- func (classList ClassList) SetClass(node *Node)
- type Node
- func (node *Node) Append(newNode *Node)
- func (node *Node) AppendChild(childNode *Node)
- func (node *Node) AppendText(text string)
- func (node *Node) GetAttribute(attributeName string) (string, bool)
- func (node *Node) GetChildNode() *Node
- func (node *Node) GetFirstNode() *Node
- func (node *Node) GetInnerText() string
- func (node *Node) GetLastNode() *Node
- func (node *Node) GetNextNode() *Node
- func (node *Node) GetParent() *Node
- func (node *Node) GetPreviousNode() *Node
- func (node *Node) GetTagName() string
- func (node *Node) GetText() string
- func (node *Node) IsTextNode() bool
- func (node *Node) IterateAttributes(callback func(attribute, value string))
- func (node *Node) RemoveAttribute(attributeName string)
- func (node *Node) RemoveNode()
- func (node *Node) SetAttribute(attribute, value string)
- func (node *Node) SetNextNode(nextNode *Node)
- func (node *Node) SetPreviousNode(previousNode *Node)
- func (node *Node) SetTagName(tagName string)
- func (node *Node) SetText(text string)
- type TraverseCondition
- type Traverser
Constants ¶
const ( Area string = "area" Base string = "base" Br string = "br" Col string = "col" Embed string = "embed" Hr string = "hr" Img string = "img" Input string = "input" Link string = "link" Meta string = "meta" Param string = "param" Source string = "source" Track string = "track" Wbr string = "wbr" )
Void tags
const ( //This is not a void el. but added it anyway. DOCTYPEDTD string = "!DOCTYPE" )
A DTD defines the structure and the legal elements and attributes of an XML document.
Variables ¶
var (
SyntaxError error = fmt.Errorf("Syntax error")
)
Functions ¶
func NodeTreeToHTML ¶
NodeTreeToHTML returns encoding of node-tree as a string.
Types ¶
type ClassList ¶
type ClassList struct {
// contains filtered or unexported fields
}
func (ClassList) AppendClass ¶
AppendClass append className to classList. className that contains multiple classes is also a valid className.
func (ClassList) DeleteClass ¶
DeleteClass deletes the specified classes in className.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
The DOM Node struct is an abstract base class upon which many other DOM API objects are based, thus letting those object types to be used similarly and often interchangeably.
func CloneNode ¶
CloneNode copy the node. But have one way connections to it's parent, next and previous nodes.
func CreateTextNode ¶
CreateTextNode returns a new node that represents the given text.
func Decode ¶
Decode reads from rd and create a node-tree. Then returns the root node and an error. If error were to occur it would be SyntaxError.
func DeepCloneNode ¶
DeepCloneNode clones the node without having references to it's original parent node, previous node and next node.
func HTMLToNodeTree ¶
HTMLToNodeTree return html code as a node-tree. If error were to occur it would be SyntaxError.
func (*Node) AppendChild ¶
The AppendChild() method of the Node adds a node to the end of the list of children of a specified parent node.
func (*Node) AppendText ¶
AppendText append text to the node.
func (*Node) GetAttribute ¶
GetAttribute returns the specified attribute value form the node. If the specified attribute doesn't exists GetAttribute returns a empty string and false.
func (*Node) GetChildNode ¶
GetChildNode returns the first child elements of this node.
func (*Node) GetFirstNode ¶
GetFirstNode returns the first node of the node branch.
func (*Node) GetInnerText ¶
GetInnerText returns all of the text inside the node.
func (*Node) GetLastNode ¶
GetLastNode returns the last node in the node branch.
func (*Node) GetNextNode ¶
GetNextNode returns node next to the node.
func (*Node) GetPreviousNode ¶
GetPreviousNode returns the previous node.
func (*Node) GetTagName ¶
Returns a string with the name of the tag for the given node.
func (*Node) GetText ¶
GetText returns text on the node. This does not returns text on it's child nodes. If you also wants child nodes text use GetInnerText method on the node.
func (*Node) IsTextNode ¶
IsTextNode returns a boolean value indicating node is a text node or not.
func (*Node) IterateAttributes ¶
IterateAttributes calls callback at every attribute in the node by passing attribute and value of the node.
func (*Node) RemoveAttribute ¶
RemoveAttribute remove or delete the specified attribute.
func (*Node) RemoveNode ¶
func (node *Node) RemoveNode()
RemoveNode removes the node from the branch safely by connecting sibling nodes.
func (*Node) SetAttribute ¶
SetAttribute add a attribute to the node.
func (*Node) SetNextNode ¶
SetNextNode make nodes next node as nextNode.
func (*Node) SetPreviousNode ¶
SetPreviousNode sets nodes previous node to previousNode.
func (*Node) SetTagName ¶
SetTagName changes the html tag name to the tagName.
type TraverseCondition ¶
type TraverseCondition bool
const ( StopWalkthrough TraverseCondition = true ContinueWalkthrough TraverseCondition = false )
type Traverser ¶
type Traverser struct {
// contains filtered or unexported fields
}
func GetTraverser ¶
GetTraverser returns a new traverser that can be used to navigate the node tree.
func (*Traverser) GetCurrentNode ¶
GetCurrentNode returns the current node.
func (*Traverser) Next ¶
Next returns the node next to current node and change CurrentNode to the new node.
func (*Traverser) Previous ¶
Previous returns the previous node and change CurrentNode to the new node.
func (*Traverser) SetCurrentNodeTo ¶
SetCurrentNodeTo changes the current node to the newNode.
func (*Traverser) Walkthrough ¶
func (t *Traverser) Walkthrough(callback func(node *Node) TraverseCondition)
Walkthrough traverse the node tree from the current node to the end of the node tree by visiting every node. If callback returned StopWalkthrough walkthrough function will stop else if it returned ContinueWalkthrough it advanced to the next node. Walkthrough calls callback at every node and pass that node. Walkthrough traverse the node tree similar to DFS without visiting visited nodes iteratively.