Skip to content

hermanschaaf/prettyprint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go PrettyPrint HTML

A simple pretty printer for HTML, written in Go.

Installation

go get github.com/hermanschaaf/prettyprint

Usage

import (
    "github.com/hermanschaaf/prettyprint"
    "fmt"
)

func main() {
    html := `<html><head></head><body><a href="http://test.com">Test link</a><p><br/></p></body></html>`
    // second parameter is the indent to use 
    // (can be anything: spaces, a tab, etc.)
    pretty, err := prettyprint.Prettify(html, "    ")
    if err != nil {
        // do something in case of error
    }
    // print the prettified html:
    fmt.Println(pretty)
}

This will have the following output:

<html>
    <head>
    </head>
    <body>
        <a href="http://test.com">Test link</a>
        <p>
            <br/>
        </p>
    </body>
</html>

Known issues

  • Poor support for self-closing tags, like HTML5 <br>. For now, only explicitly self-closing tags like <br/> will print correctly.
  • No special cases for <pre> and <code> tags
  • Comments may or may not work, they are more or less untested

About

Go HTML PrettyPrint

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages