mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Merge pull request #87 from qiuzhiqian/master
fix bug: BaseNode.RemoveChildren only set the first child as nil
This commit is contained in:
commit
5294fa5c4f
2 changed files with 21 additions and 1 deletions
|
|
@ -236,10 +236,12 @@ func (n *BaseNode) RemoveChild(self, v Node) {
|
|||
|
||||
// RemoveChildren implements Node.RemoveChildren .
|
||||
func (n *BaseNode) RemoveChildren(self Node) {
|
||||
for c := n.firstChild; c != nil; c = c.NextSibling() {
|
||||
for c := n.firstChild; c != nil; {
|
||||
c.SetParent(nil)
|
||||
c.SetPreviousSibling(nil)
|
||||
next := c.NextSibling()
|
||||
c.SetNextSibling(nil)
|
||||
c = next
|
||||
}
|
||||
n.firstChild = nil
|
||||
n.lastChild = nil
|
||||
|
|
|
|||
18
ast/ast_test.go
Normal file
18
ast/ast_test.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package ast
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRemoveChildren(t *testing.T) {
|
||||
root := NewDocument()
|
||||
|
||||
node1 := NewDocument()
|
||||
|
||||
node2 := NewDocument()
|
||||
|
||||
root.AppendChild(root, node1)
|
||||
root.AppendChild(root, node2)
|
||||
|
||||
root.RemoveChildren(root)
|
||||
|
||||
t.Logf("%+v", node2.PreviousSibling())
|
||||
}
|
||||
Loading…
Reference in a new issue