htmlb

package
v1.8.8 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

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

Element represents an element in an HTML document being built.

func HTML

func HTML(w io.Writer) (e *Element)

HTML starts a new HTML document, emitting "<!DOCTYPE html><html>". It returns a pointer to the <html> element. The HTML document must be finished by calling the Close method on the element returned by HTML.

func (*Element) A

func (e *Element) A(attrs ...any) *Element

A is an alias for Attr, for brevity in calling code.

func (*Element) Attr

func (e *Element) Attr(args ...any) *Element

Attr adds attributes to the receiver Element. It panics if any text content or child elements have been emitted for the receiver Element. Attr returns its receiver for convenient chaining.

The arguments must follow this sequence:

  1. An optional Boolean argument, controlling whether the attribute assignments in the next argument should be emitted.
  2. A string argument, containing a set of attribute assignments.
  3. Zero or more variable arguments to be interpolated into the preceding attribute assignment string; there must be exactly as many of these as called for by printf-style format codes in the attribute assignment string.

This entire sequence can repeat any number of times.

Attribute assignments have the form `attrname`, `attrname=value`, `attrname='value'`, or `attrname="value"`. Multiple attribute assignments are separated by space characters.

Attribute values can make use of printf-style variable interpolation. Values for the interpolated variables are taken from the subsequent arguments to Element. Interpolated values are HTML-encoded. Attribute values that do not contain printf-style format codes are emitted verbatim (not HTML-encoded).

If the Boolean argument is present in the argument sequence, and is false, all attribute assignments in the subsequent string argument are ignored, along with the corresponding interpolated variable arguments. If the Boolean argument is absent or is true, the attribute assignments are emitted.

The "class" attribute is handled specially, in that it can be set multiple times, in calls to Element or Attr or both. All values provided for it are concatenated, separated by spaces, into a single attribute setting in the output HTML document. As such, the "class" attribute setting is always emitted last, regardless of where it may appear in the argument list.

func (*Element) Close

func (e *Element) Close() (p *Element, err error)

Close closes the receiver Element and returns its parent. If the receiver is the initial <html> element, Close returns nil. Close also returns any accumulated error from writing to the output writer.

func (*Element) E

func (e *Element) E(args ...any) *Element

E is an alias for Element, for brevity in calling code.

func (*Element) Element

func (e *Element) Element(args ...any) *Element

Element creates a new HTML element as a child of the receiver Element. Any preceding descendant elements of the receiver are closed. before creating the new element. Element returns the Element representing the new child element.

The first argument must be a string of the form

<tagname attribute-assignments>content

The tagname is required, and must be in lower case. If any content for the element is provided, the content must be preceded by '>'. Everything else is optional.

Attribute assignments have the form `attrname`, `attrname=value`, `attrname='value'`, or `attrname="value"`. Multiple attribute assignments are separated by space characters. See the description of Attr for how the "class" attribute is handled specially.

Attribute values and content can make use of printf-style variable interpolation. Values for the interpolated variables are taken from the subsequent arguments to Element. Interpolated values are HTML-encoded. Attribute values and content that do not contain printf-style format strings are emitted verbatim (not HTML-encoded).

Any arguments left over, after consuming the first argument and its interpolated variables, are passed to the Attr method (which see).

func (*Element) P

func (e *Element) P() *Element

P is an alias for Parent, for brevity in calling code.

func (*Element) Parent

func (e *Element) Parent() *Element

Parent returns the receiver Element's parent, or nil if the receiver Element is the initial <html> element.

func (*Element) R

func (e *Element) R(html string) *Element

R is an alias for Raw, for brevity in calling code.

func (*Element) Raw

func (e *Element) Raw(html string) *Element

Raw adds raw HTML markup to the content of the receiver Element. The markup will be emitted verbatim (no HTML encoding). The markup should not close the receiver Element, and must close any other elements that it opens. Raw returns its receiver for convenient chaining.

func (*Element) T

func (e *Element) T(text string) *Element

T is an alias for Text, for brevity in calling code.

func (*Element) TF

func (e *Element) TF(f string, v ...any) *Element

TF is an alias for Textf, for brevity in calling code.

func (*Element) Text

func (e *Element) Text(text string) *Element

Text adds text to the receiver Element. The text will be HTML-encoded before being emitted. Text returns its receiver for convenient chaining.

func (*Element) Textf

func (e *Element) Textf(f string, v ...any) *Element

Textf adds formatted text to the receiver Element. The text will be HTML encoded before being emitted. Textf returns its receiver for convenient chaining.

Jump to

Keyboard shortcuts

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