nodx

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 5 Imported by: 3

README

NodX for Go

Go Reference Go Report Card Release Version License

NodX is a modern and developer-friendly Go template engine for generating safe, clean, and maintainable HTML. Designed for maximum productivity and easy maintenance, it combines simplicity, type safety and robust formatting, making it the perfect fit for your Go-based web projects.

Key Features

  • Type Safety 🛡️: Fully typed APIs ensure you write error-free HTML, even at scale.
  • Robust Formatting 🧹: Works seamlessly with go fmt to keep your code clean and consistent.
  • Zero Dependencies 📦: Lightweight and fast, with no external dependencies.
  • DX in mind 🧠: If you can write HTML and Go, you can write NodX.
  • Security by Default 🔒: Automatically escapes unsafe text to prevent XSS vulnerabilities.

Quick Start

Install the library:

# Go 1.22 or later is required
go get github.com/nodxdev/nodxgo

Start building your HTML with intuitive, type-safe functions:

package main

import (
  "os"
  "github.com/nodxdev/nodxgo"
)

func main() {
  // you can fetch this from a database or some other source
  happiness := 100
  hideContainer := false

  myTemplate := nodx.Group(
    nodx.DocType(),
    nodx.Html(
      nodx.Head(
        nodx.TitleEl(nodx.Text("My NodX Page")),
      ),
      nodx.Body(
        nodx.Div(
          nodx.ClassMap{
            "container": true,
            "hidden":    hideContainer,
          },
          nodx.H1(
            nodx.Class("title"),
            nodx.Textf("Welcome to %s!", "NodX"),
          ),
          nodx.P(nodx.Text("This is a type-safe HTML generator for Go.")),
          nodx.If(happiness > 90, nodx.P(nodx.Textf("With NodX, you will be %d%% happy!", happiness))),
        ),
      ),
    ),
  )

  _ = myTemplate.Render(os.Stdout)
  // or
  // str, err := myTemplate.RenderString()
  // byt, err := myTemplate.RenderBytes()
}
Output:
<!DOCTYPE html>
<html>
  <head>
    <title>My NodX Page</title>
  </head>
  <body>
    <div class="container">
      <h1 class="title">Welcome to NodX!</h1>
      <p>This is a type-safe HTML generator for Go.</p>
      <p>With NodX, you will be 100% happy!</p>
    </div>
  </body>
</html>

Key Concepts

1. Elements made easy

Every HTML tag is a function! Just call the function with child elements, attributes, groups or text.

nodx.Div(
  nodx.Class("container"),
  nodx.H1(nodx.Text("Hello, NodX!")),
  nodx.P(nodx.Text("Build clean and safe HTML effortlessly.")),
)
2. Attributes with helpers

Attributes like class, src, and alt have their own functions for simplicity.

nodx.Img(
  nodx.Src("image.jpg"),
  nodx.Alt("A beautiful image"),
)
3. Dynamic class management

Use ClassMap to conditionally apply classes based on your logic.

nodx.Div(
  nodx.ClassMap{
    "visible": true,
    "hidden":  false,
  },
  nodx.Text("Conditional classes made simple!"),
)
4. Fully typed server rendered components

You can create your own components to avoid code duplication and keep your code clean.

func button(text string) nodx.Node {
  return nodx.Button(
    nodx.Class("btn"),
    nodx.Text(text),
  )
}

func main() {
  myTemplate := nodx.Div(
    button("Click me 1!"),
    button("Click me 2!"),
    button("Click me 3!"),
  )

  _ := myTemplate.Render(os.Stdout)

  /*
    Output:
    <div>
      <button class="btn">Click me 1!</button>
      <button class="btn">Click me 2!</button>
      <button class="btn">Click me 3!</button>
    </div>
  */
}
5. Advanced features

Please refer to the Full Documentation to read more about all the included features.

  • Custom components: You can create your own components to avoid code duplication and keep your code clean.
  • Conditional rendering: You can use the nodx.If and nodx.IfFunc function to conditionally render elements based on your logic.
  • Map: You can use the nodx.Map function to loop over a list of items and render them as a list of Nodes.
  • Custom elements and attributes: You can use nodx.El and nodx.Attr to create your own elements and attributes if they are not included in the library.
  • Component library: You can write your own component library and publish it for others to use.
  • Dynamic classes and styles: You can use the nodx.ClassMap and nodx.StyleMap to conditionally apply classes and styles based on your own logic.

Why Choose NodX?

  • Expressive and Clear Code: Great helpers (Div, H1, P, etc.) that mirror HTML semantics, making your Go code as readable as HTML.
  • Battle-Tested for Safety: Text is escaped automatically to protect your app from XSS vulnerabilities.
  • Lightweight and Efficient: With no dependencies, you can focus on building without bloat.
  • Perfect for Modern Go Developers: Designed with Go's simplicity and elegance in mind.

License

NodX is open-source and available under the MIT License. Feel free to use it in your personal or commercial projects.


Start building safe, elegant, and maintainable HTML templates in Go today with NodX!

Documentation

Overview

Package nodx is a modern and developer-friendly Go template engine for generating safe, clean, and maintainable HTML. Designed for maximum productivity and easy maintenance, it combines simplicity, type safety and robust formatting, making it the perfect fit for your Go-based web projects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeHTML

func EscapeHTML(input string) string

