htmlfmt

package module
v0.0.0-...-0c51898 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: MIT Imports: 10 Imported by: 0

README

htmlfmt

HTML formatter.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	Key   string
	Value string
}

Attribute represents an HTML attribute.

func (Attribute) IsZero

func (a Attribute) IsZero() bool

IsZero returns whenter a is zero.

type Attributes

type Attributes []Attribute

Attributes is a slice of Attribute.

func (Attributes) ByKey

func (a Attributes) ByKey(key string) Attribute

ByKey finds an Attribute by its key. Returns a zero value if not found.

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Formatter configures the formatting and can be safely reused.

func New

func New(options ...Option) *Formatter

New HTML formatter. Can be safely reused.

func (*Formatter) Format

func (f *Formatter) Format(dst io.Writer, src io.Reader) error

Format formats src and writes the result to dst.

type Option

type Option func(f *Formatter)

Option sets an option of the HTML formatter.

func WithNewlineAttributePlaceholder

func WithNewlineAttributePlaceholder(attribute string) Option

WithNewlineAttributePlaceholder is admittedly a specialist option.

It was added for the gotfmt Go template preprocessor which needed to preserve some newlines around certain template blocks. Setting this to "newline" and the formatter will only print the whitespace produced by "<br newline/>".

Note that this is only supported for void/self closing elements.

func WithTab

func WithTab(tab string) Option

WithTab configures the formatter use tab as indentation.

func WithTextFormatters

func WithTextFormatters(lookup func(tag Tag) TextFormatter) Option

WithTextFormatters configures the formatter to use the provided lookup func to find a formatter for a block of text inside tag (e.g. a JavaScript formatter).

type Tag

type Tag struct {
	Name       string
	Attributes Attributes
}

Tag represents a HTML tag.

func (Tag) IsZero

func (t Tag) IsZero() bool

IsZero returns whether t is zero.

type TextFormatter

type TextFormatter func(text []byte, depth int) []byte

TextFormatter allows clients to plug in a text formatter for a given tag, e.g. <script> blocks.

Jump to

Keyboard shortcuts

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