dot

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 115 Imported by: 0

Documentation

Overview

Package dot provides convenience wrappers for fluent HTML element constructors.

This package is designed to be used with Go's dot import feature, allowing you to write HTML generation code without package prefixes:

import (
    . "github.com/jpl-au/fluent/dot"
    "github.com/jpl-au/fluent/html5/meta"
)

func render() node.Node {
    return Html(
        Head(
            meta.UTF8(),
            Title().Text("My Page"),
            Style().RawText("body { font-family: sans-serif; }"),
        ),
        Body(
            Div(
                H1().Text("Welcome"),
                P().Text("Hello, world!"),
            ).Class("container"),
        ),
    )
}

Function Naming

Each HTML element has a wrapper function matching its tag name:

  • Div(children ...node.Node) - creates a <div> element
  • H1(children ...node.Node) - creates an <h1> element
  • etc.

Specialised constructors (like meta.UTF8()) require importing the element package directly.

Adding Content

Use the .Text() method chain to add text content:

P().Text("Hello, world!")
H1().Class("title").Text("Welcome")
Style().RawText("body { color: red; }")

Content methods available:

  • .Text(s) - adds escaped text content
  • .Textf(format, args...) - adds formatted escaped text
  • .Static(s) - adds static text (JIT-optimisable)
  • .RawText(s) - adds unescaped HTML content
  • .RawTextf(format, args...) - adds formatted unescaped HTML

Alternative: Package Imports

If you prefer explicit package prefixes, import element packages directly:

import "github.com/jpl-au/fluent/html5/div"

el := div.New().Class("container").Text("Hello")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func A

func A(nodes ...node.Node) *a.Element

A creates a new anchor element without any initial attributes. Example: A(text.Text("Click here")).Href("https://example.com") Renders: <a href="https://example.com">Click here</a>

func Abbr

func Abbr(nodes ...node.Node) *abbr.Element

Abbr creates a new abbreviation element without any initial attributes. Use for basic abbreviations where semantic markup is needed. Example: Abbr() Renders: <abbr></abbr>

func Address

func Address(nodes ...node.Node) *address.Element

Address creates a new address element without any initial attributes. Use for basic contact information where semantic markup is needed. Example: Address() Renders: <address></address>

func Area

func Area() *area.Element

Area creates a new area element without any initial attributes. Example: Area() Renders: <area />

func Article

func Article(nodes ...node.Node) *article.Element

Article creates a new article element with optional child nodes Example: Article() Renders: <article></article>

func Aside

func Aside(nodes ...node.Node) *aside.Element

Aside creates a new aside element with the given child nodes. Example: Aside() Renders: <aside></aside>

func Audio

func Audio(nodes ...node.Node) *audio.Element

Audio creates a new audio element without any initial attributes. Example: Audio() Renders: <audio></audio>

func B

func B(nodes ...node.Node) *b.Element

B creates a new b element with the given child nodes. Example: B(text.Text("This text is important.")) Renders: <b>This text is important.</b>

func Base

func Base() *base.Element

Base creates a new base element without any initial attributes. Example: Base().Href("/docs/") Renders: <base href="/docs/" />

func Bdi

func Bdi(nodes ...node.Node) *bdi.Element

Bdi creates a new bdi element with the given child nodes. Example: Bdi(text.Text("username")) Renders: <bdi>username</bdi>

func Bdo

func Bdo(nodes ...node.Node) *bdo.Element

Bdo creates a new bdo element with child nodes. Example: Bdo(text.Text("Hello")) Renders: <bdo>Hello</bdo>

func Blockquote

func Blockquote(nodes ...node.Node) *blockquote.Element

Blockquote creates a new blockquote element with the given child nodes. Example: Blockquote(p.Text("To be or not to be.")) Renders: <blockquote><p>To be or not to be.</p></blockquote>

func Body

func Body(nodes ...node.Node) *body.Element

Body creates a new body element with the given child nodes. Example: Body(p.New(text.Text("Hello, World!"))) Renders: <body><p>Hello, World!</p></body>

