@@ -43,8 +43,7 @@ func ParseFragment(
43
43
result := ownerDocument .CreateDocumentFragment ()
44
44
if err == nil {
45
45
for _ , child := range nodes {
46
- element := createElementFromNode (ownerDocument , result , child )
47
- result .AppendChild (element )
46
+ iterate (ownerDocument , result , child )
48
47
}
49
48
}
50
49
return result , err
@@ -87,7 +86,7 @@ func parseIntoDocument(doc dom.Document, r io.Reader) error {
87
86
if err != nil {
88
87
return err
89
88
}
90
- iterate (doc , doc , node )
89
+ iterateChildren (doc , doc , node )
91
90
return nil
92
91
}
93
92
@@ -128,23 +127,27 @@ func createElementFromNode(
128
127
}
129
128
newNode = newElm
130
129
newNode = rules .AppendChild (parent , newElm )
131
- iterate (d , newNode , source )
130
+ iterateChildren (d , newNode , source )
132
131
return newElm
133
132
}
134
133
135
- func iterate (d dom.Document , dest dom.Node , source * html.Node ) {
134
+ func iterateChildren (d dom.Document , dest dom.Node , source * html.Node ) {
136
135
for child := range source .ChildNodes () {
137
- switch child .Type {
138
- case html .ElementNode :
139
- createElementFromNode (d , dest , child )
140
- case html .TextNode :
141
- dest .AppendChild (d .CreateText (child .Data ))
142
- case html .DoctypeNode :
143
- dest .AppendChild (d .CreateDocumentType (child .Data ))
144
- case html .CommentNode :
145
- dest .AppendChild (d .CreateComment (child .Data ))
146
- default :
147
- panic (fmt .Sprintf ("Node not yet supported: %v" , child .Type ))
148
- }
136
+ iterate (d , dest , child )
137
+ }
138
+ }
139
+
140
+ func iterate (d dom.Document , dest dom.Node , child * html.Node ) {
141
+ switch child .Type {
142
+ case html .ElementNode :
143
+ createElementFromNode (d , dest , child )
144
+ case html .TextNode :
145
+ dest .AppendChild (d .CreateText (child .Data ))
146
+ case html .DoctypeNode :
147
+ dest .AppendChild (d .CreateDocumentType (child .Data ))
148
+ case html .CommentNode :
149
+ dest .AppendChild (d .CreateComment (child .Data ))
150
+ default :
151
+ panic (fmt .Sprintf ("Node not yet supported: %v" , child .Type ))
149
152
}
150
153
}
0 commit comments