EscapeHTML escapes the input string to prevent XSS attacks.

Types

type ClassMap

type ClassMap map[string]bool

ClassMap represents a map of class names with conditional rendering. The keys are the class names, and the values are boolean expressions (conditions) that determine whether each class should be included in the final output.

Example:

isOdd := func(n int) bool { return n % 2 != 0 }
isEven := func(n int) bool { return n % 2 == 0 }

renderOdd := isOdd(3)   // true
renderEven := isEven(3) // false

cm := ClassMap{
	"odd-class":  renderOdd,      // Included
	"even-class": renderEven,     // Excluded
	"always-on":  true,           // Always included
}

This will render the class attribute as: class="odd-class always-on"

func (ClassMap) Render

func (cm ClassMap) Render(w io.Writer) error

Render writes the "class" attribute to the provided writer. It includes only the class names with a `true` value, sorted alphabetically.

func (ClassMap) RenderBytes

func (cm ClassMap) RenderBytes() ([]byte, error)

RenderBytes returns the "class" attribute as a byte slice. It includes only the class names with a `true` value, sorted alphabetically.

func (ClassMap) RenderString

func (cm ClassMap) RenderString() (string, error)

RenderString returns the "class" attribute as a string. It includes only the class names with a `true` value, sorted alphabetically.

type Node

type Node interface {
	// Render writes the node HTML to the writer.
	Render(w io.Writer) error

	// RenderString returns the node HTML as a string.
	RenderString() (string, error)

	// RenderBytes returns the node HTML as a byte slice.
	RenderBytes() ([]byte, error)
}

Node is the interface that wraps the basic Render methods used in the different NodX node types.

func A

func A(children ...Node) Node

A Defines a hyperlink.

Output: <a ...>...</a>

func Abbr

func Abbr(children ...Node) Node

Abbr Defines an abbreviation or acronym.

Output: <abbr ...>...</abbr>

func Accept

func Accept(value string) Node

Accept Specifies the types of files that the server accepts (only for input type='file').

Output: accept="{value}"

func AcceptCharset

func AcceptCharset(value string) Node

AcceptCharset Specifies the character encodings to be used for form submission.

Output: accept-charset="{value}"

func Accesskey

func Accesskey(value string) Node

Accesskey Specifies a shortcut key to activate/focus an element.

Output: accesskey="{value}"

func Action

func Action(value string) Node

Action Specifies where to send the form-data when a form is submitted.

Output: action="{value}"

func Address

func Address(children ...Node) Node

Address Defines contact information for the author/owner of a document.

Output: <address ...>...</address>

func Align

func Align(value string) Node

Align Specifies the alignment of the element's content.

Output: align="{value}"

func Allow

func Allow(value string) Node

Allow Specifies a feature policy for the iframe.

Output: allow="{value}"

func Alt

func Alt(value string) Node

Alt Provides alternative text for an image if it cannot be displayed.

Output: alt="{value}"

func Applet

func Applet(children ...Node) Node

Applet Defines an embedded applet (deprecated).

Output: <applet ...>...</applet>

func Area

func Area(children ...Node) Node

Area Defines an area inside an image-map.

Output: <area .../>

func Aria

func Aria(key string, value string) Node

Aria Defines accessibility semantics or ARIA properties.

Output: aria-{key}="{value}"

func Article

func Article(children ...Node) Node

Article Defines an article.

Output: <article ...>...</article>

func Aside

func Aside(children ...Node) Node

Aside Defines content aside from the page content.

Output: <aside ...>...</aside>

func Async

func Async(value string) Node

Async Indicates that the script should be executed asynchronously.

Output: async="{value}"

func Attr

func Attr(name string, value string) Node

Attr creates a new Node representing an HTML attribute with a name and value. The value is HTML-escaped to prevent XSS attacks.

func Audio

func Audio(children ...Node) Node

Audio Defines embedded sound content.

Output: <audio ...>...</audio>

func Autocapitalize

func Autocapitalize(value string) Node

Autocapitalize Controls how text input is automatically capitalized.

Output: autocapitalize="{value}"

func Autocomplete

func Autocomplete(value string) Node

Autocomplete Specifies whether an input field should have autocomplete enabled.

Output: autocomplete="{value}"

func Autofocus

func Autofocus(value string) Node

Autofocus Specifies that an input field should automatically get focus when the page loads.

Output: autofocus="{value}"

func Autoplay

func Autoplay(value string) Node

Autoplay Specifies that the audio/video should start playing as soon as it is ready.

Output: autoplay="{value}"

func B

func B(children ...Node) Node

B Defines bold text.

Output: <b ...>...</b>

func Background

func Background(value string) Node

Background Specifies a background image for the element.

Output: background="{value}"

func Base

func Base(children ...Node) Node

Base Specifies the base URL for all relative URLs in a document.

Output: <base .../>

func Basefont

func Basefont(children ...Node) Node

Basefont Specifies a default color, size, and font for all text in a document (deprecated).

Output: <basefont ...>...</basefont>

func Bdi

func Bdi(children ...Node) Node

Bdi Isolates a part of text that might be formatted in a different direction from other text.

Output: <bdi ...>...</bdi>

func Bdo

func Bdo(children ...Node) Node

Bdo Overrides the current text direction.

Output: <bdo ...>...</bdo>

func Bgcolor

func Bgcolor(value string) Node

Bgcolor Specifies the background color of an element.

Output: bgcolor="{value}"

func Blockquote

func Blockquote(children ...Node) Node

Blockquote Defines a section that is quoted from another source.

Output: <blockquote ...>...</blockquote>

func Body

func Body(children ...Node) Node

Body Defines the body of the document.

Output: <body ...>...</body>

func Border

func Border(value string) Node

Border Specifies the border width.

Output: border="{value}"

func Br

func Br(children ...Node) Node

Br Inserts a single line break.

Output: <br .../>

func Buffered

func Buffered(value string) Node

Buffered Contains the time ranges that the media element has buffered.

Output: buffered="{value}"

func Button

func Button(children ...Node) Node

Button Defines a clickable button.

Output: <button ...>...</button>

func Canvas

func Canvas(children ...Node) Node

Canvas Used to draw graphics on the fly via scripting.

Output: <canvas ...>...</canvas>

func Caption

func Caption(children ...Node) Node

Caption Defines a table caption.

Output: <caption ...>...</caption>

func Capture

func Capture(value string) Node

Capture Specifies that the camera should be used for input.

Output: capture="{value}"

func Center

func Center(children ...Node) Node

Center Defines centered text (deprecated).

Output: <center ...>...</center>

func Challenge

func Challenge(value string) Node

Challenge Specifies that the value of the keygen element should be challenged when submitted.

Output: challenge="{value}"

func Charset

func Charset(value string) Node

Charset Specifies the character encoding.

Output: charset="{value}"

func Checked

func Checked(value string) Node

Checked Specifies that an input element should be pre-selected when the page loads.

Output: checked="{value}"

func CiteAttr

func CiteAttr(value string) Node

CiteAttr Specifies a URL that explains the quote, or why a text was inserted/deleted.

Output: cite="{value}"

func CiteEl

func CiteEl(children ...Node) Node

CiteEl Defines the title of a work.

Output: <cite ...>...</cite>

func Class

func Class(value string) Node

Class Specifies one or more class names for an element.

Output: class="{value}"

func CodeAttr

func CodeAttr(value string) Node

CodeAttr Specifies the URL of the applet's class file to be loaded and executed.

Output: code="{value}"

func CodeEl

func CodeEl(children ...Node) Node

CodeEl Defines a piece of computer code.

Output: <code ...>...</code>

func Codebase

func Codebase(value string) Node

Codebase Specifies the base URL for an applet.

Output: codebase="{value}"

func Col

func Col(children ...Node) Node

Col Specifies column properties for each column within a colgroup element.

Output: <col .../>

func Colgroup

func Colgroup(children ...Node) Node

Colgroup Specifies a group of one or more columns in a table for formatting.

Output: <colgroup ...>...</colgroup>

func Color

func Color(value string) Node

Color Specifies the text color of an element.

Output: color="{value}"

func Cols

func Cols(value string) Node

Cols Specifies the visible width of a text area.

Output: cols="{value}"

func Colspan

func Colspan(value string) Node

Colspan Specifies the number of columns a cell should span.

Output: colspan="{value}"

func Content

func Content(value string) Node

Content Gives the value associated with the http-equiv or name attribute.

Output: content="{value}"

func Contenteditable

func Contenteditable(value string) Node

Contenteditable Specifies whether the content of an element is editable.

Output: contenteditable="{value}"

func Contextmenu

func Contextmenu(value string) Node

Contextmenu Specifies a context menu for an element.

Output: contextmenu="{value}"

func Controls

func Controls(value string) Node

Controls Specifies that audio/video controls should be displayed.

Output: controls="{value}"

func Coords

func Coords(value string) Node

Coords Specifies the coordinates of an area in an image-map.

Output: coords="{value}"

func Crossorigin

func Crossorigin(value string) Node

Crossorigin Configures the CORS requests for the element's fetched data.

Output: crossorigin="{value}"

func Csp

func Csp(value string) Node

Csp Allows specifying a Content Security Policy for the content in the iframe.

Output: csp="{value}"

func Data

func Data(key string, value string) Node

Data Used to store custom data private to the page or application.

Output: data-{key}="{value}"

func DataAttr

func DataAttr(value string) Node

DataAttr Specifies the URL of the resource to be used by the object.

Output: data="{value}"

func DataEl

func DataEl(children ...Node) Node

DataEl Links the given content with a machine-readable translation.

Output: <data ...>...</data>

func Datalist

func Datalist(children ...Node) Node

Datalist Specifies a list of pre-defined options for input controls.

Output: <datalist ...>...</datalist>

func Datetime

func Datetime(value string) Node

Datetime Specifies the date and time.

Output: datetime="{value}"

func Dd

func Dd(children ...Node) Node

Dd Defines a description/value of a term in a description list.

Output: <dd ...>...</dd>

func Decoding

func Decoding(value string) Node

Decoding Indicates how the browser should load the image.

Output: decoding="{value}"

func Default

func Default(value string) Node

Default Specifies the default track kind.

Output: default="{value}"

func Defer

func Defer(value string) Node

Defer Specifies that the script is executed when the page has finished parsing.

Output: defer="{value}"

func Del

func Del(children ...Node) Node

Del Defines text that has been deleted from a document.

Output: <del ...>...</del>

func Details