func Br

func Br() *br.Element

Br creates a new br element without any initial attributes. Example: Br() Renders: <br />

func Button

func Button(nodes ...node.Node) *button.Element

Button creates a new button element with the given child nodes. Example: Button(text.Text("Click Me")) Renders: <button>Click Me</button>

func Canvas

func Canvas(nodes ...node.Node) *canvas.Element

Canvas creates a new canvas element with child nodes for fallback content. Example: Canvas(text.Text("Your browser does not support canvas.")) Renders: <canvas>Your browser does not support canvas.</canvas>

func Caption

func Caption(nodes ...node.Node) *caption.Element

Caption creates a new caption element with the given child nodes. Example: Caption(text.Text("My Table Caption")) Renders: <caption>My Table Caption</caption>

func Cite

func Cite(nodes ...node.Node) *cite.Element

Cite creates a new cite element with the given child nodes. Example: Cite(text.Text("Nineteen Eighty-Four")) Renders: <cite>Nineteen Eighty-Four</cite>

func Code

func Code(nodes ...node.Node) *code.Element

Code creates a new code element with the given child nodes. Example: Code(text.Text("console.log('Hello, World!');")) Renders: <code>console.log('Hello, World!');</code>

func Col

func Col() *col.Element

Col creates a new col element without any initial attributes. Example: Col() Renders: <col />

func Colgroup

func Colgroup(nodes ...node.Node) *colgroup.Element

Colgroup creates a new colgroup element with the given child nodes (typically <col> elements). Example: Colgroup(col.New(), col.Span(2)) Renders: <colgroup><col /><col span="2" /></colgroup>

func Data

func Data(nodes ...node.Node) *data.Element

Data creates a new data element with the given child nodes. Example: Data(text.Text("Mini Ketchup")) Renders: <data>Mini Ketchup</data>

func Datalist

func Datalist(nodes ...node.Node) *datalist.Element

Datalist creates a new datalist element with child nodes (typically <option> elements). Example: Datalist(option.New().Value("Chocolate"), option.New().Value("Vanilla")) Renders: <datalist><option value="Chocolate"><option value="Vanilla"></datalist>

func Dd

func Dd(nodes ...node.Node) *dd.Element

Dd creates a new dd element with child nodes. Example: Dd(text.Text("A large feline inhabiting Bodmin Moor.")) Renders: <dd>A large feline inhabiting Bodmin Moor.</dd>

func Del

func Del(nodes ...node.Node) *del.Element

Del creates a new del element with optional child nodes. Example: Del() Renders: <del></del>

func Details

func Details(nodes ...node.Node) *details.Element

Details creates a new details element with the given child nodes. Example: Details(summary.Text("Details"), p.Text("Hidden content")) Renders: <details><summary>Details</summary><p>Hidden content</p></details>

func Dfn

func Dfn(nodes ...node.Node) *dfn.Element

Dfn creates a new dfn element with the given child nodes. Example: Dfn(text.Text("validator")) Renders: <dfn>validator</dfn>

func Dialog

func Dialog(nodes ...node.Node) *dialog.Element

Dialog creates a new dialog element with the given child nodes. Example: Dialog(p.Text("Greetings, one and all!")) Renders: <dialog><p>Greetings, one and all!</p></dialog>

func Div

func Div(nodes ...node.Node) *div.Element

Div creates a new div element with child nodes. Example: Div(p.New(text.Text("Any kind of content here."))) Renders: <div><p>Any kind of content here.</p></div>

func Dl

func Dl(nodes ...node.Node) *dl.Element

Dl creates a new dl element with the given child nodes (typically <dt> and <dd> elements). Example: Dl(dt.New(text.Text("Term")), dd.New(text.Text("Description"))) Renders: <dl><dt>Term</dt><dd>Description</dd></dl>

func Dropdown(nodes ...node.Node) *dropdown.Element

