Documentation
¶
Overview ¶
Package htmlformat provides function for cleanly formatting html code, for purposes of making the html code more human-readable.
Cleanly formatted (AKA pretty printed) means: - any excess or unnecessary whitespaces are removed - child nodes are indented and aligned relative to parent node
This package does not handle long lines, no line wrapping is done to break lone lines.
Conserving whitespaces takes priority over formatting and readability. This means this package avoids adding whitespaces where it might alter rendered HTML.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
Format returns a cleanly formatted html string.
Example ¶
html := `<p id = "x">hello</p > ` fmt.Println(Format(html))
Output: <p id="x">hello</p>
func Write ¶
Format writes the cleanly formatted html string into w.
Example ¶
// Write output directly to stdout html := `<p id = "x">hello to stdout</p > ` Write(html, os.Stdout)
Output: <p id="x">hello to stdout</p>
Example (Second) ¶
// Write output directly to a file file, err := os.CreateTemp("", "") if err != nil { panic(err) } defer os.Remove(file.Name()) html := `<p id = "x">hello to file</p > ` Write(html, file) file.Sync() file.Close() bytes, err := os.ReadFile(file.Name()) fmt.Println(string(bytes))
Output: <p id="x">hello to file</p>
Types ¶
This section is empty.