# GoHTML - HTML formatter for Go [![wercker status](https://app.wercker.com/status/926cf3edc004271539be40d705d037bd/s "wercker status")](https://app.wercker.com/project/bykey/926cf3edc004271539be40d705d037bd) [![GoDoc](http://godoc.org/github.com/yosssi/gohtml?status.png)](http://godoc.org/github.com/yosssi/gohtml) GoHTML is an HTML formatter for [Go](http://golang.org/). You can format HTML source codes by using this package. ## Install ``` go get -u github.com/yosssi/gohtml ``` ## Example Example Go source code: ```go package main import ( "fmt" "github.com/yosssi/gohtml" ) func main() { h := `This is a title.

AAA
BBB>

` fmt.Println(gohtml.Format(h)) } ``` Output: ```html This is a title.

AAA
BBB>

``` ## Output Formatted HTML with Line No You can output formatted HTML source codes with line no by calling `FormatWithLineNo`: ```go package main import ( "fmt" "github.com/yosssi/gohtml" ) func main() { h := `This is a title.

AAA
BBB>

` fmt.Println(gohtml.FormatWithLineNo(h)) } ``` Output: ```sh 1 2 3 4 5 This is a title. 6 7 13 20 21 22
23 24

25 AAA 26
27 BBB> 28

29
30 31 32 ``` ## Format Go html/template Package's Template's Execute Result You can format [Go html/template package](http://golang.org/pkg/html/template/)'s template's execute result by passing `Writer` to the `tpl.Execute`: ```go package main import ( "os" "text/template" "github.com/yosssi/gohtml" ) func main() { tpl, err := template.New("test").Parse("{{.Msg}}") if err != nil { panic(err) } data := map[string]interface{}{"Msg": "Hello!"} err = tpl.Execute(gohtml.NewWriter(os.Stdout), data) if err != nil { panic(err) } } ``` Output: ```html Hello! ``` ## Docs * [GoDoc](https://godoc.org/github.com/yosssi/gohtml)