Skip to content

Latest commit

 

History

History

nodes

nodes

Package nodes provides data structures to represents Html ElementNodes, TextNodes and Attributes.

You are free to use this package, but is probably more comfortable to use the html package, that already have html elements and common attributes.

Variables

var Beautify = true

Types

type Attr

type Attr struct { ... }

Attr holds information about an attribute for an Element Node

func NewAttr

func NewAttr(key string, value ...string) Attr

NewAttr creates a new attribute. If several arguments are given, they are join by a space

func (Attr) String

func (a Attr) String() string

func (Attr) WriteTo

func (a Attr) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes the current string to the writer w

type ContentNode []io.WriterTo

func (ContentNode) WriteTo

func (c ContentNode) WriteTo(w io.Writer) (n64 int64, err error)

type Element

type Element struct { ... }

func NewElement(tagname string, options ...any) Element

NewElement creates a new element with the provided tagname and the provided options The options can be:

  • An Attr that will be render
  • A string or Text
  • Another Element
  • Any WriterTo interface Attributes are output in order The rest is output in the same order as received
Beautify = false
content := NewElement("html", NewAttr("lang", "en"),
    NewElement("head",
        NewElement("title", "Mi pagina")),
    NewElement("body",
        NewElement("h1", "This is my page")),
)

content.WriteTo(os.Stdout)

Output:

<!DOCTYPE html><html lang=en><head><title>Mi pagina</title><body><h1>This is my page</h1>

func (Element) String

func (r Element) String() string

func (Element) WriteTo

func (r Element) WriteTo(w io.Writer) (n64 int64, err error)

WriteTo writes the current string to the writer w

type Raw

type Raw string

func (Raw) WriteTo

func (t Raw) WriteTo(w io.Writer) (int64, error)

WriteTo writes the current string to the writer w without any escape

type Text

type Text string

Text represents a TextNode

func (Text) WriteTo

func (t Text) WriteTo(w io.Writer) (int64, error)

WriteTo writes the current string to the writer w while escapeing html with https://godocs.io/html#EscapeString


Readme created from Go doc with goreadme