Created
August 7, 2014 02:58
-
-
Save fmpwizard/dccaef7f0b74ae35fc4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const html9 = (`<html><head></head><body><div data-lift="ReplaceInnerSpan"><p>Diego</p><p class="last-name">Bauman</p></div></body></html>`) | |
func ReplaceInnerSpan(in string) string { | |
//in is the html we get from the template | |
sq, _ := selector.Selector("[data-lift]") | |
//because the html may not be a full page, we use the Partial* function | |
node, _ := h5.PartialFromString(in) | |
for _, value1 := range node { | |
//apply the css selector to get a []*html.Node of matching nodes | |
ret := sq.Find(value1) | |
for _, value2 := range ret { | |
//if we wanted to have a *Tree of the nodes, use this | |
t := h5.NewTree(value2) | |
//here we loop over the attributes of the matching node | |
for _, attr := range value2.Attr { | |
fmt.Println("Function Name: " + attr.Val) | |
fmt.Println("html to process: " + h5.RenderNodesToString([]*html.Node{value2})) | |
} | |
return t.String() | |
} | |
} | |
return "" | |
} | |
the result is | |
Function Name: ReplaceInnerSpan | |
html to process: <div data-lift="ReplaceInnerSpan"><p>Diego</p><p class="last-name">Bauman</p></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment