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.
In NodX, everything is a node and anything that implements the Node interface can be rendered as HTML or used as a Node child.
Index ¶
- func EscapeHTML(input string) string
- type ClassMap
- type Node
- func A(children ...Node) Node
- func Abbr(children ...Node) Node
- func Accept(value string) Node
- func AcceptCharset(value string) Node
- func Accesskey(value string) Node
- func Action(value string) Node
- func Address(children ...Node) Node
- func Align(value string) Node
- func Allow(value string) Node
- func Alt(value string) Node
- func Applet(children ...Node) Node
- func Area(children ...Node) Node
- func Aria(key string, value string) Node
- func Article(children ...Node) Node
- func Aside(children ...Node) Node
- func Async(value string) Node
- func Attr(name string, value string) Node
- func Audio(children ...Node) Node
- func Autocapitalize(value string) Node
- func Autocomplete(value string) Node
- func Autofocus(value string) Node
- func Autoplay(value string) Node
- func B(children ...Node) Node
- func Background(value string) Node
- func Base(children ...Node) Node
- func Basefont(children ...Node) Node
- func Bdi(children ...Node) Node
- func Bdo(children ...Node) Node
- func Bgcolor(value string) Node
- func Blockquote(children ...Node) Node
- func Body(children ...Node) Node
- func Border(value string) Node
- func Br(children ...Node) Node
- func Buffered(value string) Node
- func Button(children ...Node) Node
- func Canvas(children ...Node) Node
- func Caption(children ...Node) Node
- func Capture(value string) Node
- func Center(children ...Node) Node
- func Challenge(value string) Node
- func Charset(value string) Node
- func Checked(value string) Node
- func CiteAttr(value string) Node
- func CiteEl(children ...Node) Node
- func Class(value string) Node
- func CodeAttr(value string) Node
- func CodeEl(children ...Node) Node
- func Codebase(value string) Node
- func Col(children ...Node) Node
- func Colgroup(children ...Node) Node
- func Color(value string) Node
- func Cols(value string) Node
- func Colspan(value string) Node
- func Content(value string) Node
- func Contenteditable(value string) Node
- func Contextmenu(value string) Node
- func Controls(value string) Node
- func Coords(value string) Node
- func Crossorigin(value string) Node
- func Csp(value string) Node
- func Data(key string, value string) Node
- func DataAttr(value string) Node
- func DataEl(children ...Node) Node
- func Datalist(children ...Node) Node
- func Datetime(value string) Node
- func Dd(children ...Node) Node
- func Decoding(value string) Node
- func Default(value string) Node
- func Defer(value string) Node
- func Del(children ...Node) Node
- func Details(children ...Node) Node
- func Dfn(children ...Node) Node
- func Dialog(children ...Node) Node
- func DirAttr(value string) Node
- func DirEl(children ...Node) Node
- func Dirname(value string) Node
- func Disabled(value string) Node
- func Div(children ...Node) Node
- func Dl(children ...Node) Node
- func DocType() Node
- func Download(value string) Node
- func Draggable(value string) Node
- func Dt(children ...Node) Node
- func El(name string, children ...Node) Node
- func ElVoid(name string, children ...Node) Node
- func Em(children ...Node) Node
- func Embed(children ...Node) Node
- func Enctype(value string) Node
- func Enterkeyhint(value string) Node
- func Eval(fn func() Node) Node
- func Fieldset(children ...Node) Node
- func Figcaption(children ...Node) Node
- func Figure(children ...Node) Node
- func Font(children ...Node) Node
- func Footer(children ...Node) Node
- func For(value string) Node
- func FormAttr(value string) Node
- func FormEl(children ...Node) Node
- func Formaction(value string) Node
- func Formenctype(value string) Node
- func Formmethod(value string) Node
- func Formnovalidate(value string) Node
- func Formtarget(value string) Node
- func Frame(children ...Node) Node
- func Frameset(children ...Node) Node
- func Group(nodes ...Node) Node
- func H1(children ...Node) Node
- func H2(children ...Node) Node
- func H3(children ...Node) Node
- func H4(children ...Node) Node
- func H5(children ...Node) Node
- func H6(children ...Node) Node
- func Head(children ...Node) Node
- func Header(children ...Node) Node
- func Headers(value string) Node
- func Height(value string) Node
- func Hidden(value string) Node
- func High(value string) Node
- func Hr(children ...Node) Node
- func Href(value string) Node
- func Hreflang(value string) Node
- func Html(children ...Node) Node
- func HttpEquiv(value string) Node
- func I(children ...Node) Node
- func Icon(value string) Node
- func Id(value string) Node
- func If(condition bool, node Node) Node
- func IfFunc(condition bool, function func() Node) Node
- func Iframe(children ...Node) Node
- func Img(children ...Node) Node
- func Importance(value string) Node
- func Input(children ...Node) Node
- func Ins(children ...Node) Node
- func Integrity(value string) Node
- func Ismap(value string) Node
- func Itemprop(value string) Node
- func Kbd(children ...Node) Node
- func Keytype(value string) Node
- func Kind(value string) Node
- func LabelAttr(value string) Node
- func LabelEl(children ...Node) Node
- func Lang(value string) Node
- func Language(value string) Node
- func Legend(children ...Node) Node
- func Li(children ...Node) Node
- func Link(children ...Node) Node
- func List(value string) Node
- func Loading(value string) Node
- func Loop(value string) Node
- func Low(value string) Node
- func Main(children ...Node) Node
- func Manifest(value string) Node
- func Map[T any](slice []T, function func(T) Node) Node
- func MapEl(children ...Node) Node
- func Mark(children ...Node) Node
- func Max(value string) Node
- func Maxlength(value string) Node
- func Media(value string) Node
- func Meta(children ...Node) Node
- func Meter(children ...Node) Node
- func Method(value string) Node
- func Min(value string) Node
- func Minlength(value string) Node
- func Multiple(value string) Node
- func Muted(value string) Node
- func Name(value string) Node
- func Nav(children ...Node) Node
- func Noframes(children ...Node) Node
- func Nomodule(value string) Node
- func Nonce(value string) Node
- func Noscript(children ...Node) Node
- func Novalidate(value string) Node
- func Object(children ...Node) Node
- func Ol(children ...Node) Node
- func Open(value string) Node
- func Optgroup(children ...Node) Node
- func Optimum(value string) Node
- func Option(children ...Node) Node
- func Output(children ...Node) Node
- func P(children ...Node) Node
- func Param(children ...Node) Node
- func Pattern(value string) Node
- func Picture(children ...Node) Node
- func Ping(value string) Node
- func Placeholder(value string) Node
- func Playsinline(value string) Node
- func Poster(value string) Node
- func Pre(children ...Node) Node
- func Preload(value string) Node
- func Progress(children ...Node) Node
- func Q(children ...Node) Node
- func Raw(value string) Node
- func Rawf(format string, a ...any) Node
- func Rb(children ...Node) Node
- func Readonly(value string) Node
- func Referrerpolicy(value string) Node
- func Rel(value string) Node
- func Required(value string) Node
- func Reversed(value string) Node
- func Role(value string) Node
- func Rows(value string) Node
- func Rowspan(value string) Node
- func Rp(children ...Node) Node
- func Rt(children ...Node) Node
- func Rtc(children ...Node) Node
- func Ruby(children ...Node) Node
- func S(children ...Node) Node
- func Samp(children ...Node) Node
- func Sandbox(value string) Node
- func Scope(value string) Node
- func Scoped(value string) Node
- func Script(children ...Node) Node
- func Section(children ...Node) Node
- func Select(children ...Node) Node
- func Selected(value string) Node
- func Shape(value string) Node
- func Size(value string) Node
- func Sizes(value string) Node
- func SlotAttr(value string) Node
- func SlotEl(children ...Node) Node
- func Small(children ...Node) Node
- func Source(children ...Node) Node
- func SpanAttr(value string) Node
- func SpanEl(children ...Node) Node
- func Spellcheck(value string) Node
- func Src(value string) Node
- func Srcdoc(value string) Node
- func Srclang(value string) Node
- func Srcset(value string) Node
- func Start(value string) Node
- func Step(value string) Node
- func Strike(children ...Node) Node
- func Strong(children ...Node) Node
- func StyleAttr(value string) Node
- func StyleEl(children ...Node) Node
- func Sub(children ...Node) Node
- func SummaryAttr(value string) Node
- func SummaryEl(children ...Node) Node
- func Sup(children ...Node) Node
- func Svg(children ...Node) Node
- func Tabindex(value string) Node
- func Table(children ...Node) Node
- func Target(value string) Node
- func Tbody(children ...Node) Node
- func Td(children ...Node) Node
- func Template(children ...Node) Node
- func Text(value string) Node
- func Textarea(children ...Node) Node
- func Textf(format string, a ...any) Node
- func Tfoot(children ...Node) Node
- func Th(children ...Node) Node
- func Thead(children ...Node) Node
- func Time(children ...Node) Node
- func TitleAttr(value string) Node
- func TitleEl(children ...Node) Node
- func Tr(children ...Node) Node
- func Track(children ...Node) Node
- func Translate(value string) Node
- func Tt(children ...Node) Node
- func Type(value string) Node
- func U(children ...Node) Node
- func Ul(children ...Node) Node
- func Usemap(value string) Node
- func Value(value string) Node
- func Var(children ...Node) Node
- func Video(children ...Node) Node
- func Wbr(children ...Node) Node
- func Width(value string) Node
- func Wrap(value string) Node
- type StyleMap
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EscapeHTML ¶
EscapeHTML escapes the input string to prevent XSS attacks.
Types ¶
type ClassMap ¶
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) IsAttribute ¶ added in v0.2.0
func (ClassMap) RenderBytes ¶
func (ClassMap) RenderString ¶
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)
// IsElement indicates if the node should be rendered as an element.
IsElement() bool
// IsAttribute indicates if the node should be rendered as an attribute.
IsAttribute() bool
// String returns the node HTML as a string and implements the fmt.Stringer interface.
//
// This is only for convenience and debugging purposes and it ignores the
// error return value.
//
// You should use RenderString() whenever possible.
String() string
}
Node is the interface that wraps the basic Render methods used in the different NodX node types.
Anything that implements this interface can be used as a node.
func Accept ¶
Accept Specifies the types of files that the server accepts (only for input type='file').
Output: accept="{value}"
func AcceptCharset ¶
AcceptCharset Specifies the character encodings to be used for form submission.
Output: accept-charset="{value}"
func Accesskey ¶
Accesskey Specifies a shortcut key to activate/focus an element.
Output: accesskey="{value}"
func Action ¶
Action Specifies where to send the form-data when a form is submitted.
Output: action="{value}"
func Address ¶
Address Defines contact information for the author/owner of a document.
Output: <address ...>...</address>
func Alt ¶
Alt Provides alternative text for an image if it cannot be displayed.
Output: alt="{value}"
func Async ¶
Async Indicates that the script should be executed asynchronously.
Output: async="{value}"
func Attr ¶
Attr creates a new Node representing an HTML attribute with a name and value. The value is HTML-escaped to prevent XSS attacks.
func Autocapitalize ¶
Autocapitalize Controls how text input is automatically capitalized.
Output: autocapitalize="{value}"
func Autocomplete ¶
Autocomplete Specifies whether an input field should have autocomplete enabled.
Output: autocomplete="{value}"
func Autofocus ¶
Autofocus Specifies that an input field should automatically get focus when the page loads.
Output: autofocus="{value}"
func Autoplay ¶
Autoplay Specifies that the audio/video should start playing as soon as it is ready.
Output: autoplay="{value}"
func Background ¶
Background Specifies a background image for the element.
Output: background="{value}"
func Basefont ¶
Basefont Specifies a default color, size, and font for all text in a document (deprecated).
Output: <basefont ...>...</basefont>
func Bdi ¶
Bdi Isolates a part of text that might be formatted in a different direction from other text.
Output: <bdi ...>...</bdi>
func Blockquote ¶
Blockquote Defines a section that is quoted from another source.
Output: <blockquote ...>...</blockquote>
func Buffered ¶
Buffered Contains the time ranges that the media element has buffered.
Output: buffered="{value}"
func Canvas ¶
Canvas Used to draw graphics on the fly via scripting.
Output: <canvas ...>...</canvas>
func Capture ¶
Capture Specifies that the camera should be used for input.
Output: capture="{value}"
func Challenge ¶
Challenge Specifies that the value of the keygen element should be challenged when submitted.
Output: challenge="{value}"
func Checked ¶
Checked Specifies that an input element should be pre-selected when the page loads.
Output: checked="{value}"
func CiteAttr ¶
CiteAttr Specifies a URL that explains the quote, or why a text was inserted/deleted.
Output: cite="{value}"
func CodeAttr ¶
CodeAttr Specifies the URL of the applet's class file to be loaded and executed.
Output: code="{value}"
func Col ¶
Col Specifies column properties for each column within a colgroup element.
Output: <col ...>
func Colgroup ¶
Colgroup Specifies a group of one or more columns in a table for formatting.
Output: <colgroup ...>...</colgroup>
func Colspan ¶
Colspan Specifies the number of columns a cell should span.
Output: colspan="{value}"
func Content ¶
Content Gives the value associated with the http-equiv or name attribute.
Output: content="{value}"
func Contenteditable ¶
Contenteditable Specifies whether the content of an element is editable.
Output: contenteditable="{value}"
func Contextmenu ¶
Contextmenu Specifies a context menu for an element.
Output: contextmenu="{value}"
func Controls ¶
Controls Specifies that audio/video controls should be displayed.
Output: controls="{value}"
func Crossorigin ¶
Crossorigin Configures the CORS requests for the element's fetched data.
Output: crossorigin="{value}"
func Csp ¶
Csp Allows specifying a Content Security Policy for the content in the iframe.
Output: csp="{value}"
func Data ¶
Data Used to store custom data private to the page or application.
Output: data-{key}="{value}"
func DataAttr ¶
DataAttr Specifies the URL of the resource to be used by the object.
Output: data="{value}"
func DataEl ¶
DataEl Links the given content with a machine-readable translation.
Output: <data ...>...</data>
func Datalist ¶
Datalist Specifies a list of pre-defined options for input controls.
Output: <datalist ...>...</datalist>
func Decoding ¶
Decoding Indicates how the browser should load the image.
Output: decoding="{value}"
func Defer ¶
Defer Specifies that the script is executed when the page has finished parsing.
Output: defer="{value}"
func Details ¶
Details Defines additional details that the user can view or hide.
Output: <details ...>...</details>
func Dirname ¶
Dirname Enables the submission of the text directionality of an input field.
Output: dirname="{value}"
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 ¶
Download Specifies that the target will be downloaded when a user clicks on the hyperlink.
Output: download="{value}"
func Draggable ¶
Draggable Specifies whether an element is draggable or not.
Output: draggable="{value}"
func ElVoid ¶
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 Embed ¶
Embed Defines a container for an external application or interactive content.
Output: <embed ...>
func Enctype ¶
Enctype Specifies how the form-data should be encoded when submitting it to the server.
Output: enctype="{value}"
func Enterkeyhint ¶
Enterkeyhint Specifies what action label to present for the enter key on virtual keyboards.
Output: enterkeyhint="{value}"
func Eval ¶ added in v0.2.0
Eval executes a provided function and integrates its resulting Node into the current node tree.
Use Eval to insert dynamic content, apply complex logic, or generate nodes on the fly.
Example:
node := nodx.Group(
nodx.Div(
nodx.Class("container"),
nodx.Eval(func() nodx.Node {
if condition {
return nodx.Text("Condition is true")
}
return nodx.Text("Condition is false")
}),
),
)
Example ¶
condition := 3 > 2
node := Div(
Class("container"),
Eval(func() Node {
// You can add your own go code here
if condition {
return Text("Condition is true")
}
return Text("Condition is false")
}),
)
fmt.Println(node)
Output: <div class="container">Condition is true</div>
func Figcaption ¶
Figcaption Defines a caption for a figure element.
Output: <figcaption ...>...</figcaption>
func For ¶
For Specifies which form element a label or output element is bound to.
Output: for="{value}"
func Formaction ¶
Formaction Specifies where to send the form-data when a form is submitted (for input and button elements).
Output: formaction="{value}"
func Formenctype ¶
Formenctype Specifies how form-data should be encoded (for input and button elements).
Output: formenctype="{value}"
func Formmethod ¶
Formmethod Defines the HTTP method for sending form-data (for input and button elements).
Output: formmethod="{value}"
func Formnovalidate ¶
Formnovalidate Defines that form elements should not be validated when submitted.
Output: formnovalidate="{value}"
func Formtarget ¶
Formtarget Specifies where to display the response after submitting the form.
Output: formtarget="{value}"
func Frame ¶
Frame Defines a window (a frame) in a frameset (deprecated).
Output: <frame ...>...</frame>
func Group ¶
Group combines multiple nodes into a single node without wrapping them in any HTML tag.
When rendered directly, it will call Render on all the nodes in the group sequentially.
When used as a child of another node, it will be expanded so that the nodes in the group become children of the group's parent.
Example ¶
node := Group(
DocType(),
Html(
Head(
TitleEl(Text("Hello, World!")),
),
Body(Text("Hello, World!")),
),
)
fmt.Println(node)
Output: <!DOCTYPE html><html><head><title>Hello, World!</title></head><body>Hello, World!</body></html>
func Headers ¶
Headers Specifies one or more header cells a cell is related to.
Output: headers="{value}"
func Hidden ¶
Hidden Specifies that an element is not yet, or is no longer, relevant.
Output: hidden="{value}"
func HttpEquiv ¶
HttpEquiv Provides an HTTP header for the information/value of the content attribute.
Output: http-equiv="{value}"
func If ¶
If renders a Node based on the provided boolean condition. If the condition is true, the node is rendered; otherwise, it renders nothing.
Example ¶
condition := 3 > 2
node := Div(
Class("container"),
If(condition, Text("Condition is true")),
)
fmt.Println(node)
Output: <div class="container">Condition is true</div>
func IfFunc ¶
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.
Example ¶
condition := 3 > 2
node := Div(
Class("container"),
IfFunc(condition, func() Node {
// You can add your own go code here
return Text("Condition is true")
}),
)
fmt.Println(node)
Output: <div class="container">Condition is true</div>
func Importance ¶
Importance Indicates the relative fetch priority for the resource.
Output: importance="{value}"
func Integrity ¶
Integrity Allows a browser to verify the fetched resource's integrity.
Output: integrity="{value}"
func Language ¶
Language Deprecated. Specifies the scripting language used for the script.
Output: language="{value}"
func Link ¶
Link Defines the relationship between a document and an external resource.
Output: <link ...>
func List ¶
List Refers to a datalist element that contains pre-defined options.
Output: list="{value}"
func Loading ¶
Loading Indicates how the browser should load the image or iframe.
Output: loading="{value}"
func Loop ¶
Loop Specifies that the audio/video will start over again, every time it is finished.
Output: loop="{value}"
func Manifest ¶
Manifest Specifies the URL of the document's cache manifest.
Output: manifest="{value}"
func Map ¶
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.
Example ¶
items := []string{"Item 1", "Item 2", "Item 3"}
node := Ul(
Map(items, func(item string) Node {
return Li(Text(item))
}),
)
fmt.Println(node)
Output: <ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul>
func Maxlength ¶
Maxlength Specifies the maximum number of characters allowed in an input field.
Output: maxlength="{value}"
func Media ¶
Media Specifies what media/device the linked document is optimized for.
Output: media="{value}"
func Meter ¶
Meter Defines a scalar measurement within a known range.
Output: <meter ...>...</meter>
func Method ¶
Method Specifies the HTTP method to use when sending form-data.
Output: method="{value}"
func Minlength ¶
Minlength Specifies the minimum number of characters required in an input field.
Output: minlength="{value}"
func Multiple ¶
Multiple Specifies that a user can enter more than one value.
Output: multiple="{value}"
func Noframes ¶
Noframes Defines an alternate content for users that do not support frames (deprecated).
Output: <noframes ...>...</noframes>
func Nomodule ¶
Nomodule Indicates that the script should not be executed in browsers that support module scripts.
Output: nomodule="{value}"
func Noscript ¶
Noscript Defines an alternate content for users that do not support client-side scripts.
Output: <noscript ...>...</noscript>
func Novalidate ¶
Novalidate Specifies that the form should not be validated when submitted.
Output: novalidate="{value}"
func Optgroup ¶
Optgroup Defines a group of related options in a drop-down list.
Output: <optgroup ...>...</optgroup>
func Pattern ¶
Pattern Specifies a regular expression that the input element's value is checked against.
Output: pattern="{value}"
func Picture ¶
Picture Defines a container for multiple image resources.
Output: <picture ...>...</picture>
func Ping ¶
Ping Specifies a space-separated list of URLs to be notified if a user follows the hyperlink.
Output: ping="{value}"
func Placeholder ¶
Placeholder Specifies a short hint that describes the expected value of an input field.
Output: placeholder="{value}"
func Playsinline ¶
Playsinline Indicates that the video should play inline on mobile devices.
Output: playsinline="{value}"
func Poster ¶
Poster Specifies an image to be shown while the video is downloading or until the user hits the play button.
Output: poster="{value}"
func Preload ¶
Preload Specifies if and how the author thinks the audio/video should be loaded when the page loads.
Output: preload="{value}"
func Raw ¶
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 ¶
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 Referrerpolicy ¶
Referrerpolicy Specifies which referrer information to send when fetching a resource.
Output: referrerpolicy="{value}"
func Rel ¶
Rel Specifies the relationship between the current document and the linked document.
Output: rel="{value}"
func Required ¶
Required Specifies that the input field must be filled out before submitting the form.
Output: required="{value}"
func Reversed ¶
Reversed Specifies that the list order should be descending (9,8,7...).
Output: reversed="{value}"
func Rp ¶
Rp Defines what to show in browsers that do not support ruby annotations.
Output: <rp ...>...</rp>
func Rt ¶
Rt Defines an explanation/pronunciation of characters (for East Asian typography).
Output: <rt ...>...</rt>
func Sandbox ¶
Sandbox Enables an extra set of restrictions for the content in an iframe.
Output: sandbox="{value}"
func Scope ¶
Scope Specifies whether a header cell is a header for a column, row, or group of columns or rows.
Output: scope="{value}"
func Scoped ¶
Scoped Specifies that the styles only apply to this element's parent and child elements.
Output: scoped="{value}"
func Selected ¶
Selected Specifies that an option should be pre-selected when the page loads.
Output: selected="{value}"
func SpanAttr ¶
SpanAttr Defines the number of columns to span for a col or colgroup element.
Output: span="{value}"
func Spellcheck ¶
Spellcheck Specifies whether the element is to have its spelling and grammar checked or not.
Output: spellcheck="{value}"
func Srcdoc ¶
Srcdoc Specifies the HTML content of the page to show in the iframe.
Output: srcdoc="{value}"
func Srclang ¶
Srclang Specifies the language of the track text data (required if kind='subtitles').
Output: srclang="{value}"
func Srcset ¶
Srcset Specifies the URL of the image to use in different situations.
Output: srcset="{value}"
func SummaryAttr ¶
SummaryAttr Specifies a summary of the content of a table (deprecated in HTML5).
Output: summary="{value}"
func SummaryEl ¶
SummaryEl Defines a visible heading for a details element.
Output: <summary ...>...</summary>
func Text ¶
Text creates a new Node representing an escaped HTML text node. The value is HTML-escaped to prevent XSS attacks.
func Textf ¶
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 Translate ¶
Translate Specifies whether the content of an element should be translated or not.
Output: translate="{value}"
func U ¶
U Defines text that should be stylistically different from normal text.
Output: <u ...>...</u>
type StyleMap ¶
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"