all repos — htmlformat @ indent-script-style-content

Go package and CLI tool used to format HTML

drwxrwxrwx
cmd/
-rw-r--r--
1112
LICENSE
-rw-r--r--
813
README.md
-rw-r--r--
5835
format.go
-rw-r--r--
1769
format_test.go
-rw-r--r--
117
go.mod
-rw-r--r--
320
go.sum

htmlformat

htmlformat is a Go package and CLI tool used to format HTML.

It is forked and simplified from the https://github.com/ericchiang/pup package.

It does not aim to:

  • Colorize output.
  • Modify the input HTML except for formatting (i.e. no HTML escaping will be applied).
  • Provide any facilities to query the content.

Installation

To use the CLI, you can install with Go > 1.20.

go install alin.ovh/htmlformat/cmd/htmlformat@latest

Usage

CLI

echo '<ol><li style="&"><em>A</em></li><li>B</li></ol>' | htmlformat
<ol>
 <li style="&">
  <em>A</em>
 </li>
 <li>B</li>
</ol>

Package

r := strings.NewReader(`<ol><li style="&">A</li><li>B</li></ol>`)
w := os.Stdout
if err := Fragment(w, r); err != nil {
  log.Fatalf("failed to format: %v", err)
}