本文整理汇总了Golang中golang.org/x/net/html.Node.FirstChild方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.FirstChild方法的具体用法?Golang Node.FirstChild怎么用?Golang Node.FirstChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/net/html.Node
的用法示例。
在下文中一共展示了Node.FirstChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: removeNegativeAttributeMatches
func removeNegativeAttributeMatches(n *html.Node) *html.Node {
for c := n.FirstChild; c != nil; c = c.NextSibling {
if c.Type != html.TextNode && containerregrex.MatchString(c.Data) {
for _, attr := range c.Attr {
key := strings.ToLower(attr.Key)
if key == "id" || key == "class" {
val := strings.ToLower(attr.Val)
values := nonwordregex.Split(val, -1)
penalty := 0
for _, value := range values {
if negativeregex.MatchString(value) {
penalty = penalty + 4
}
}
if penalty > 0 {
if c.PrevSibling != nil {
c.PrevSibling.NextSibling = c.NextSibling
} else {
n.FirstChild = c.NextSibling
}
} else {
d := removeNegativeAttributeMatches(c)
if c.PrevSibling != nil {
c.PrevSibling.NextSibling = d
} else {
n.FirstChild = c.NextSibling
}
}
}
}
}
}
return n
}
示例2: topDownV1
/*
div div
div p
p TO img
img p
p
Operates from the *middle* div.
Saves all children in inverted slice.
Removes each child and reattaches it one level higher.
Finally the intermediary, now childless div is removed.
\ /
\ /\ /
\_____/ \_____/
\ /
\_____/\_____/
\__________/ => Breaks are gone
\p1___p2___/ => Wrapping preserves breaks
*/
func topDownV1(n *html.Node, couple []string, parentType string) {
if noParent(n) {
return
}
p := n.Parent
parDiv := p.Type == html.ElementNode && p.Data == couple[0] // Parent is a div
iAmDiv := n.Type == html.ElementNode && n.Data == couple[1] // I am a div
noSiblings := n.PrevSibling == nil && n.NextSibling == nil
only1Child := n.FirstChild != nil && n.FirstChild == n.LastChild
svrlChildn := n.FirstChild != nil && n.FirstChild != n.LastChild
noChildren := n.FirstChild == nil
_, _ = noSiblings, noChildren
if parDiv && iAmDiv {
if only1Child || svrlChildn {
var children []*html.Node
for c := n.FirstChild; c != nil; c = c.NextSibling {
children = append([]*html.Node{c}, children...) // order inversion
}
insertionPoint := n.NextSibling
for _, c1 := range children {
n.RemoveChild(c1)
if c1.Type == html.TextNode || c1.Data == "a" {
// pf("wrapping %v\n", NodeTypeStr(c1.Type))
wrap := html.Node{Type: html.ElementNode, Data: "p",
Attr: []html.Attribute{html.Attribute{Key: "cfrm", Val: "div"}}}
wrap.FirstChild = c1
p.InsertBefore(&wrap, insertionPoint)
c1.Parent = &wrap
insertionPoint = &wrap
} else {
p.InsertBefore(c1, insertionPoint)
insertionPoint = c1
}
}
p.RemoveChild(n)
if p.Data != parentType {
p.Data = parentType
}
}
}
}
示例3: removeNegativeMatches
func removeNegativeMatches(n *html.Node) *html.Node {
for c := n.FirstChild; c != nil; c = c.NextSibling {
if !negativeregex.MatchString(c.Data) || positiveregex.MatchString(c.Data) {
d := removeNegativeMatches(c)
if c.PrevSibling != nil {
c.PrevSibling.NextSibling = d
} else {
n.FirstChild = d
}
} else {
if c.PrevSibling != nil {
c.PrevSibling.NextSibling = c.NextSibling
} else {
n.FirstChild = c.NextSibling
}
}
}
return n
}
示例4: openTag
func (m *minificationText) openTag(node *html.Node) {
parent := node.Parent
for it := node.FirstChild; it != nil; it = it.NextSibling {
it.Parent = parent
}
parent.FirstChild = node.FirstChild
parent.LastChild = node.LastChild
node.FirstChild = nil
node.LastChild = nil
node.Parent = nil
}