htmlfmt

package module
v0.0.0-...-a1bf404 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2018 License: MIT Imports: 8 Imported by: 2

README

htmlfmt

html reformatter and minifier that understands block and in-line elements

API IS UNSTABLE

Both the golang API and CLI are unstable. Expect breaking changes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(src io.Reader, out io.Writer, prefix, indent string) error

Format reformats an input HTML document or error

func FormatBytes

func FormatBytes(src []byte, prefix, indent string) []byte

FormatBytes reformats an input HTML document as []byte

func FormatFragment

func FormatFragment(src io.Reader, out io.Writer, prefix, indent string) error

FormatFragment reformats an HTML fragment

func Render

func Render(w io.Writer, n *html.Node, prefix, indent string) error

Render renders the parse tree n to the given writer.

Rendering is done on a 'best effort' basis: calling Parse on the output of Render will always result in something similar to the original tree, but it is not necessarily an exact clone unless the original tree was 'well-formed'. 'Well-formed' is not easily specified; the HTML5 specification is complicated.

Calling Parse on arbitrary input typically results in a 'well-formed' parse tree. However, it is possible for Parse to yield a 'badly-formed' parse tree. For example, in a 'well-formed' parse tree, no <a> element is a child of another <a> element: parsing "<a><a>" results in two sibling elements. Similarly, in a 'well-formed' parse tree, no <a> element is a child of a <table> element: parsing "<p><table><a>" results in a <p> with two sibling children; the <a> is reparented to the <table>'s parent. However, calling Parse on "<a><table><a>" does not return an error, but the result has an <a> element with an <a> child, and is therefore not 'well-formed'.

Programmatically constructed trees are typically also 'well-formed', but it is possible to construct a tree that looks innocuous but, when rendered and re-parsed, results in a different tree. A simple example is that a solitary text node would become a tree containing <html>, <head> and <body> elements. Another example is that the programmatic equivalent of "a<head>b</head>c" becomes "<html><head><head/><body>abc</body></html>".

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL