Documentation ¶
Overview ¶
Atempting to re-create my Python htmltree in go.
Index ¶
- Variables
- func Gohtify(htext string, ignoreTags map[string]struct{}, gohttext *string) (err error)
- func Ids(tree *HtmlTree, ids *[]string) (err error)
- func Render(h *HtmlTree, b *bytes.Buffer, nindent int) (err error)
- type AttributeErrors
- type HtmlTree
- func A(a string, c ...interface{}) *HtmlTree
- func Address(a string, c ...interface{}) *HtmlTree
- func Area(a string) *HtmlTree
- func Article(a string, c ...interface{}) *HtmlTree
- func Aside(a string, c ...interface{}) *HtmlTree
- func Audio(a string, c ...interface{}) *HtmlTree
- func B(a string, c ...interface{}) *HtmlTree
- func Blockquote(a string, c ...interface{}) *HtmlTree
- func Body(a string, c ...interface{}) *HtmlTree
- func Br(a string) *HtmlTree
- func Button(a string, c ...interface{}) *HtmlTree
- func Canvas(a string, c ...interface{}) *HtmlTree
- func Caption(a string, c ...interface{}) *HtmlTree
- func Cite(a string, c ...interface{}) *HtmlTree
- func Code(a string, c ...interface{}) *HtmlTree
- func Col(a string) *HtmlTree
- func Datalist(a string, c ...interface{}) *HtmlTree
- func Dd(a string, c ...interface{}) *HtmlTree
- func Details(a string, c ...interface{}) *HtmlTree
- func Dialog(a string, c ...interface{}) *HtmlTree
- func Div(a string, c ...interface{}) *HtmlTree
- func Dl(a string, c ...interface{}) *HtmlTree
- func Dt(a string, c ...interface{}) *HtmlTree
- func Em(a string, c ...interface{}) *HtmlTree
- func Embed(a string) *HtmlTree
- func Fieldset(a string, c ...interface{}) *HtmlTree
- func Figcaption(a string, c ...interface{}) *HtmlTree
- func Figure(a string, c ...interface{}) *HtmlTree
- func Footer(a string, c ...interface{}) *HtmlTree
- func Form(a string, c ...interface{}) *HtmlTree
- func H1(a string, c ...interface{}) *HtmlTree
- func H2(a string, c ...interface{}) *HtmlTree
- func H3(a string, c ...interface{}) *HtmlTree
- func H4(a string, c ...interface{}) *HtmlTree
- func H5(a string, c ...interface{}) *HtmlTree
- func H6(a string, c ...interface{}) *HtmlTree
- func Head(a string, c ...interface{}) *HtmlTree
- func Header(a string, c ...interface{}) *HtmlTree
- func Hr(a string) *HtmlTree
- func Html(a string, c ...interface{}) *HtmlTree
- func I(a string, c ...interface{}) *HtmlTree
- func Img(a string) *HtmlTree
- func Input(a string) *HtmlTree
- func Label(a string, c ...interface{}) *HtmlTree
- func Legend(a string, c ...interface{}) *HtmlTree
- func Li(a string, c ...interface{}) *HtmlTree
- func Link(a string) *HtmlTree
- func Main(a string, c ...interface{}) *HtmlTree
- func Map(a string, c ...interface{}) *HtmlTree
- func Meta(a string) *HtmlTree
- func Meter(a string, c ...interface{}) *HtmlTree
- func Nav(a string, c ...interface{}) *HtmlTree
- func Noscript(a string, c ...interface{}) *HtmlTree
- func Null(c ...interface{}) *HtmlTree
- func Object(a string, c ...interface{}) *HtmlTree
- func Ol(a string, c ...interface{}) *HtmlTree
- func Optgroup(a string, c ...interface{}) *HtmlTree
- func Option(a string, c ...interface{}) *HtmlTree
- func Output(a string, c ...interface{}) *HtmlTree
- func P(a string, c ...interface{}) *HtmlTree
- func Param(a string) *HtmlTree
- func Pre(a string, c ...interface{}) *HtmlTree
- func Progress(a string, c ...interface{}) *HtmlTree
- func S(a string, c ...interface{}) *HtmlTree
- func Samp(a string, c ...interface{}) *HtmlTree
- func Script(a string, c ...interface{}) *HtmlTree
- func Section(a string, c ...interface{}) *HtmlTree
- func Select(a string, c ...interface{}) *HtmlTree
- func Small(a string, c ...interface{}) *HtmlTree
- func Source(a string) *HtmlTree
- func Span(a string, c ...interface{}) *HtmlTree
- func Strong(a string, c ...interface{}) *HtmlTree
- func Style(a string, c ...interface{}) *HtmlTree
- func Sub(a string, c ...interface{}) *HtmlTree
- func Summary(a string, c ...interface{}) *HtmlTree
- func Sup(a string, c ...interface{}) *HtmlTree
- func Table(a string, c ...interface{}) *HtmlTree
- func Tbody(a string, c ...interface{}) *HtmlTree
- func Td(a string, c ...interface{}) *HtmlTree
- func Textarea(a string, c ...interface{}) *HtmlTree
- func Tfoot(a string, c ...interface{}) *HtmlTree
- func Th(a string, c ...interface{}) *HtmlTree
- func Thead(a string, c ...interface{}) *HtmlTree
- func Title(a string, c ...interface{}) *HtmlTree
- func Tr(a string, c ...interface{}) *HtmlTree
- func Track(a string) *HtmlTree
- func U(a string, c ...interface{}) *HtmlTree
- func Ul(a string, c ...interface{}) *HtmlTree
- func Video(a string, c ...interface{}) *HtmlTree
Constants ¶
This section is empty.
Variables ¶
var Attributes map[string][]string
Attributes is filled in at init time with a list of attributes and the tag names that support them.
Functions ¶
func Gohtify ¶ added in v1.1.2
Gohtify parses an html string, htext, and returns equivalent goht code in gohttext. The ignoreTags map contains one or more tags to be ignored as map keys. These are typically "html", "head" and "body" because html.Parse creates them if they're not present in the string. That's usually not desired since the chief use of Gohtify is to turn useful fragments of html into into equivalent Go code.
func Ids ¶ added in v1.1.2
Ids returns a slice of string containing all the id attributes found in tree. It will return an error if the search finds a malformed id, multiple ids in the same tag or the same id in different tags.
func Render ¶
Render walks through HtmlTree h and writes html text to byte buffer b. The nindent argument specifies whether and how much to indent the output where -1 means render all on one line and 0 means indent each inner tag by 2 spaces relative to its parent. Render returns an error when it encounters invalid content.
Types ¶
type AttributeErrors ¶
type AttributeErrors struct { Tag string // an html tag Attrs string // a string of zero or more attributes Errs []error // errors found in attrs }
AttributeErrors is a struct returned by CheckAttributes. It contains the tag, the string of attributes and a slice of errors returned by checkTagAttributes.
type HtmlTree ¶
type HtmlTree struct { T string // html tagname, e.g. 'head' A string // zero or more html attributes, e.g 'id=1 class="foo"' C []interface{} // a slice of content whose elements may be strings or *HtmlTree // contains filtered or unexported fields }
HtmlTree represents a tree of html content.
func Blockquote ¶
func Figcaption ¶
func Null ¶ added in v1.1.0
func Null(c ...interface{}) *HtmlTree
Null tag is a special case and does not correspond to any valid HTML tag. When rendered it returns its content with no enclosing tag, e.g. Null(Br(“),Br(“)) --> <br><br> . It is defined in goht to support injecting a list of elements into an existing tag as JavaScript innerHTML content.
func Style ¶
Style is a special case in the sense that the only valid content is one or more strings of CSS. At this time there's no check to complain about other content.
func (*HtmlTree) CheckAttributes ¶
func (e *HtmlTree) CheckAttributes(perrs *[]AttributeErrors)
CheckAttributes walks through an ElementTree and checks each tag to verify that the attribute names associated with the tag are valid for that tag. It returns a slice AttributeErrors. The slice will be empty if no errors were found.