Cody Joyce 1 month ago
parent
commit
b865265e11
2 changed files with 13 additions and 10 deletions
  1. 6 4
      gen/domquery/node.go
  2. 7 6
      gen/main.go

+ 6 - 4
gen/domquery/node.go

@@ -26,14 +26,16 @@ func (node *Node) SetOuterHTML(str string) {
 	closeTag.token = ""
 
 	//use the token to insert str
-	node.token = str
+	node.token = ""
 	node.Children = []*Node{}
 
 	// regen parent
-	tokList := getTokenList(node.Parent.InnerHTML())
+	tokList := getTokenList(str)
 	tree := buildTree(tokList)
-
-	node.Parent.Children = tree.Children
+	node.Children = tree.Children
+	for _, child := range tree.Children {
+		child.Parent = node
+	}
 }
 
 func (node *Node) InnerHTML() string {

+ 7 - 6
gen/main.go

@@ -327,14 +327,15 @@ func cleanBlocks(dir string) error {
 
 		var clean func()
 		clean = func() {
-			blocks := dom.QuerySelectorAll("block")
-
-			// grab the top block only as blocks is invalid after a SetOuterHTML event
-			for _, block := range blocks {
-				block.SetOuterHTML(block.InnerHTML())
-				clean()
+			block := dom.QuerySelector("block")
+			if block.TagName() != "block" {
 				return
 			}
+
+			block.SetOuterHTML(block.InnerHTML())
+			clean()
+			return
+
 		}
 		clean()