html — typed HTML5 for nimony

A registry of every HTML5 element and its attributes (void / deprecated / experimental markers), plus a document-tree builder and a correct, escaping, void-aware renderer. Pure logic, standard library only, no dependencies. For nimony / Nim 3.0.

Repo → github.com/aoughwl/html

import html

isElement("section")       # true
isVoidElement("br")        # true
isAttribute("a", "href")   # true
isAttribute("div", "href") # false   (href is not valid on <div>)

echo $el("a", @[attr("href", "/x?a=1&b=2")], @[text("go & see <it>")])
# <a href="/x?a=1&amp;b=2">go &amp; see &lt;it&gt;</a>

Two halves

A registry, driven by a baked HTML5 table:

proc result
isElement(name) is name a known HTML element (case-insensitive)
isVoidElement(name) void element — no children, no closing tag (<br>, <img>, …)
isDeprecated(name) obsolete element (<center>, <font>, <marquee>, …)
isExperimental(name) not yet baseline (<fencedframe>, …)
isGlobalAttribute(attr) global attribute, incl. data-* / aria-* / on* families
isAttribute(element, attr) valid on that element (global or element-specific)
elementAttributes(element) the element-specific attributes declared for it

A document treeHTMLNode (element / text / comment / raw) and HTML (a sequence of them) with a builder (el, attr, text) and an escaping, void-aware renderer ($).

Pairs with css for validation and web for the combined DSL.


Back to top

aoughwl — next-gen self-hosted platform for things n stuff. Reach out on Discord (timbuktu_guy) for access to the private backends.

This site uses Just the Docs, a documentation theme for Jekyll.