func Details(children ...Node) Node

Details Defines additional details that the user can view or hide.

Output: <details ...>...</details>

func Dfn

func Dfn(children ...Node) Node

Dfn Represents the defining instance of a term.

Output: <dfn ...>...</dfn>

func Dialog

func Dialog(children ...Node) Node

Dialog Defines a dialog box or window.

Output: <dialog ...>...</dialog>

func DirAttr

func DirAttr(value string) Node

DirAttr Specifies the text direction for the content.

Output: dir="{value}"

func DirEl

func DirEl(children ...Node) Node

DirEl Defines a directory list (deprecated).

Output: <dir ...>...</dir>

func Dirname

func Dirname(value string) Node

Dirname Enables the submission of the text directionality of an input field.

Output: dirname="{value}"

func Disabled

func Disabled(value string) Node

Disabled Specifies that an element should be disabled.

Output: disabled="{value}"

func Div

func Div(children ...Node) Node

Div Defines a section or a division in a document.

Output: <div ...>...</div>

func Dl

func Dl(children ...Node) Node

Dl Defines a description list.

Output: <dl ...>...</dl>

func DocType

func DocType() Node

DocType Defines the document type.

This is a special element and should be used inside a nodx.Group.

Output: <!DOCTYPE html>

func Download

func Download(value string) Node

Download Specifies that the target will be downloaded when a user clicks on the hyperlink.

Output: download="{value}"

func Draggable

func Draggable(value string) Node

Draggable Specifies whether an element is draggable or not.

Output: draggable="{value}"

func Dt

func Dt(children ...Node) Node

Dt Defines a term/name in a description list.

Output: <dt ...>...</dt>

func El

func El(name string, children ...Node) Node

El creates a new Node representing an HTML element with the given name.

func ElVoid

func ElVoid(name string, children ...Node) Node

ElVoid creates a new Node representing an HTML void element with the given name. Void elements are self-closing, such as <img> or <input>.

func Em

func Em(children ...Node) Node

Em Defines emphasized text.

Output: <em ...>...</em>

func Embed

func Embed(children ...Node) Node

Embed Defines a container for an external application or interactive content.

Output: <embed .../>

func Enctype

func Enctype(value string) Node

Enctype Specifies how the form-data should be encoded when submitting it to the server.

Output: enctype="{value}"

func Enterkeyhint

func Enterkeyhint(value string) Node

Enterkeyhint Specifies what action label to present for the enter key on virtual keyboards.

Output: enterkeyhint="{value}"

func Fieldset

func Fieldset(children ...Node) Node

Fieldset Groups related elements in a form.

Output: <fieldset ...>...</fieldset>

func Figcaption

func Figcaption(children ...Node) Node

Figcaption Defines a caption for a figure element.

Output: <figcaption ...>...</figcaption>

func Figure

func Figure(children ...Node) Node

Figure Specifies self-contained content.

Output: <figure ...>...</figure>

func Font

func Font(children ...Node) Node

Font Defines font, color, and size for text (deprecated).

Output: <font ...>...</font>

func Footer(children ...Node) Node

Footer Defines a footer for a document or section.

Output: <footer ...>...</footer>

func For

func For(value string) Node

For Specifies which form element a label or output element is bound to.

Output: for="{value}"

func FormAttr

func FormAttr(value string) Node

FormAttr Specifies the form the element belongs to.

Output: form="{value}"

func FormEl

func FormEl(children ...Node) Node

FormEl Defines an HTML form for user input.

Output: <form ...>...</form>

func Formaction

func Formaction(value string) Node

Formaction Specifies where to send the form-data when a form is submitted (for input and button elements).

Output: formaction="{value}"

func Formenctype

func Formenctype(value string) Node

Formenctype Specifies how form-data should be encoded (for input and button elements).

Output: formenctype="{value}"

func Formmethod

func Formmethod(value string) Node

Formmethod Defines the HTTP method for sending form-data (for input and button elements).

Output: formmethod="{value}"

func Formnovalidate

func Formnovalidate(value string) Node

Formnovalidate Defines that form elements should not be validated when submitted.

Output: formnovalidate="{value}"

func Formtarget

func Formtarget(value string) Node

Formtarget Specifies where to display the response after submitting the form.

Output: formtarget="{value}"

func Frame

func Frame(children ...Node) Node

Frame Defines a window (a frame) in a frameset (deprecated).

Output: <frame ...>...</frame>

func Frameset

func Frameset(children ...Node) Node

Frameset Defines a set of frames (deprecated).

Output: <frameset ...>...</frameset>

func Group

func Group(nodes ...Node) Node

Group combines multiple nodes into a single node without wrapping them in any HTML tag. It renders the child nodes directly.

func H1

func H1(children ...Node) Node

H1 Defines HTML headings level 1.

Output: <h1 ...>...</h1>

func H2

func H2(children ...Node) Node

H2 Defines HTML headings level 2.

Output: <h2 ...>...</h2>

func H3

func H3(children ...Node) Node

H3 Defines HTML headings level 3.

Output: <h3 ...>...</h3>

func H4

func H4(children ...Node) Node

H4 Defines HTML headings level 4.

Output: <h4 ...>...</h4>

func H5

func H5(children ...Node) Node

H5 Defines HTML headings level 5.

Output: <h5 ...>...</h5>

func H6

func H6(children ...Node) Node

H6 Defines HTML headings level 6.

Output: <h6 ...>...</h6>

func Head(children ...Node) Node

Head Contains metadata/information for the document.

Output: <head ...>...</head>

func Header(children ...Node) Node

Header Defines a header for a document or section.

Output: <header ...>...</header>

func Headers

func Headers(value string) Node

Headers Specifies one or more header cells a cell is related to.

Output: headers="{value}"

func Height

func Height(value string) Node

Height Specifies the height of the element.

Output: height="{value}"

func Hidden

func Hidden(value string) Node

Hidden Specifies that an element is not yet, or is no longer, relevant.

Output: hidden="{value}"

func High

func High(value string) Node

High Specifies the range that is considered to be a high value.

Output: high="{value}"

func Hr

func Hr(children ...Node) Node

Hr Defines a thematic change in the content.

Output: <hr .../>

func Href

func Href(value string) Node

Href Specifies the URL of the page the link goes to.

Output: href="{value}"

func Hreflang

func Hreflang(value string) Node

Hreflang Specifies the language of the linked document.

Output: hreflang="{value}"

func Html

func Html(children ...Node) Node

Html Defines the root of an HTML document.

Output: <html ...>...</html>

func HttpEquiv

func HttpEquiv(value string) Node

HttpEquiv Provides an HTTP header for the information/value of the content attribute.

Output: http-equiv="{value}"

func I

func I(children ...Node) Node

I Defines a part of text in an alternate voice or mood.

Output: <i ...>...</i>

func Icon

func Icon(value string) Node

Icon Specifies an icon for the command.

Output: icon="{value}"

func Id

func Id(value string) Node

Id Specifies a unique id for an element.

Output: id="{value}"

func If

func If(condition bool, node Node) Node

If renders a Node based on the provided boolean condition. If the condition is true, the node is rendered; otherwise, it renders nothing.

func IfFunc

func IfFunc(condition bool, function func() Node) Node

IfFunc executes and renders the result of a function based on the provided boolean condition. If the condition is true, the function is executed and rendered; otherwise, nothing is executed nor rendered.

func Iframe

func Iframe(children ...Node) Node

Iframe Defines an inline frame.

Output: <iframe ...>...</iframe>

func Img

func Img(children ...Node) Node

Img Defines an image.

Output: <img .../>

func Importance

func Importance(value string) Node

Importance Indicates the relative fetch priority for the resource.

Output: importance="{value}"

func Input

func Input(children ...Node) Node

Input Defines an input control.

Output: <input .../>

func Ins

func Ins(children ...Node) Node

Ins Defines a text that has been inserted into a document.

Output: <ins ...>...</ins>

func Integrity

func Integrity(value string) Node

Integrity Allows a browser to verify the fetched resource's integrity.

Output: integrity="{value}"

func Ismap

func Ismap(value string) Node

Ismap Specifies an image as a server-side image-map.

Output: ismap="{value}"

func Itemprop

func Itemprop(value string) Node

Itemprop Defines a property of an item.

Output: itemprop="{value}"

func Kbd

func Kbd(children ...Node) Node

Kbd Defines keyboard input.

Output: <kbd ...>...</kbd>

func Keytype

func Keytype(value string) Node

Keytype Specifies the security algorithm of a key.

Output: keytype="{value}"

func Kind

func Kind(value string) Node

Kind Specifies the kind of text track.

Output: kind="{value}"

func LabelAttr

func LabelAttr(value string) Node

LabelAttr Specifies the title of the text track.

Output: label="{value}"

func LabelEl

func LabelEl(children ...Node) Node

LabelEl Defines a label for an input element.

Output: <label ...>...</label>

func Lang

func Lang(value string) Node

Lang Specifies the language of the element's content.

Output: lang="{value}"

func Language

func Language(value string) Node

Language Deprecated. Specifies the scripting language used for the script.

Output: language="{value}"

func Legend

func Legend(children ...Node) Node

Legend Defines a caption for a fieldset element.

Output: <legend ...>...</legend>

func Li

func Li(children ...Node) Node

Li Defines a list item.

Output: <li ...>...</li>

func Link(children ...Node) Node

Link Defines the relationship between a document and an external resource.

Output: <link .../>

func List

func List(value string) Node

List Refers to a datalist element that contains pre-defined options.

Output: list="{value}"

func Loading

func Loading(value string) Node

Loading Indicates how the browser should load the image or iframe.

Output: loading="{value}"

func Loop

func Loop(value string) Node

Loop Specifies that the audio/video will start over again, every time it is finished.

Output: loop="{value}"

func Low

func Low(value string) Node

Low Specifies the range that is considered to be a low value.

Output: low="{value}"

func Main

func Main(children ...Node) Node

Main Specifies the main content of a document.

Output: <main ...>...</main>

func Manifest

func Manifest(value string) Node

Manifest Specifies the URL of the document's cache manifest.

Output: manifest="{value}"

func Map

func Map[T any](slice []T, function func(T) Node) Node

Map transforms a slice of any type into a group of nodes by applying a function to each element. Returns a single Node that contains all the resulting nodes.

func MapEl

func MapEl(children ...Node) Node

MapEl Defines an image-map.

Output: <map ...>...</map>

func Mark

func Mark(children ...Node) Node

