Last active
September 28, 2015 12:17
-
-
Save Luit/db775d67733784a6440f to your computer and use it in GitHub Desktop.
in response to https://twitter.com/pdimitar/status/648458395675164672
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
package main | |
import ( | |
"log" | |
"os" | |
"golang.org/x/net/html" | |
) | |
func main() { | |
n := &html.Node{ | |
Type: html.ElementNode, | |
Data: "div", | |
} | |
check := &html.Node{ | |
Type: html.ElementNode, | |
Data: "div", | |
} | |
check.AppendChild(&html.Node{ | |
Type: html.TextNode, | |
Data: "hey check this out", | |
}) | |
n.AppendChild(check) | |
neat := &html.Node{ | |
Type: html.ElementNode, | |
Data: "div", | |
} | |
neat.AppendChild(&html.Node{ | |
Type: html.TextNode, | |
Data: "kinda neat imo", | |
}) | |
neat.AppendChild(&html.Node{ | |
Type: html.ElementNode, | |
Data: "br", | |
}) | |
check.AppendChild(neat) | |
sweet := &html.Node{ | |
Type: html.ElementNode, | |
Data: "div", | |
} | |
sweet.AppendChild(&html.Node{ | |
Type: html.TextNode, | |
Data: "haha sweet", | |
}) | |
n.AppendChild(sweet) | |
err := html.Render(os.Stdout, n) | |
if err != nil { | |
log.Fatal(err) | |
} | |
_, err = os.Stdout.Write([]byte{'\n'}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
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
$ go run main.go | |
<div><div>hey check this out<div>kinda neat imo<br/></div></div><div>haha sweet</div></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment