Skip to content

Instantly share code, notes, and snippets.

@fmpwizard
Created August 7, 2014 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmpwizard/dccaef7f0b74ae35fc4d to your computer and use it in GitHub Desktop.
Save fmpwizard/dccaef7f0b74ae35fc4d to your computer and use it in GitHub Desktop.
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