Mark Defines marked or highlighted text.

Output: <mark ...>...</mark>

func Max

func Max(value string) Node

Max Specifies the maximum value.

Output: max="{value}"

func Maxlength

func Maxlength(value string) Node

Maxlength Specifies the maximum number of characters allowed in an input field.

Output: maxlength="{value}"

func Media

func Media(value string) Node

Media Specifies what media/device the linked document is optimized for.

Output: media="{value}"

func Meta

func Meta(children ...Node) Node

Meta Defines metadata about an HTML document.

Output: <meta .../>

func Meter

func Meter(children ...Node) Node

Meter Defines a scalar measurement within a known range.

Output: <meter ...>...</meter>

func Method

func Method(value string) Node

Method Specifies the HTTP method to use when sending form-data.

Output: method="{value}"

func Min

func Min(value string) Node

Min Specifies the minimum value.

Output: min="{value}"

func Minlength

func Minlength(value string) Node

Minlength Specifies the minimum number of characters required in an input field.

Output: minlength="{value}"

func Multiple

func Multiple(value string) Node

Multiple Specifies that a user can enter more than one value.

Output: multiple="{value}"

func Muted

func Muted(value string) Node

Muted Specifies that the audio output should be muted.

Output: muted="{value}"

func Name

func Name(value string) Node

Name Specifies the name of the element.

Output: name="{value}"

func Nav(children ...Node) Node

Nav Defines navigation links.

Output: <nav ...>...</nav>

func Noframes

func Noframes(children ...Node) Node

Noframes Defines an alternate content for users that do not support frames (deprecated).

Output: <noframes ...>...</noframes>

func Nomodule

func Nomodule(value string) Node

Nomodule Indicates that the script should not be executed in browsers that support module scripts.

Output: nomodule="{value}"

func Nonce

func Nonce(value string) Node

Nonce A cryptographic nonce used in Content Security Policy.

Output: nonce="{value}"

func Noscript

func Noscript(children ...Node) Node

Noscript Defines an alternate content for users that do not support client-side scripts.

Output: <noscript ...>...</noscript>

func Novalidate

func Novalidate(value string) Node

Novalidate Specifies that the form should not be validated when submitted.

Output: novalidate="{value}"

func Object

func Object(children ...Node) Node

Object Defines an embedded object.

Output: <object ...>...</object>

func Ol

func Ol(children ...Node) Node

Ol Defines an ordered list.

Output: <ol ...>...</ol>

func Open

func Open(value string) Node

Open Specifies that the details should be visible to the user.

Output: open="{value}"

func Optgroup

func Optgroup(children ...Node) Node

Optgroup Defines a group of related options in a drop-down list.

Output: <optgroup ...>...</optgroup>

func Optimum

func Optimum(value string) Node

Optimum Specifies the optimal value of the gauge.

Output: optimum="{value}"

func Option

func Option(children ...Node) Node

Option Defines an option in a drop-down list.

Output: <option ...>...</option>

func Output

func Output(children ...Node) Node

Output Defines the result of a calculation.

Output: <output ...>...</output>

func P

func P(children ...Node) Node

P Defines a paragraph.

Output: <p ...>...</p>

func Param

func Param(children ...Node) Node

Param Defines a parameter for an object.

Output: <param .../>

func Pattern

func Pattern(value string) Node

Pattern Specifies a regular expression that the input element's value is checked against.

Output: pattern="{value}"

func Picture

func Picture(children ...Node) Node

Picture Defines a container for multiple image resources.

Output: <picture ...>...</picture>

func Ping

func Ping(value string) Node

Ping Specifies a space-separated list of URLs to be notified if a user follows the hyperlink.

Output: ping="{value}"

func Placeholder

func Placeholder(value string) Node

Placeholder Specifies a short hint that describes the expected value of an input field.

Output: placeholder="{value}"

func Playsinline

func Playsinline(value string) Node

Playsinline Indicates that the video should play inline on mobile devices.

Output: playsinline="{value}"

func Poster

func Poster(value string) Node

Poster Specifies an image to be shown while the video is downloading or until the user hits the play button.

Output: poster="{value}"

func Pre

func Pre(children ...Node) Node

Pre Defines preformatted text.

Output: <pre ...>...</pre>

func Preload

func Preload(value string) Node

Preload Specifies if and how the author thinks the audio/video should be loaded when the page loads.

Output: preload="{value}"

func Progress

func Progress(children ...Node) Node

Progress Represents the progress of a task.

Output: <progress ...>...</progress>

func Q

func Q(children ...Node) Node

Q Defines a short quotation.

Output: <q ...>...</q>

func Raw

func Raw(value string) Node

Raw creates a new Node representing a raw HTML text node. The value is not escaped, so the caller must ensure the content is safe. Useful for rendering raw HTML, like <script> or <style> tags.

func Rawf

func Rawf(format string, a ...any) Node

Rawf creates a new Node representing a raw HTML text node. The value is formatted with fmt.Sprintf and not escaped, so ensure its safety. Useful for rendering raw HTML, like <script> or <style> tags.

func Rb

func Rb(children ...Node) Node

Rb Used to delimit the base text component of a ruby annotation.

Output: <rb ...>...</rb>

func Readonly

func Readonly(value string) Node

Readonly Specifies that the input field is read-only.

Output: readonly="{value}"

