NAME
html/tags - shortcut functions for HTML generation.
SYNOPSIS
from html/tags import *;
from std/colour import parse_colour;
let classes := [ "big", "bold" ];
let doc := HTML(
lang: "en",
HEAD(
META( charset: "utf8" ),
TITLE( "Hello World" ),
STYLE( ```
.big { font-size: 1.5rem; }
.small { font-size: 0.75rem; }
.bold { font-weight: bold; }
#intro { color: ${ parse_colour("blue") }; }
``` ),
),
BODY(
H1( "Hello World" ),
P( class: classes, id: "intro", "This is an example." ),
P( class: "small bold", "And now we're done." ),
),
);
say doc;
DESCRIPTION
This module provides shortcut functions for quickly constructing a DOM in ZuzuScript.
EXPORTS
Functions
General Functions
html_tag( String tagname, ... PairList attrs, Array children ) → HTMLElementGeneric HTML tag; can be used to insert any element which this module otherwise doesn't provide.
let annoyance := html_tag( "blink", "This text flashes." );Attributes are passed as named parameters:
let link := html_tag( "a", href: "https://example.net/", "Link text" );All other parameters (including plain strings) are treated as child nodes.
html_comment( String comment ) → HTMLCommentUsed to insert an HTML comment.
html_literal( String literal_html ) → HTMLNodeUsed to insert literal HTML which will not be escaped during output. Internally this is represented as a special HTMLComment node.
let div := DIV( id: "example", P("This div contains two paragraphs, but one is commented out."), html_literal("<!-- "), P("This one should be commented out."), html_literal(" -->"), );
Main root
HTML(... PairList attrs, Array children ) → HTMLElementRepresents the top-level root element of an HTML document; every other element in the document is a descendant of it.
Document metadata
BASE(... PairList attrs, Array children ) → HTMLElementSets the base URL used to resolve relative URLs in the document; only one base element is allowed.
HEAD(... PairList attrs, Array children ) → HTMLElementContains document metadata such as the title, scripts, style sheets, links, and other machine-readable information.
LINK(... PairList attrs, Array children ) → HTMLElementDeclares a relationship between the current document and an external resource, commonly a style sheet or site icon.
META(... PairList attrs, Array children ) → HTMLElementProvides metadata that cannot be expressed by other metadata elements such as base, link, script, style, or title.
STYLE(... PairList attrs, Array children ) → HTMLElementContains CSS rules for the document or for a part of the document.
TITLE(... PairList attrs, Array children ) → HTMLElementDefines the document title shown by browsers in the window title or tab label; markup inside it is treated as text.
Sectioning root
BODY(... PairList attrs, Array children ) → HTMLElementContains the visible and interactive content of an HTML document; a document has at most one body element.
Content sectioning
ADDRESS(... PairList attrs, Array children ) → HTMLElementProvides contact information for a person, people, or organisation related to the surrounding content.
ARTICLE(... PairList attrs, Array children ) → HTMLElementRepresents a self-contained piece of content that can stand on its own or be reused independently.
ASIDE(... PairList attrs, Array children ) → HTMLElementRepresents content that is tangentially related to the main surrounding content, such as a sidebar or callout.
FOOTER(... PairList attrs, Array children ) → HTMLElementRepresents footer content for the nearest section or sectioning root, such as authorship, copyright, or related links.
HEADER(... PairList attrs, Array children ) → HTMLElementRepresents introductory content or navigational aids for the surrounding section or page.
H1(... PairList attrs, Array children ) → HTMLElementRepresents the highest-level section heading.
H2(... PairList attrs, Array children ) → HTMLElementRepresents a second-level section heading.
H3(... PairList attrs, Array children ) → HTMLElementRepresents a third-level section heading.
H4(... PairList attrs, Array children ) → HTMLElementRepresents a fourth-level section heading.
H5(... PairList attrs, Array children ) → HTMLElementRepresents a fifth-level section heading.
H6(... PairList attrs, Array children ) → HTMLElementRepresents the lowest-level section heading.
HGROUP(... PairList attrs, Array children ) → HTMLElementGroups a heading with related secondary content such as a subtitle, alternative title, or tagline.
MAIN(... PairList attrs, Array children ) → HTMLElementRepresents the dominant content of the document body.
NAV(... PairList attrs, Array children ) → HTMLElementRepresents a section whose purpose is navigation within the current document or to other documents.
SECTION(... PairList attrs, Array children ) → HTMLElementRepresents a generic standalone section when no more specific semantic element applies.
SEARCH(... PairList attrs, Array children ) → HTMLElementRepresents a region containing controls or content for search or filtering.
Text content
BLOCKQUOTE(... PairList attrs, Array children ) → HTMLElementRepresents an extended quotation, optionally with a source URL in the cite attribute.
DD(... PairList attrs, Array children ) → HTMLElementRepresents the description, definition, or value for the preceding term in a description list.
DIV(... PairList attrs, Array children ) → HTMLElementRepresents a generic flow-content container with no inherent semantic meaning.
DL(... PairList attrs, Array children ) → HTMLElementRepresents a description list made of term and description groups.
DT(... PairList attrs, Array children ) → HTMLElementRepresents a term in a description or definition list.
FIGCAPTION(... PairList attrs, Array children ) → HTMLElementRepresents a caption or legend for the rest of the parent figure element.
FIGURE(... PairList attrs, Array children ) → HTMLElementRepresents self-contained content, optionally with a figcaption, referenced as a single unit.
HR(... PairList attrs, Array children ) → HTMLElementRepresents a thematic break between paragraph-level sections of content.
LI(... PairList attrs, Array children ) → HTMLElementRepresents an item in a list or menu.
MENU(... PairList attrs, Array children ) → HTMLElementRepresents an unordered list of items, treated by browsers like ul.
OL(... PairList attrs, Array children ) → HTMLElementRepresents an ordered list of items.
P(... PairList attrs, Array children ) → HTMLElementRepresents a paragraph or paragraph-like grouping of related content.
PRE(... PairList attrs, Array children ) → HTMLElementRepresents preformatted text where whitespace is presented as written.
UL(... PairList attrs, Array children ) → HTMLElementRepresents an unordered list of items.
Inline text semantics
A(... PairList attrs, Array children ) → HTMLElementRepresents a hyperlink when used with href, linking to a URL, file, email address, or location.
ABBR(... PairList attrs, Array children ) → HTMLElementRepresents an abbreviation or acronym.
B(... PairList attrs, Array children ) → HTMLElementDraws attention to text without implying additional importance.
BDI(... PairList attrs, Array children ) → HTMLElementIsolates its text from surrounding bidirectional text handling.
BDO(... PairList attrs, Array children ) → HTMLElementOverrides the current text direction for its contents.
BR(... PairList attrs, Array children ) → HTMLElementRepresents a line break within text.
CITE(... PairList attrs, Array children ) → HTMLElementMarks the title of a cited creative work.
CODE(... PairList attrs, Array children ) → HTMLElementRepresents a short fragment of computer code.
DATA(... PairList attrs, Array children ) → HTMLElementAssociates content with a machine-readable value.
DFN(... PairList attrs, Array children ) → HTMLElementMarks the term being defined by the surrounding context.
EM(... PairList attrs, Array children ) → HTMLElementMarks text with stress emphasis.
I(... PairList attrs, Array children ) → HTMLElementRepresents text set off from normal prose, such as a term, idiom, or technical phrase.
KBD(... PairList attrs, Array children ) → HTMLElementRepresents user input from a keyboard, voice input, or another input device.
MARK(... PairList attrs, Array children ) → HTMLElementMarks text highlighted for reference or relevance.
Q(... PairList attrs, Array children ) → HTMLElementRepresents a short inline quotation.
RP(... PairList attrs, Array children ) → HTMLElementProvides fallback parentheses for ruby annotations in browsers without ruby support.
RT(... PairList attrs, Array children ) → HTMLElementRepresents ruby annotation text, such as pronunciation or translation.
RUBY(... PairList attrs, Array children ) → HTMLElementRepresents ruby annotations, commonly used for East Asian typography.
S(... PairList attrs, Array children ) → HTMLElementRepresents content that is no longer relevant or accurate, usually rendered with a strikethrough.
SAMP(... PairList attrs, Array children ) → HTMLElementRepresents sample or quoted output from a program.
SMALL(... PairList attrs, Array children ) → HTMLElementRepresents side comments or small print.
SPAN(... PairList attrs, Array children ) → HTMLElementRepresents a generic inline container with no inherent semantic meaning.
STRONG(... PairList attrs, Array children ) → HTMLElementRepresents text with strong importance, seriousness, or urgency.
SUB(... PairList attrs, Array children ) → HTMLElementRepresents inline text that should be displayed as subscript for typographic reasons.
SUP(... PairList attrs, Array children ) → HTMLElementRepresents inline text that should be displayed as superscript for typographic reasons.
TIME(... PairList attrs, Array children ) → HTMLElementRepresents a time, date, duration, or other specific period in time.
U(... PairList attrs, Array children ) → HTMLElementRepresents text with a non-textual annotation, commonly rendered with an underline.
VAR(... PairList attrs, Array children ) → HTMLElementRepresents a variable name in mathematics, programming, or similar contexts.
WBR(... PairList attrs, Array children ) → HTMLElementRepresents an optional word-break opportunity.
Image and multimedia
AREA(... PairList attrs, Array children ) → HTMLElementDefines a clickable area within an image map.
AUDIO(... PairList attrs, Array children ) → HTMLElementEmbeds sound content or streamed audio in a document.
IMG(... PairList attrs, Array children ) → HTMLElementEmbeds an image into the document.
MAP(... PairList attrs, Array children ) → HTMLElementDefines an image map containing clickable areas.
TRACK(... PairList attrs, Array children ) → HTMLElementSpecifies timed text tracks or timed data for audio and video elements.
VIDEO(... PairList attrs, Array children ) → HTMLElementEmbeds a video-capable media player in the document.
Embedded content
EMBED(... PairList attrs, Array children ) → HTMLElementEmbeds external content supplied by another application, plug-in, or content source.
FENCEDFRAME(... PairList attrs, Array children ) → HTMLElementRepresents a privacy-focused nested browsing context similar to an iframe.
IFRAME(... PairList attrs, Array children ) → HTMLElementEmbeds another HTML page as a nested browsing context.
OBJECT(... PairList attrs, Array children ) → HTMLElementRepresents an external resource handled as an image, browsing context, or plug-in resource.
PICTURE(... PairList attrs, Array children ) → HTMLElementGroups alternative image sources with an img fallback.
SOURCE(... PairList attrs, Array children ) → HTMLElementSpecifies an alternative media resource for picture, audio, or video.
SVG and MathML
SVG(... PairList attrs, Array children ) → HTMLElementRepresents an SVG container and coordinate system, including SVG embedded in HTML.
MATH(... PairList attrs, Array children ) → HTMLElementRepresents the top-level MathML element for mathematical markup.
Scripting
CANVAS(... PairList attrs, Array children ) → HTMLElementProvides a drawable graphics surface for the canvas or WebGL APIs.
NOSCRIPT(... PairList attrs, Array children ) → HTMLElementProvides fallback HTML used when scripting is unsupported or disabled.
SCRIPT(... PairList attrs, Array children ) → HTMLElementEmbeds executable code or data, most commonly JavaScript.
Demarcating edits
DEL(... PairList attrs, Array children ) → HTMLElementRepresents content that has been deleted from the document.
INS(... PairList attrs, Array children ) → HTMLElementRepresents content that has been inserted into the document.
Table content
CAPTION(... PairList attrs, Array children ) → HTMLElementRepresents the caption or title of a table.
COL(... PairList attrs, Array children ) → HTMLElementRepresents one or more columns within a colgroup.
COLGROUP(... PairList attrs, Array children ) → HTMLElementRepresents a group of columns in a table.
TABLE(... PairList attrs, Array children ) → HTMLElementRepresents tabular data arranged in rows and columns.
TBODY(... PairList attrs, Array children ) → HTMLElementGroups table rows that make up the body of table data.
TD(... PairList attrs, Array children ) → HTMLElementRepresents a data cell in a table row.
TFOOT(... PairList attrs, Array children ) → HTMLElementGroups table rows that make up the footer of a table.
TH(... PairList attrs, Array children ) → HTMLElementRepresents a header cell in a table row.
THEAD(... PairList attrs, Array children ) → HTMLElementGroups table rows that make up the header of a table.
TR(... PairList attrs, Array children ) → HTMLElementRepresents a row of table cells.
Forms
BUTTON(... PairList attrs, Array children ) → HTMLElementRepresents an interactive button that can perform an action or submit a form.
DATALIST(... PairList attrs, Array children ) → HTMLElementContains option elements that provide suggested choices for another control.
FIELDSET(... PairList attrs, Array children ) → HTMLElementGroups related form controls and labels.
FORM(... PairList attrs, Array children ) → HTMLElementRepresents a section containing interactive controls for submitting information.
INPUT(... PairList attrs, Array children ) → HTMLElementRepresents an interactive form control for accepting user input.
LABEL(... PairList attrs, Array children ) → HTMLElementRepresents a caption for a form control or other user-interface item.
LEGEND(... PairList attrs, Array children ) → HTMLElementRepresents a caption for the parent fieldset.
METER(... PairList attrs, Array children ) → HTMLElementRepresents a scalar value within a known range or a fractional value.
OPTGROUP(... PairList attrs, Array children ) → HTMLElementGroups related options within a select element.
OPTION(... PairList attrs, Array children ) → HTMLElementRepresents an item in a select, optgroup, or datalist.
OUTPUT(... PairList attrs, Array children ) → HTMLElementRepresents a container for the result of a calculation or user action.
PROGRESS(... PairList attrs, Array children ) → HTMLElementRepresents the completion progress of a task.
SELECT(... PairList attrs, Array children ) → HTMLElementRepresents a control offering a menu of options.
SELECTEDCONTENT(... PairList attrs, Array children ) → HTMLElementRepresents the currently selected option content inside a closed select element.
TEXTAREA(... PairList attrs, Array children ) → HTMLElementRepresents a multi-line plain-text editing control.
Interactive elements
DETAILS(... PairList attrs, Array children ) → HTMLElementRepresents a disclosure widget whose contents can be expanded or collapsed.
DIALOG(... PairList attrs, Array children ) → HTMLElementRepresents a dialog box or other interactive component.
GEOLOCATION(... PairList attrs, Array children ) → HTMLElementCreates a control for sharing geolocation data with the page.
SUMMARY(... PairList attrs, Array children ) → HTMLElementRepresents the summary or label for a details disclosure widget.
Web Components
SLOT(... PairList attrs, Array children ) → HTMLElementRepresents a placeholder in a web component where assigned content is rendered.
TEMPLATE(... PairList attrs, Array children ) → HTMLElementHolds inert HTML that can be instantiated later by script.
Obsolete and deprecated elements
ACRONYM(... PairList attrs, Array children ) → HTMLElementObsolete element for marking an acronym or abbreviation.
BIG(... PairList attrs, Array children ) → HTMLElementObsolete element that rendered text one font size larger.
CENTER(... PairList attrs, Array children ) → HTMLElementObsolete element that centred its contents horizontally.
CONTENT(... PairList attrs, Array children ) → HTMLElementObsolete Web Components insertion point replaced by slot.
DIR(... PairList attrs, Array children ) → HTMLElementObsolete container for a directory-style list; use ul instead.
FONT(... PairList attrs, Array children ) → HTMLElementObsolete element for setting font size, colour, and face.
FRAME(... PairList attrs, Array children ) → HTMLElementObsolete element defining a frame within a frameset.
FRAMESET(... PairList attrs, Array children ) → HTMLElementObsolete element containing frame elements.
IMAGE(... PairList attrs, Array children ) → HTMLElementObsolete precursor to img.
MARQUEE(... PairList attrs, Array children ) → HTMLElementObsolete element for scrolling text.
MENUITEM(... PairList attrs, Array children ) → HTMLElementObsolete element representing a command in a popup or context menu.
NOBR(... PairList attrs, Array children ) → HTMLElementObsolete element preventing automatic line wrapping.
NOEMBED(... PairList attrs, Array children ) → HTMLElementObsolete fallback content for browsers without embed support.
NOFRAMES(... PairList attrs, Array children ) → HTMLElementObsolete fallback content for browsers without frame support.
PARAM(... PairList attrs, Array children ) → HTMLElementObsolete element defining parameters for an object element.
PLAINTEXT(... PairList attrs, Array children ) → HTMLElementObsolete element that treats all following content as raw text.
RB(... PairList attrs, Array children ) → HTMLElementObsolete ruby base-text delimiter.
RTC(... PairList attrs, Array children ) → HTMLElementObsolete container for semantic ruby annotations.
SHADOW(... PairList attrs, Array children ) → HTMLElementObsolete Web Components shadow DOM insertion point.
STRIKE(... PairList attrs, Array children ) → HTMLElementObsolete element for strikethrough text.
TT(... PairList attrs, Array children ) → HTMLElementObsolete element for teletype-style monospace text.
XMP(... PairList attrs, Array children ) → HTMLElementObsolete element for displaying uninterpreted HTML text.
SEE ALSO
html/dom.
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements.
COPYRIGHT AND LICENCE
html/tags is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.