File tree 1 file changed +14
-17
lines changed
1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change @@ -63,9 +63,22 @@ func (s *Selection) Text() string {
63
63
var buf bytes.Buffer
64
64
65
65
// Slightly optimized vs calling Each: no single selection object created
66
+ var f func (* html.Node )
67
+ f = func (n * html.Node ) {
68
+ if n .Type == html .TextNode {
69
+ // Keep newlines and spaces, like jQuery
70
+ buf .WriteString (n .Data )
71
+ }
72
+ if n .FirstChild != nil {
73
+ for c := n .FirstChild ; c != nil ; c = c .NextSibling {
74
+ f (c )
75
+ }
76
+ }
77
+ }
66
78
for _ , n := range s .Nodes {
67
- buf . WriteString ( getNodeText ( n ) )
79
+ f ( n )
68
80
}
81
+
69
82
return buf .String ()
70
83
}
71
84
@@ -192,22 +205,6 @@ func (s *Selection) ToggleClass(class ...string) *Selection {
192
205
return s
193
206
}
194
207
195
- // Get the specified node's text content.
196
- func getNodeText (node * html.Node ) string {
197
- if node .Type == html .TextNode {
198
- // Keep newlines and spaces, like jQuery
199
- return node .Data
200
- } else if node .FirstChild != nil {
201
- var buf bytes.Buffer
202
- for c := node .FirstChild ; c != nil ; c = c .NextSibling {
203
- buf .WriteString (getNodeText (c ))
204
- }
205
- return buf .String ()
206
- }
207
-
208
- return ""
209
- }
210
-
211
208
func getAttributePtr (attrName string , n * html.Node ) * html.Attribute {
212
209
if n == nil {
213
210
return nil
You can’t perform that action at this time.
0 commit comments