Dropdown creates a new select element with option and optgroup child elements. Example: Dropdown(option.Option("Red", "red"), option.Option("Blue", "blue")) Renders: <select><option value="red">Red</option><option value="blue">Blue</option></select>

func Dt

func Dt(nodes ...node.Node) *dt.Element

Dt creates a new dt element with the given child nodes. Example: Dt(text.Text("Term")) Renders: <dt>Term</dt>

func Em

func Em(nodes ...node.Node) *em.Element

Em creates a new em element with the given child nodes. Example: Em(text.Text("now")) Renders: <em>now</em>

func Embed

func Embed() *embed.Element

Embed creates a new embed element without any initial attributes. Example: Embed() Renders: <embed />

func Fieldset

func Fieldset(nodes ...node.Node) *fieldset.Element

Fieldset creates a new fieldset element with child nodes. Example: Fieldset(legend.Text("Personal details"), input.Text("name", "")) Renders: <fieldset><legend>Personal details</legend><input name="name" type="text" /></fieldset>

func Figcaption

func Figcaption(nodes ...node.Node) *figcaption.Element

Figcaption creates a new figcaption element with child nodes. Example: Figcaption(text.Text("An elephant at sunset")) Renders: <figcaption>An elephant at sunset</figcaption>

func Figure

func Figure(nodes ...node.Node) *figure.Element

Figure creates a new figure element with the given child nodes. Example: Figure(img.New().Src("elephant.jpg"), figcaption.New(text.Text("An elephant at sunset"))) Renders: <figure><img src="elephant.jpg" /><figcaption>An elephant at sunset</figcaption></figure>

func Footer(nodes ...node.Node) *footer.Element

Footer creates a new footer element with the given child nodes. Example: Footer(p.New(text.Text("Copyright 2023 My Website"))) Renders: <footer><p>Copyright 2023 My Website</p></footer>

func Form

func Form(nodes ...node.Node) *form.Element

Form creates a new form element with child nodes. Example: Form(input.Text("name", ""), button.Submit("Send")) Renders: <form><input name="name" type="text" /><button type="submit">Send</button></form>

func H1

func H1(nodes ...node.Node) *h1.Element

H1 creates a new h1 element with the given child nodes. Example: H1(text.Text("Page Title")) Renders: <h1>Page Title</h1>

func H2

func H2(nodes ...node.Node) *h2.Element

H2 creates a new h2 element with the given child nodes. Example: H2(text.Text("Section Title")) Renders: <h2>Section Title</h2>

func H3

func H3(nodes ...node.Node) *h3.Element

H3 creates a new h3 element with the given child nodes. Example: H3(text.Text("Subsection Title")) Renders: <h3>Subsection Title</h3>

func H4

func H4(nodes ...node.Node) *h4.Element

H4 creates a new h4 element with the given child nodes. Example: H4(text.Text("Detailed Point")) Renders: <h4>Detailed Point</h4>

func H5

func H5(nodes ...node.Node) *h5.Element

H5 creates a new h5 element with the given child nodes. Example: H5(text.Text("Sub-point")) Renders: <h5>Sub-point</h5>

func H6

func H6(nodes ...node.Node) *h6.Element

H6 creates a new h6 element with the given child nodes. Example: H6(text.Text("Footnote Title")) Renders: <h6>Footnote Title</h6>

func Head(nodes ...node.Node) *head.Element

Head creates a new head element with the given child nodes (metadata content). Example: Head(title.New(text.Text("My Page")), meta.Charset("UTF-8")) Renders: <head><title>My Page</title><meta charset="UTF-8" /></head>

func Header(nodes ...node.Node) *header.Element

Header creates a new header element with the given child nodes. Example: Header(h1.Text("Welcome"), p.Text("A brief introduction")) Renders: <header><h1>Welcome</h1><p>A brief introduction</p></header>

func Hgroup

func Hgroup(nodes ...node.Node) *hgroup.Element

Hgroup creates a new hgroup element with child nodes (typically a heading and subtitle paragraphs). Example: Hgroup(h1.Text("Main Title"), p.Text("A subtitle")) Renders: <hgroup><h1>Main Title</h1><p>A subtitle</p></hgroup>

