Documentation ¶
Overview ¶
Package web provides html writing capabilities.
In most cases when writing interactive webapplications you should stick to html/template package. This package however can be suitable when writing documentation or generating websites.
article := Article( Class("fancy"), H1("Title of my article"), ) page := NewPage("", Html(Body(article))) page.WriteTo(os.Stdout)
By default the page is written as html, expected.
<!DOCTYPE html> <html> <body> <article class="fancy"> <h1>Title of my article</h1> </article> </body> </html>
Index ¶
- func CheckLink(file, rel string, n *html.Node, broken chan BrokenLink)
- func CheckLinks(root string, broken chan BrokenLink)
- type Attribute
- func Alt(v string) *Attribute
- func Charset(v string) *Attribute
- func Class(v string) *Attribute
- func Content(v string) *Attribute
- func Href(v string) *Attribute
- func Id(v string) *Attribute
- func Lang(v string) *Attribute
- func Name(v string) *Attribute
- func Rel(v string) *Attribute
- func Src(v string) *Attribute
- func Type(v string) *Attribute
- type BrokenLink
- type Element
- func A(c ...interface{}) *Element
- func Abbr(c ...interface{}) *Element
- func Acronym(c ...interface{}) *Element
- func Address(c ...interface{}) *Element
- func Article(c ...interface{}) *Element
- func Aside(c ...interface{}) *Element
- func B(c ...interface{}) *Element
- func Base(c ...interface{}) *Element
- func Big(c ...interface{}) *Element
- func Blockquote(c ...interface{}) *Element
- func Body(c ...interface{}) *Element
- func Br(c ...interface{}) *Element
- func Button(c ...interface{}) *Element
- func Cite(c ...interface{}) *Element
- func Code(c ...interface{}) *Element
- func Dd(c ...interface{}) *Element
- func Del(c ...interface{}) *Element
- func Details(c ...interface{}) *Element
- func Dfn(c ...interface{}) *Element
- func Div(c ...interface{}) *Element
- func Dl(c ...interface{}) *Element
- func Dt(c ...interface{}) *Element
- func Footer(c ...interface{}) *Element
- func Form(c ...interface{}) *Element
- func H1(c ...interface{}) *Element
- func H2(c ...interface{}) *Element
- func H3(c ...interface{}) *Element
- func H4(c ...interface{}) *Element
- func H5(c ...interface{}) *Element
- func H6(c ...interface{}) *Element
- func Head(c ...interface{}) *Element
- func Header(c ...interface{}) *Element
- func Hgroup(c ...interface{}) *Element
- func Hr(c ...interface{}) *Element
- func Html(c ...interface{}) *Element
- func I(c ...interface{}) *Element
- func Img(c ...interface{}) *Element
- func Input(c ...interface{}) *Element
- func Ins(c ...interface{}) *Element
- func Kbd(c ...interface{}) *Element
- func Keygen(c ...interface{}) *Element
- func Label(c ...interface{}) *Element
- func Legend(c ...interface{}) *Element
- func Li(c ...interface{}) *Element
- func Link(c ...interface{}) *Element
- func Mark(c ...interface{}) *Element
- func Menu(c ...interface{}) *Element
- func Meta(c ...interface{}) *Element
- func Meter(c ...interface{}) *Element
- func Nav(c ...interface{}) *Element
- func NewElement(Name string, childOrAttr ...interface{}) *Element
- func NewSimpleElement(Name string, childOrAttr ...interface{}) *Element
- func Noscript(c ...interface{}) *Element
- func Ol(c ...interface{}) *Element
- func Optgroup(c ...interface{}) *Element
- func Option(c ...interface{}) *Element
- func Output(c ...interface{}) *Element
- func P(c ...interface{}) *Element
- func Pre(c ...interface{}) *Element
- func Quote(c ...interface{}) *Element
- func Script(c ...interface{}) *Element
- func Section(c ...interface{}) *Element
- func Select(c ...interface{}) *Element
- func Span(c ...interface{}) *Element
- func Style(c ...interface{}) *Element
- func Sub(c ...interface{}) *Element
- func Summary(c ...interface{}) *Element
- func Sup(c ...interface{}) *Element
- func Table(c ...interface{}) *Element
- func Tbody(c ...interface{}) *Element
- func Td(c ...interface{}) *Element
- func Textarea(c ...interface{}) *Element
- func Th(c ...interface{}) *Element
- func Thead(c ...interface{}) *Element
- func Title(c ...interface{}) *Element
- func Tr(c ...interface{}) *Element
- func U(c ...interface{}) *Element
- func Ul(c ...interface{}) *Element
- func Var(c ...interface{}) *Element
- type HtmlWriter
- type MarkdownWriter
- type Page
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckLinks ¶
func CheckLinks(root string, broken chan BrokenLink)
Types ¶
type BrokenLink ¶
func (*BrokenLink) String ¶
func (l *BrokenLink) String() string
type Element ¶
type Element struct { Children []interface{} Name string Attributes []*Attribute // contains filtered or unexported fields }
func A ¶
func A(c ...interface{}) *Element
A returns a <a> element with optional children or attributes
func Abbr ¶
func Abbr(c ...interface{}) *Element
Abbr returns a <abbr> element with optional children or attributes
func Acronym ¶
func Acronym(c ...interface{}) *Element
Acronym returns a <acronym> element with optional children or attributes
func Address ¶
func Address(c ...interface{}) *Element
Address returns a <address> element with optional children or attributes
func Article ¶
func Article(c ...interface{}) *Element
Article returns a <article> element with optional children or attributes
func Aside ¶
func Aside(c ...interface{}) *Element
Aside returns a <aside> element with optional children or attributes
func B ¶
func B(c ...interface{}) *Element
B returns a <b> element with optional children or attributes
func Base ¶
func Base(c ...interface{}) *Element
Base returns a <base/> element with optional attributes
func Big ¶
func Big(c ...interface{}) *Element
Big returns a <big> element with optional children or attributes
func Blockquote ¶
func Blockquote(c ...interface{}) *Element
Blockquote returns a <blockquote> element with optional children or attributes
func Body ¶
func Body(c ...interface{}) *Element
Body returns a <body> element with optional children or attributes
func Button ¶
func Button(c ...interface{}) *Element
Button returns a <button> element with optional children or attributes
func Cite ¶
func Cite(c ...interface{}) *Element
Cite returns a <cite> element with optional children or attributes
func Code ¶
func Code(c ...interface{}) *Element
Code returns a <code> element with optional children or attributes
func Dd ¶
func Dd(c ...interface{}) *Element
Dd returns a <dd> element with optional children or attributes
func Del ¶
func Del(c ...interface{}) *Element
Del returns a <del> element with optional children or attributes
func Details ¶
func Details(c ...interface{}) *Element
Details returns a <details> element with optional children or attributes
func Dfn ¶
func Dfn(c ...interface{}) *Element
Dfn returns a <dfn> element with optional children or attributes
func Div ¶
func Div(c ...interface{}) *Element
Div returns a <div> element with optional children or attributes
func Dl ¶
func Dl(c ...interface{}) *Element
Dl returns a <dl> element with optional children or attributes
func Dt ¶
func Dt(c ...interface{}) *Element
Dt returns a <dt> element with optional children or attributes
func Footer ¶
func Footer(c ...interface{}) *Element
Footer returns a <footer> element with optional children or attributes
func Form ¶
func Form(c ...interface{}) *Element
Form returns a <form> element with optional children or attributes
func H1 ¶
func H1(c ...interface{}) *Element
H1 returns a <h1> element with optional children or attributes
func H2 ¶
func H2(c ...interface{}) *Element
H2 returns a <h2> element with optional children or attributes
func H3 ¶
func H3(c ...interface{}) *Element
H3 returns a <h3> element with optional children or attributes
func H4 ¶
func H4(c ...interface{}) *Element
H4 returns a <h4> element with optional children or attributes
func H5 ¶
func H5(c ...interface{}) *Element
H5 returns a <h5> element with optional children or attributes
func H6 ¶
func H6(c ...interface{}) *Element
H6 returns a <h6> element with optional children or attributes
func Head ¶
func Head(c ...interface{}) *Element
Head returns a <head> element with optional children or attributes
func Header ¶
func Header(c ...interface{}) *Element
Header returns a <header> element with optional children or attributes
func Hgroup ¶
func Hgroup(c ...interface{}) *Element
Hgroup returns a <hgroup> element with optional children or attributes
func Html ¶
func Html(c ...interface{}) *Element
Html returns a <html> element with optional children or attributes
func I ¶
func I(c ...interface{}) *Element
I returns a <i> element with optional children or attributes
func Img ¶
func Img(c ...interface{}) *Element
Img returns a <img/> element with optional attributes
func Input ¶
func Input(c ...interface{}) *Element
Input returns a <input/> element with optional attributes
func Ins ¶
func Ins(c ...interface{}) *Element
Ins returns a <ins> element with optional children or attributes
func Kbd ¶
func Kbd(c ...interface{}) *Element
Kbd returns a <kbd> element with optional children or attributes
func Keygen ¶
func Keygen(c ...interface{}) *Element
Keygen returns a <keygen/> element with optional attributes
func Label ¶
func Label(c ...interface{}) *Element
Label returns a <label> element with optional children or attributes
func Legend ¶
func Legend(c ...interface{}) *Element
Legend returns a <legend> element with optional children or attributes
func Li ¶
func Li(c ...interface{}) *Element
Li returns a <li> element with optional children or attributes
func Link ¶
func Link(c ...interface{}) *Element
Link returns a <link/> element with optional attributes
func Mark ¶
func Mark(c ...interface{}) *Element
Mark returns a <mark> element with optional children or attributes
func Menu ¶
func Menu(c ...interface{}) *Element
Menu returns a <menu> element with optional children or attributes
func Meta ¶
func Meta(c ...interface{}) *Element
Meta returns a <meta/> element with optional attributes
func Meter ¶
func Meter(c ...interface{}) *Element
Meter returns a <meter> element with optional children or attributes
func Nav ¶
func Nav(c ...interface{}) *Element
Nav returns a <nav> element with optional children or attributes
func NewElement ¶
func NewSimpleElement ¶
func Noscript ¶
func Noscript(c ...interface{}) *Element
Noscript returns a <noscript> element with optional children or attributes
func Ol ¶
func Ol(c ...interface{}) *Element
Ol returns a <ol> element with optional children or attributes
func Optgroup ¶
func Optgroup(c ...interface{}) *Element
Optgroup returns a <optgroup> element with optional children or attributes
func Option ¶
func Option(c ...interface{}) *Element
Option returns a <option> element with optional children or attributes
func Output ¶
func Output(c ...interface{}) *Element
Output returns a <output> element with optional children or attributes
func P ¶
func P(c ...interface{}) *Element
P returns a <p> element with optional children or attributes
func Pre ¶
func Pre(c ...interface{}) *Element
Pre returns a <pre> element with optional children or attributes
func Quote ¶
func Quote(c ...interface{}) *Element
Quote returns a <quote> element with optional children or attributes
func Script ¶
func Script(c ...interface{}) *Element
Script returns a <script> element with optional children or attributes
func Section ¶
func Section(c ...interface{}) *Element
Section returns a <section> element with optional children or attributes
func Select ¶
func Select(c ...interface{}) *Element
Select returns a <select> element with optional children or attributes
func Span ¶
func Span(c ...interface{}) *Element
Span returns a <span> element with optional children or attributes
func Style ¶
func Style(c ...interface{}) *Element
Style returns a <style> element with optional children or attributes
func Sub ¶
func Sub(c ...interface{}) *Element
Sub returns a <sub> element with optional children or attributes
func Summary ¶
func Summary(c ...interface{}) *Element
Summary returns a <summary> element with optional children or attributes
func Sup ¶
func Sup(c ...interface{}) *Element
Sup returns a <sup> element with optional children or attributes
func Table ¶
func Table(c ...interface{}) *Element
Table returns a <table> element with optional children or attributes
func Tbody ¶
func Tbody(c ...interface{}) *Element
Tbody returns a <tbody> element with optional children or attributes
func Td ¶
func Td(c ...interface{}) *Element
Td returns a <td> element with optional children or attributes
func Textarea ¶
func Textarea(c ...interface{}) *Element
Textarea returns a <textarea> element with optional children or attributes
func Th ¶
func Th(c ...interface{}) *Element
Th returns a <th> element with optional children or attributes
func Thead ¶
func Thead(c ...interface{}) *Element
Thead returns a <thead> element with optional children or attributes
func Title ¶
func Title(c ...interface{}) *Element
Title returns a <title> element with optional children or attributes
func Tr ¶
func Tr(c ...interface{}) *Element
Tr returns a <tr> element with optional children or attributes
func U ¶
func U(c ...interface{}) *Element
U returns a <u> element with optional children or attributes
func Ul ¶
func Ul(c ...interface{}) *Element
Ul returns a <ul> element with optional children or attributes
type HtmlWriter ¶
func NewHtmlWriter ¶
func NewHtmlWriter(w io.Writer) *HtmlWriter
func (*HtmlWriter) WriteHtml ¶
func (p *HtmlWriter) WriteHtml(t interface{}) (int64, error)
type MarkdownWriter ¶
func NewMarkdownWriter ¶
func NewMarkdownWriter(w io.Writer) *MarkdownWriter
func (*MarkdownWriter) WriteMarkdown ¶
func (p *MarkdownWriter) WriteMarkdown(e *Element)
type Page ¶
func (*Page) WriteTo ¶
Example ¶
article := Article( Class("fancy"), H1("Title of my article"), P( "before ", A(Href("http://example.com"), "example"), " after", ), ) page := NewPage("", Html(Body(article))) page.WriteTo(os.Stdout)
Output: <!DOCTYPE html> <html> <body> <article class="fancy"> <h1>Title of my article</h1> <p>before <a href="http://example.com">example</a> after</p> </article> </body> </html>