feat: Rename Parse to ParseDocument, add ParseNode

This commit is contained in:
ptrcnull 2022-07-08 00:12:01 +02:00
parent 947b928a5d
commit 8b4b2ec3cd

10
html.go
View file

@ -12,7 +12,7 @@ type Node struct {
*html.Node
}
func Parse(r io.Reader) (*Node, error) {
func ParseDocument(r io.Reader) (*Node, error) {
n, err := html.Parse(r)
if err != nil {
return nil, err
@ -20,6 +20,14 @@ func Parse(r io.Reader) (*Node, error) {
return &Node{n}, nil
}
func ParseNode(r io.Reader) (*Node, error) {
n, err := html.ParseFragment(r, nil)
if err != nil {
return nil, err
}
return &Node{n[0]}, nil
}
func (n *Node) QuerySelector(selector string) *Node {
if strings.HasPrefix(selector, "#") {
return n.GetElementById(selector[1:])