func Hr

func Hr() *hr.Element

Hr creates a new hr element without any initial attributes. Example: Hr() Renders: <hr />

func Html

func Html(nodes ...node.Node) *html.Element

Html creates a complete HTML5 document with DOCTYPE declaration Example: Html() Renders: <!DOCTYPE html><html></html>

func I

func I(nodes ...node.Node) *i.Element

I creates a new italic element with optional child nodes. Example: I() Renders: <i></i>

func Iframe

func Iframe(nodes ...node.Node) *iframe.Element

Iframe creates a new iframe element with optional fallback content. Example: Iframe().Src("/page.html") Renders: <iframe src="/page.html"></iframe>

func Imagemap

func Imagemap(nodes ...node.Node) *imagemap.Element

Imagemap creates a new map element with optional child nodes (typically area elements). Example: Imagemap(area.Rect(0, 0, 100, 50, "/page1")) Renders: <map><area shape="rect" coords="0,0,100,50" href="/page1" /></map>

func Img

func Img() *img.Element

Img creates a new img element without any initial attributes. Example: Img().Src("photo.jpg").Alt("A beautiful sunset") Renders: <img src="photo.jpg" alt="A beautiful sunset" />

func Input

func Input() *input.Element

Input creates a new input element without any initial attributes. Example: Input().Type(inputtype.Text).Name("username") Renders: <input name="username" type="text" />

func Ins

func Ins(nodes ...node.Node) *ins.Element

Ins creates a new ins element with optional child nodes. Example: Ins() Renders: <ins></ins>

func Kbd

func Kbd(nodes ...node.Node) *kbd.Element

Kbd creates a new kbd element with optional child nodes. Example: Kbd() Renders: <kbd></kbd>

func Label

func Label(nodes ...node.Node) *label.Element

Label creates a new label element with child nodes. Example: Label() Renders: <label></label>

func Legend

func Legend(nodes ...node.Node) *legend.Element

Legend creates a new legend element with optional child nodes. Example: Legend() Renders: <legend></legend>

func Li

func Li(nodes ...node.Node) *li.Element

Li creates a new list item element with optional child nodes. Example: Li() Renders: <li></li>

func Link() *link.Element

Link creates a new link element without any initial attributes. Example: Link() Renders: <link />

func Mark

func Mark(nodes ...node.Node) *mark.Element

Mark creates a new mark element with the given child nodes. Example: Mark(text.Text("highlighted text")) Renders: <mark>highlighted text</mark>

func Math

func Math(nodes ...node.Node) *math.Element

Math creates a new math element with optional child nodes. Example: Math() Renders: <math></math>

func Menu(nodes ...node.Node) *menu.Element

Menu creates a new menu element with child li elements. Example: Menu(li.Text("Cut"), li.Text("Copy"), li.Text("Paste")) Renders: <menu><li>Cut</li><li>Copy</li><li>Paste</li></menu>

func Meta

func Meta() *meta.Element

Meta creates a new meta element without any initial attributes. Example: Meta() Renders: <meta />

func Meter

func Meter(nodes ...node.Node) *meter.Element

Meter creates a new meter element with optional child nodes Example: Meter() Renders: <meter></meter>

func Nav(nodes ...node.Node) *nav.Element

Nav creates a new nav element with optional child nodes Example: Nav() Renders: <nav></nav>

func Noscript

func Noscript(nodes ...node.Node) *noscript.Element

Noscript creates a new noscript element with optional child nodes Example: Noscript() Renders: <noscript></noscript>

func Object

func Object(nodes ...node.Node) *object.Element

Object creates a new object element with optional child nodes Example: Object() Renders: <object></object>

func Ol

func Ol(nodes ...node.Node) *ol.Element

Ol creates a new ordered list element with optional child nodes (typically li elements) Example: Ol() Renders: <ol></ol>

func Optgroup

func Optgroup(nodes ...node.Node) *optgroup.Element

