tagfunctions

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

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

Go to latest
Published: Jan 29, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(parent *html.Node, children ...*html.Node) *html.Node

Append adds the child to the parent and returns the parent helper to do function chaining

func CsvEscape

func CsvEscape(n *html.Node) error

func Entity

func Entity(n *html.Node) error

given a $ent[VALUE] -> &VALUE; no error checkign to see if a value HTML or XML entity

func Execute

func Execute(n *html.Node, fmap map[string]NodeFunc) error

func Generate

func Generate(src string, fmap map[string]NodeFunc) (string, error)

Execute parses and renders a tag string

func GetArg

func GetArg(n *html.Node, i int) (out string)

GetArg - get Attribute value by index.

If index is invalid, an empty string is returned.

func GetAttr

func GetAttr(n *html.Node, key string) (out string)

GetAttr - Get Attribute by key

func InsertBefore

func InsertBefore(parent *html.Node, children ...*html.Node) *html.Node

func NewElement

func NewElement(name string, kv ...string) *html.Node

func NewText

func NewText(text string) *html.Node

func RemoveChildren

func RemoveChildren(n *html.Node) *html.Node

RemoveChildren removes all child nodes and returns itself

func Render

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

Render AST back into parseble string

i.e. $root{....}

func RenderHTML

func RenderHTML(w io.Writer, n *html.Node) error

Render AST into HTML

func RenderStringFunc

func RenderStringFunc(render func(io.Writer, *html.Node) error) func(n *html.Node) (string, error)

func Reparent

func Reparent(dst, src *html.Node) *html.Node

Reparent moves children from src to dst, and returns dst

func Replace

func Replace(dst, src *html.Node) *html.Node

Replace

func Select

func Select(n *html.Node, tag string) string

"select title" --

only returns text children
Could be improved.

func Selector

func Selector(n *html.Node, fn func(*html.Node) bool) []*html.Node

Selector recursively selects all nodes that match a given function

TODO: why is this in this file?

func Serve

func Serve(outdir string, prefix string)

func SetArg

func SetArg(n *html.Node, i int, k string)

SetArg Set attribute argument by index

func TextContent

func TextContent(n *html.Node) string

func ToArgs

func ToArgs(n *html.Node) []string

ToArgs converts a Node's attributes into a list of arguments

if a value is empty then it's just "key"

func TransformElement

func TransformElement(n *html.Node, name string, attr ...string) *html.Node

Transform changes ElementNode's name and attributes children remain the same

Types

type NodeFunc

type NodeFunc func(n *html.Node) error

func ExecuteFunc

func ExecuteFunc(m map[string]NodeFunc) NodeFunc

func MakeTag

func MakeTag(tag string) NodeFunc

MakeTag return a NodeFunc that transforms the incoming node - Type of ElementNode - With a new Tag name - With no Attributes - Children are preserved

func MakeTagClass

func MakeTagClass(tag string, cz string) NodeFunc

MakeTagClass returns a NodeFunc that transforms in incoming node: - Type of ElementNode - With a new Tag Name - Clears all existing attributes - Add an attribute of class with value - Children are preserved.

func NewCsvTableHTML

func NewCsvTableHTML(formatter func(string, int, int) string) NodeFunc

NewCsvTableHTML takes an embedded CSV and converts to an HTML table.

The table's tags have optional class attributes using the formatter function. If nil, then no class attributes are added. It takes the class name, and the row and col of the cell if appropriate.

fn("td", 3, 2") means emit a CSS class for a <td> in row 3, col 2. fn("table", 0,0,) the row and colum are always zero

Sometimes you need to wrap a table in an outer div to get the desired behavior.

fn("wrap", 0, 0)

if non-empty will wrap the table in a <div class="xxx">

type Paragrapher

type Paragrapher struct {
	Tag      string // elements to split on "\n\n" to generate new blocks
	Create   string // element to make
	IsInline func(*html.Node) bool
}

func (*Paragrapher) Execute

func (p *Paragrapher) Execute(n *html.Node) error

type Tokenizer

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

func (*Tokenizer) Parse

func (z *Tokenizer) Parse(r io.ByteScanner) *html.Node

Jump to

Keyboard shortcuts

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