nodes

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

README

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.


Readme created from Go doc with goreadme

Documentation

Overview

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.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Beautify = false

Functions

This section is empty.

Types

type Attr

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

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) WriteTo

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

WriteTo writes the current string to the writer w

type ContentNode

type ContentNode []io.WriterTo

func (ContentNode) WriteTo

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

type Element

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

func NewElement

func NewElement(tagname string, options ...interface{}) 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

Example
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:

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

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

Jump to

Keyboard shortcuts

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