Optgroup creates a new optgroup element with child option elements. Example: Optgroup(option.Option("red", "Red"), option.Option("blue", "Blue")).Label("Colours") Renders: <optgroup label="Colours"><option value="red">Red</option><option value="blue">Blue</option></optgroup>

func Option

func Option(nodes ...node.Node) *option.Element

Option creates a new option element with optional child nodes Example: Option() Renders: <option></option>

func Output

func Output(nodes ...node.Node) *output.Element

Output creates a new output element with optional child nodes Example: Output() Renders: <output></output>

func P

func P(nodes ...node.Node) *p.Element

P creates a new paragraph element with optional child nodes Example: P(text.Text("Hello")) Renders: <p>Hello</p>

func Picture

func Picture(nodes ...node.Node) *picture.Element

Picture creates a new picture element with source and img child elements. Example: Picture(source.ImageWebP("photo.webp"), img.Src("photo.jpg")) Renders: <picture><source srcset="photo.webp" type="image/webp"><img src="photo.jpg"></picture>

func Pre

func Pre(nodes ...node.Node) *pre.Element

Pre creates a new pre element with the given child nodes Example: Pre(text.Text("Code")) Renders: <pre>Code</pre>

func Primary

func Primary(nodes ...node.Node) *primary.Element

Primary creates a new main element with optional child nodes Example: Primary() Renders: <main></main>

func Progress

func Progress(nodes ...node.Node) *progress.Element

Progress creates a new progress element with optional child nodes for fallback content. Example: Progress() Renders: <progress></progress>

func Q

func Q(nodes ...node.Node) *q.Element

Q creates a new q element with optional child nodes. Example: Q(text.Text("To be or not to be")) Renders: <q>To be or not to be</q>

func Rp

func Rp(nodes ...node.Node) *rp.Element