func Referrerpolicy

func Referrerpolicy(value string) Node

Referrerpolicy Specifies which referrer information to send when fetching a resource.

Output: referrerpolicy="{value}"

func Rel

func Rel(value string) Node

Rel Specifies the relationship between the current document and the linked document.

Output: rel="{value}"

func Required

func Required(value string) Node

Required Specifies that the input field must be filled out before submitting the form.

Output: required="{value}"

func Reversed

func Reversed(value string) Node

Reversed Specifies that the list order should be descending (9,8,7...).

Output: reversed="{value}"

func Role

func Role(value string) Node

Role Defines the role of an element for accessibility purposes.

Output: role="{value}"

func Rows

func Rows(value string) Node

Rows Specifies the visible number of lines in a text area.

Output: rows="{value}"

func Rowspan

func Rowspan(value string) Node

Rowspan Specifies the number of rows a cell should span.

Output: rowspan="{value}"

func Rp

func Rp(children ...Node) Node

Rp Defines what to show in browsers that do not support ruby annotations.

Output: <rp ...>...</rp>

func Rt

func Rt(children ...Node) Node

Rt Defines an explanation/pronunciation of characters (for East Asian typography).

Output: <rt ...>...</rt>

func Rtc

func Rtc(children ...Node) Node

Rtc Defines a ruby text container for multiple rt elements.

Output: <rtc ...>...</rtc>

func Ruby

func Ruby(children ...Node) Node

Ruby Defines a ruby annotation.

Output: <ruby ...>...</ruby>

func S

func S(children ...Node) Node

S Defines text that is no longer correct.

Output: <s ...>...</s>

func Samp

func Samp(children ...Node) Node

Samp Defines sample output from a computer program.

Output: <samp ...>...</samp>

func Sandbox

func Sandbox(value string) Node

Sandbox Enables an extra set of restrictions for the content in an iframe.

Output: sandbox="{value}"

func Scope

func Scope(value string) Node

Scope Specifies whether a header cell is a header for a column, row, or group of columns or rows.

Output: scope="{value}"

func Scoped

func Scoped(value string) Node

Scoped Specifies that the styles only apply to this element's parent and child elements.

Output: scoped="{value}"

func Script

func Script(children ...Node) Node

Script Defines a client-side script.

Output: <script ...>...</script>

func Section

func Section(children ...Node) Node

Section Defines a section in a document.

Output: <section ...>...</section>

func Select

func Select(children ...Node) Node

Select Defines a drop-down list.

Output: <select ...>...</select>

func Selected

func Selected(value string) Node

Selected Specifies that an option should be pre-selected when the page loads.

Output: selected="{value}"

func Shape

func Shape(value string) Node

Shape Specifies the shape of an area in an image-map.

Output: shape="{value}"

func Size

func Size(value string) Node

Size Specifies the width, in characters, of an input field.

Output: size="{value}"

func Sizes

func Sizes(value string) Node

Sizes Specifies the sizes of icons for visual media.

Output: sizes="{value}"

func SlotAttr

func SlotAttr(value string) Node

SlotAttr Assigns a slot in a shadow DOM shadow tree.

Output: slot="{value}"

func SlotEl

func SlotEl(children ...Node) Node

SlotEl Defines a placeholder inside a web component.

Output: <slot ...>...</slot>

func Small

func Small(children ...Node) Node

Small Defines smaller text.

Output: <small ...>...</small>

func Source

func Source(children ...Node) Node

Source Defines multiple media resources for media elements.

Output: <source .../>

func SpanAttr

func SpanAttr(value string) Node

SpanAttr Defines the number of columns to span for a col or colgroup element.

Output: span="{value}"

func SpanEl

func SpanEl(children ...Node) Node

SpanEl Defines a section in a document.

Output: <span ...>...</span>

func Spellcheck

func Spellcheck(value string) Node

Spellcheck Specifies whether the element is to have its spelling and grammar checked or not.

Output: spellcheck="{value}"

func Src

func Src(value string) Node

Src Specifies the URL of the media file.

Output: src="{value}"

func Srcdoc

func Srcdoc(value string) Node

Srcdoc Specifies the HTML content of the page to show in the iframe.

Output: srcdoc="{value}"

func Srclang

func Srclang(value string) Node

Srclang Specifies the language of the track text data (required if kind='subtitles').

Output: srclang="{value}"

func Srcset

func Srcset(value string) Node

Srcset Specifies the URL of the image to use in different situations.

Output: srcset="{value}"

func Start

func Start(value string) Node

Start Specifies the start value of an ordered list.

Output: start="{value}"

func Step

func Step(value string) Node

Step Specifies the legal number intervals for an input field.

Output: step="{value}"

func Strike

func Strike(children ...Node) Node

Strike Defines strikethrough text (deprecated).

Output: <strike ...>...</strike>

func Strong

func Strong(children ...Node) Node

Strong Defines important text.

Output: <strong ...>...</strong>

func StyleAttr

func StyleAttr(value string) Node

StyleAttr Specifies an inline CSS style for an element.

Output: style="{value}"

func StyleEl

func StyleEl(children ...Node) Node

StyleEl Defines style information for a document.

Output: <style ...>...</style>

func Sub

func Sub(children ...Node) Node

Sub Defines subscripted text.

Output: <sub ...>...</sub>

