This commit is contained in:
2026-02-12 01:10:58 +03:00
parent 23f32375a4
commit f41daf8f88

View File

@@ -15,7 +15,7 @@ var body = &html.Node{
DataAtom: atom.Body, DataAtom: atom.Body,
} }
var ErrNotAnElementNode = errors.New("not an ElementNode") var ErrNotAnElementNode = errors.New("not a html.ElementNode")
func parseFragment(s string) (*html.Node, error) { func parseFragment(s string) (*html.Node, error) {
n, err := html.ParseFragment(strings.NewReader(s), body) n, err := html.ParseFragment(strings.NewReader(s), body)
@@ -25,18 +25,26 @@ func parseFragment(s string) (*html.Node, error) {
return n[0], nil return n[0], nil
} }
func MatchElemAttr(s string, n2 *html.Node) (bool, error) { func MatchElemAttr(s string, n *html.Node) (bool, error) {
n1, err := parseFragment(s) n1, err := parseFragment(s)
if err != nil { if err != nil {
return false, err return false, err
} }
if !(n1.Type == html.ElementNode && if n1.Type != html.ElementNode {
n2.Type == html.ElementNode) { return false, errors.Join(
return false, ErrNotAnElementNode ErrNotAnElementNode,
errors.New("s isn's a html.ElementNode"),
)
}
if n.Type != html.ElementNode {
return false, errors.Join(
ErrNotAnElementNode,
errors.New("n isn's a html.ElementNode"),
)
} }
if n1.Data == n2.Data && if n1.Data == n.Data &&
slices.Equal(n1.Attr, n2.Attr) { slices.Equal(n1.Attr, n2.Attr) {
return true, nil return true, nil
} }