Rp creates a new rp element with optional child nodes. Example: Rp(text.Text("(")) Renders: <rp>(</rp>

func Rt

func Rt(nodes ...node.Node) *rt.Element

Rt creates a new rt element with optional child nodes Example: Rt(text.Text("kan")) Renders: <rt>kan</rt>

func Ruby

func Ruby(nodes ...node.Node) *ruby.Element

Ruby creates a new ruby element with optional child nodes Example: Ruby(text.Text("漢字")) Renders: <ruby>漢字</ruby>

func S

func S(nodes ...node.Node) *s.Element

S creates a new s element with optional child nodes. Examples: S() renders <s></s> S(text.Text("Old price: $100")) renders <s>Old price: $100</s>

func Samp

func Samp(nodes ...node.Node) *samp.Element

Samp creates a new samp element with optional child nodes Example: Samp(text.Text("Output")) Renders: <samp>Output</samp>

func Script

func Script(nodes ...node.Node) *script.Element

Script creates a new script element without any initial attributes Example: Script() Renders: <script></script>

func Search(nodes ...node.Node) *search.Element

Search creates a new search element with optional child nodes Example: Search() Renders: <search></search>

func Section

func Section(nodes ...node.Node) *section.Element

Section creates a new section element with optional child nodes Example: Section() Renders: <section></section>

func Slot

func Slot(nodes ...node.Node) *slot.Element

Slot creates a new slot element with optional child nodes. Example: Slot() Renders: <slot></slot>

func Small

func Small(nodes ...node.Node) *small.Element

Small creates a new small element with the given child nodes. Example: Small(text.Text("© 2024 Company Name")) Renders: <small>© 2024 Company Name</small>

func Source

func Source() *source.Element

Source creates a new source element without any initial attributes. Example: Source().Src("image.webp").Type("image/webp") Renders: <source src="image.webp" type="image/webp" />

func Span

func Span(nodes ...node.Node) *span.Element

Span creates a new span element with optional child nodes. Example: Span() Renders: <span></span>

func Strong

func Strong(nodes ...node.Node) *strong.Element

Strong creates a new strong element with optional child nodes. Example: Strong() Renders: <strong></strong>

func Style

func Style(nodes ...node.Node) *style.Element

Style creates a new style element without any initial attributes. Example: Style() Renders: <style></style>

func Sub

func Sub(nodes ...node.Node) *sub.Element

Sub creates a new sub element with the given child nodes. Example: Sub(text.Text("2")) Renders: <sub>2</sub>

func Summary

func Summary(nodes ...node.Node) *summary.Element

Summary creates a new summary element with optional child nodes. Example: Summary() Renders: <summary></summary>

func Sup

func Sup(nodes ...node.Node) *sup.Element

Sup creates a new sup element with the given child nodes. Example: Sup(text.Text("2")) Renders: <sup>2</sup>

func Svg

func Svg(nodes ...node.Node) *svg.Element

Svg creates a new svg element with child SVG elements. Example: Svg().Width("100").Height("100").ViewBox("0 0 100 100") Renders: <svg width="100" height="100" viewBox="0 0 100 100"></svg>

func Table

func Table(nodes ...node.Node) *table.Element

Table creates a new table element with optional child nodes (typically thead, tbody, tfoot, tr elements). Example: Table() Renders: <table></table>

func Tbody

func Tbody(nodes ...node.Node) *tbody.Element

Tbody creates a new tbody element with child tr elements. Example: Tbody(tr.New(td.Text("cell"))) Renders: <tbody><tr><td>cell</td></tr></tbody>

func Td

func Td(nodes ...node.Node) *td.Element

Td creates a new table data cell element with optional child nodes. Example: Td() Renders: <td></td>

func Template

func Template(nodes ...node.Node) *template.Element

Template creates a new template element with child nodes. Content is not rendered directly but can be instantiated at runtime using JavaScript. Example: Template() Renders: <template></template>

func Textarea

func Textarea(nodes ...node.Node) *textarea.Element

Textarea creates a new textarea element with optional child nodes Example: Textarea() Renders: <textarea></textarea>

func Tfoot

func Tfoot(nodes ...node.Node) *tfoot.Element

Tfoot creates a new tfoot element with child tr elements. Example: Tfoot(tr.New(td.Text("Total"), td.Text("100"))) Renders: <tfoot><tr><td>Total</td><td>100</td></tr></tfoot>

func Th

func Th(nodes ...node.Node) *th.Element

Th creates a new th element with optional child nodes. Example: Th() Renders: <th></th>

func Thead

func Thead(nodes ...node.Node) *thead.Element

Thead creates a new thead element with child tr elements. Example: Thead(tr.New(th.Text("Name"), th.Text("Age"))) Renders: <thead><tr><th>Name</th><th>Age</th></tr></thead>

func Time

func Time(nodes ...node.Node) *time.Element

Time creates a new time element with optional child nodes Example: Time() Renders: <time></time>

func Title

func Title(nodes ...node.Node) *title.Element

Title creates a new title element with text content Example: Title() Renders: <title></title>

func Tr

func Tr(nodes ...node.Node) *tr.Element

Tr creates a new table row element with optional child nodes (typically td or th elements). Example: Tr() Renders: <tr></tr>

func Track

func Track() *track.Element

Track creates a new track element without any initial attributes. Example: Track() Renders: <track />

func U

func U(nodes ...node.Node) *u.Element

U creates a new u element with the given child nodes. Example: U(text.Text("misspelled"))

func Ul

func Ul(nodes ...node.Node) *ul.Element

Ul creates a new unordered list element with optional child nodes (typically li elements). Example: Ul() Renders: <ul></ul>

func Variable

func Variable(nodes ...node.Node) *variable.Element

Variable creates a new var element with optional child nodes. Example: Variable() Renders: <var></var>

func Video

func Video(nodes ...node.Node) *video.Element

Video creates a new video element with optional child nodes Example: Video() Renders: <video></video>

func Wbr

func Wbr() *wbr.Element

Wbr creates a new wbr element without any initial attributes. Example: Wbr() Renders: <wbr />

Types

This section is empty.

Jump to

Keyboard shortcuts

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