本文整理汇总了Golang中code/google/com/p/go/net/html.Node.NextSibling方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.NextSibling方法的具体用法?Golang Node.NextSibling怎么用?Golang Node.NextSibling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/go/net/html.Node
的用法示例。
在下文中一共展示了Node.NextSibling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sanitizeRemove
// sanitizeRemove traverses pre-order over the nodes,
// removing any element nodes that are not whitelisted
// and and removing any attributes that are not whitelisted
// from a given element node
func (w *Whitelist) sanitizeRemove(n *html.Node) error {
return w.sanitizeNode(n, func(n *html.Node) bool {
if !w.HasElement(n.Data) {
if n.Parent != nil {
nextSibling := n.NextSibling
n.Parent.RemoveChild(n)
// reset next sibling to support continuation
// of linked-list style traversal of parent node's children
n.NextSibling = nextSibling
}
return false
}
return true
})
}
示例2: sanitizeUnwrap
// sanitizeUnwrap traverses pre-order over the nodes, reattaching
// the whitelisted children of any element nodes that are not
// whitelisted to the parent of the unwhitelisted node
func (w *Whitelist) sanitizeUnwrap(n *html.Node) error {
return w.sanitizeNode(n, func(n *html.Node) bool {
if w.HasElement(n.Data) || n.Parent == nil {
return true
}
insertBefore := n.NextSibling
firstChild := n.FirstChild
for c := n.FirstChild; c != nil; {
nodeToUnwrap := c
c = c.NextSibling
n.RemoveChild(nodeToUnwrap)
n.Parent.InsertBefore(nodeToUnwrap, insertBefore)
}
n.Parent.RemoveChild(n)
// reset next sibling to support continuation
// of linked-list style traversal of parent node's children
n.NextSibling = firstChild
return false
})
}