func SummaryAttr

func SummaryAttr(value string) Node

SummaryAttr Specifies a summary of the content of a table (deprecated in HTML5).

Output: summary="{value}"

func SummaryEl

func SummaryEl(children ...Node) Node

SummaryEl Defines a visible heading for a details element.

Output: <summary ...>...</summary>

func Sup

func Sup(children ...Node) Node

Sup Defines superscripted text.

Output: <sup ...>...</sup>

func Svg

func Svg(children ...Node) Node

Svg Defines a container for SVG graphics.

Output: <svg ...>...</svg>

func Tabindex

func Tabindex(value string) Node

Tabindex Specifies the tabbing order of an element.

Output: tabindex="{value}"

func Table

func Table(children ...Node) Node

Table Defines a table.

Output: <table ...>...</table>

func Target

func Target(value string) Node

Target Specifies where to open the linked document.

Output: target="{value}"

func Tbody

func Tbody(children ...Node) Node

Tbody Groups the body content in a table.

Output: <tbody ...>...</tbody>

func Td

func Td(children ...Node) Node

Td Defines a cell in a table.

Output: <td ...>...</td>

func Template

func Template(children ...Node) Node

Template Defines a template.

Output: <template ...>...</template>

func Text

func Text(value string) Node

Text creates a new Node representing an escaped HTML text node. The value is HTML-escaped to prevent XSS attacks.

func Textarea

func Textarea(children ...Node) Node

Textarea Defines a multiline input control.

Output: <textarea ...>...</textarea>

func Textf

func Textf(format string, a ...any) Node

Textf creates a new Node representing an escaped HTML text node. The value is formatted with fmt.Sprintf and then HTML-escaped to prevent XSS attacks.

func Tfoot

func Tfoot(children ...Node) Node

Tfoot Groups the footer content in a table.

Output: <tfoot ...>...</tfoot>

func Th

func Th(children ...Node) Node

Th Defines a header cell in a table.

Output: <th ...>...</th>

func Thead

func Thead(children ...Node) Node

Thead Groups the header content in a table.

Output: <thead ...>...</thead>

func Time

func Time(children ...Node) Node

Time Defines a specific time.

Output: <time ...>...</time>

func TitleAttr

func TitleAttr(value string) Node

TitleAttr Specifies extra information about an element.

Output: title="{value}"

func TitleEl

func TitleEl(children ...Node) Node

TitleEl Defines a title for the document.

Output: <title ...>...</title>

func Tr

func Tr(children ...Node) Node

Tr Defines a row in a table.

Output: <tr ...>...</tr>

func Track

func Track(children ...Node) Node

Track Defines text tracks for media elements.

Output: <track .../>

func Translate

func Translate(value string) Node

Translate Specifies whether the content of an element should be translated or not.

Output: translate="{value}"

func Tt

func Tt(children ...Node) Node

Tt Defines teletype text (deprecated).

Output: <tt ...>...</tt>

func Type

func Type(value string) Node

Type Specifies the type of element.

Output: type="{value}"

func U

func U(children ...Node) Node

U Defines text that should be stylistically different from normal text.

Output: <u ...>...</u>

func Ul

func Ul(children ...Node) Node

Ul Defines an unordered list.

Output: <ul ...>...</ul>

func Usemap

func Usemap(value string) Node

Usemap Specifies an image as a client-side image-map.

Output: usemap="{value}"

func Value

func Value(value string) Node

Value Specifies the value of the element.

Output: value="{value}"

func Var

func Var(children ...Node) Node

Var Defines a variable.

Output: <var ...>...</var>

func Video

func Video(children ...Node) Node

Video Defines embedded video content.

Output: <video ...>...</video>

func Wbr

func Wbr(children ...Node) Node

Wbr Defines a possible line-break.

Output: <wbr .../>

func Width

func Width(value string) Node

Width Specifies the width of the element.

Output: width="{value}"

func Wrap

func Wrap(value string) Node

Wrap Specifies how the text in a text area is to be wrapped when submitted in a form.

Output: wrap="{value}"

type StyleMap

type StyleMap map[string]bool

StyleMap represents a map of CSS style rules with conditional rendering. The keys are the complete CSS rules (e.g., "border: 1px solid black"), and the values are boolean conditions indicating whether each rule should be included in the final output.

Example:

sm := StyleMap{
	"border: 1px solid black": true,  // Included
	"padding: 10px":           false, // Excluded
	"margin: 5px":             true,  // Included
}

This will render the style attribute as: style="border: 1px solid black; margin: 5px"

func (StyleMap) Render

func (sm StyleMap) Render(w io.Writer) error

Render writes the "style" attribute to the provided writer. It includes only the style rules with a `true` value, sorted alphabetically.

func (StyleMap) RenderBytes

func (sm StyleMap) RenderBytes() ([]byte, error)

RenderBytes returns the "style" attribute as a byte slice. It includes only the style rules with a `true` value, sorted alphabetically.

func (StyleMap) RenderString

func (sm StyleMap) RenderString() (string, error)

RenderString returns the "style" attribute as a string. It includes only the style rules with a `true` value, sorted alphabetically.

Directories

Path Synopsis
internal
assert
Package assert provides a set of functions to help with testing of this project.
Package assert provides a set of functions to help with testing of this project.

Jump to

Keyboard shortcuts

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