htmlgen
Do yourself a favor and import the module as from htmlgen import nil and then fully qualify the macros.
Note: The Karax project (nimble install karax) has a better way to achieve the same, see https://github.com/pragmagic/karax/blob/master/tests/nativehtmlgen.nim for an example.
This module implements a simple XML and HTML code generator. Each commonly used HTML tag has a corresponding macro that generates a string with its HTML representation.
MathML
MathML is supported, MathML is part of HTML5. MathML is an Standard ISO/IEC 40314 from year 2015. MathML allows you to draw advanced math on the web, visually similar to Latex math.
Examples
var nim = "Nim" echo h1(a(href="https://nim-lang.org", nim))
Writes the string:
<h1><a href="https://nim-lang.org">Nim</a></h1>
Example:
let nim = "Nim"
assert h1(a(href = "https://nim-lang.org", nim)) ==
  """<h1><a href="https://nim-lang.org">Nim</a></h1>"""
assert form(action = "test", `accept-charset` = "Content-Type") ==
  """<form action="test" accept-charset="Content-Type"></form>"""
assert math(
  semantics(
    mrow(
      msup(
        mi("x"),
        mn("42")
      )
    )
  )
) == "<math><semantics><mrow><msup><mi>x</mi><mn>42</mn></msup></mrow></semantics></math>"
assert math(
  semantics(
    annotation(encoding = "application/x-tex", title = "Latex on Web", r"x^{2} + y")
  )
) == """<math><semantics><annotation encoding="application/x-tex" title="Latex on Web">x^{2} + y</annotation></semantics></math>"""  Imports
Consts
coreAttr = " accesskey class contenteditable dir hidden id lang spellcheck style tabindex title translate "
- HTML DOM Core Attributes Source Edit
 eventAttr = "onabort onblur oncancel oncanplay oncanplaythrough onchange onclick oncuechange ondblclick ondurationchange onemptied onended onerror onfocus oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmousedown onmouseenter onmouseleave onmousemove onmouseout onmouseover onmouseup onmousewheel onpause onplay onplaying onprogress onratechange onreset onresize onscroll onseeked onseeking onselect onshow onstalled onsubmit onsuspend ontimeupdate ontoggle onvolumechange onwaiting "
- HTML DOM Event Attributes Source Edit
 ariaAttr = " role "
- HTML DOM Aria Attributes Source Edit
 commonAttr = " accesskey class contenteditable dir hidden id lang spellcheck style tabindex title translate onabort onblur oncancel oncanplay oncanplaythrough onchange onclick oncuechange ondblclick ondurationchange onemptied onended onerror onfocus oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart onmousedown onmouseenter onmouseleave onmousemove onmouseout onmouseover onmouseup onmousewheel onpause onplay onplaying onprogress onratechange onreset onresize onscroll onseeked onseeking onselect onshow onstalled onsubmit onsuspend ontimeupdate ontoggle onvolumechange onwaiting role "
- HTML DOM Common Attributes Source Edit
 
Procs
proc xmlCheckedTag(argsList: NimNode; tag: string; optAttr = ""; reqAttr = ""; isLeaf = false): NimNode {...}{.compileTime, raises: [], tags: [].}- use this procedure to define a new XML tag Source Edit
 
Macros
macro a(e: varargs[untyped]): untyped
-  Generates the HTML 
aelement. Source Edit macro abbr(e: varargs[untyped]): untyped
-  Generates the HTML 
abbrelement. Source Edit macro address(e: varargs[untyped]): untyped
-  Generates the HTML 
addresselement. Source Edit macro area(e: varargs[untyped]): untyped
-  Generates the HTML 
areaelement. Source Edit macro article(e: varargs[untyped]): untyped
-  Generates the HTML 
articleelement. Source Edit macro aside(e: varargs[untyped]): untyped
-  Generates the HTML 
asideelement. Source Edit macro audio(e: varargs[untyped]): untyped
-  Generates the HTML 
audioelement. Source Edit macro b(e: varargs[untyped]): untyped
-  Generates the HTML 
belement. Source Edit macro base(e: varargs[untyped]): untyped
-  Generates the HTML 
baseelement. Source Edit macro bdi(e: varargs[untyped]): untyped
-  Generates the HTML 
bdielement. Source Edit macro bdo(e: varargs[untyped]): untyped
-  Generates the HTML 
bdoelement. Source Edit macro big(e: varargs[untyped]): untyped
-  Generates the HTML 
bigelement. Source Edit macro blockquote(e: varargs[untyped]): untyped
-  Generates the HTML 
blockquoteelement. Source Edit macro body(e: varargs[untyped]): untyped
-  Generates the HTML 
bodyelement. Source Edit macro br(e: varargs[untyped]): untyped
-  Generates the HTML 
brelement. Source Edit macro button(e: varargs[untyped]): untyped
-  Generates the HTML 
buttonelement. Source Edit macro canvas(e: varargs[untyped]): untyped
-  Generates the HTML 
canvaselement. Source Edit macro caption(e: varargs[untyped]): untyped
-  Generates the HTML 
captionelement. Source Edit macro center(e: varargs[untyped]): untyped
-  Generates the HTML 
centerelement. Source Edit macro cite(e: varargs[untyped]): untyped
-  Generates the HTML 
citeelement. Source Edit macro code(e: varargs[untyped]): untyped
-  Generates the HTML 
codeelement. Source Edit macro col(e: varargs[untyped]): untyped
-  Generates the HTML 
colelement. Source Edit macro colgroup(e: varargs[untyped]): untyped
-  Generates the HTML 
colgroupelement. Source Edit macro data(e: varargs[untyped]): untyped
-  Generates the HTML 
dataelement. Source Edit macro datalist(e: varargs[untyped]): untyped
-  Generates the HTML 
datalistelement. Source Edit macro dd(e: varargs[untyped]): untyped
-  Generates the HTML 
ddelement. Source Edit macro del(e: varargs[untyped]): untyped
-  Generates the HTML 
delelement. Source Edit macro details(e: varargs[untyped]): untyped
-  Generates the HTML 
detailselement. Source Edit macro dfn(e: varargs[untyped]): untyped
-  Generates the HTML 
dfnelement. Source Edit macro dialog(e: varargs[untyped]): untyped
-  Generates the HTML 
dialogelement. Source Edit macro `div`(e: varargs[untyped]): untyped
-  Generates the HTML 
divelement. Source Edit macro dl(e: varargs[untyped]): untyped
-  Generates the HTML 
dlelement. Source Edit macro dt(e: varargs[untyped]): untyped
-  Generates the HTML 
dtelement. Source Edit macro em(e: varargs[untyped]): untyped
-  Generates the HTML 
emelement. Source Edit macro embed(e: varargs[untyped]): untyped
-  Generates the HTML 
embedelement. Source Edit macro fieldset(e: varargs[untyped]): untyped
-  Generates the HTML 
fieldsetelement. Source Edit macro figure(e: varargs[untyped]): untyped
-  Generates the HTML 
figureelement. Source Edit macro figcaption(e: varargs[untyped]): untyped
-  Generates the HTML 
figcaptionelement. Source Edit macro footer(e: varargs[untyped]): untyped
-  Generates the HTML 
footerelement. Source Edit macro form(e: varargs[untyped]): untyped
-  Generates the HTML 
formelement. Source Edit macro h1(e: varargs[untyped]): untyped
-  Generates the HTML 
h1element. Source Edit macro h2(e: varargs[untyped]): untyped
-  Generates the HTML 
h2element. Source Edit macro h3(e: varargs[untyped]): untyped
-  Generates the HTML 
h3element. Source Edit macro h4(e: varargs[untyped]): untyped
-  Generates the HTML 
h4element. Source Edit macro h5(e: varargs[untyped]): untyped
-  Generates the HTML 
h5element. Source Edit macro h6(e: varargs[untyped]): untyped
-  Generates the HTML 
h6element. Source Edit macro head(e: varargs[untyped]): untyped
-  Generates the HTML 
headelement. Source Edit macro header(e: varargs[untyped]): untyped
-  Generates the HTML 
headerelement. Source Edit macro html(e: varargs[untyped]): untyped
-  Generates the HTML 
htmlelement. Source Edit macro hr(): untyped
-  Generates the HTML 
hrelement. Source Edit macro i(e: varargs[untyped]): untyped
-  Generates the HTML 
ielement. Source Edit macro iframe(e: varargs[untyped]): untyped
-  Generates the HTML 
iframeelement. Source Edit macro img(e: varargs[untyped]): untyped
-  Generates the HTML 
imgelement. Source Edit macro input(e: varargs[untyped]): untyped
-  Generates the HTML 
inputelement. Source Edit macro ins(e: varargs[untyped]): untyped
-  Generates the HTML 
inselement. Source Edit macro kbd(e: varargs[untyped]): untyped
-  Generates the HTML 
kbdelement. Source Edit macro keygen(e: varargs[untyped]): untyped
-  Generates the HTML 
keygenelement. Source Edit macro label(e: varargs[untyped]): untyped
-  Generates the HTML 
labelelement. Source Edit macro legend(e: varargs[untyped]): untyped
-  Generates the HTML 
legendelement. Source Edit macro li(e: varargs[untyped]): untyped
-  Generates the HTML 
lielement. Source Edit macro link(e: varargs[untyped]): untyped
-  Generates the HTML 
linkelement. Source Edit macro main(e: varargs[untyped]): untyped
-  Generates the HTML 
mainelement. Source Edit macro map(e: varargs[untyped]): untyped
-  Generates the HTML 
mapelement. Source Edit macro mark(e: varargs[untyped]): untyped
-  Generates the HTML 
markelement. Source Edit macro marquee(e: varargs[untyped]): untyped
-  Generates the HTML 
marqueeelement. Source Edit macro meta(e: varargs[untyped]): untyped
-  Generates the HTML 
metaelement. Source Edit macro meter(e: varargs[untyped]): untyped
-  Generates the HTML 
meterelement. Source Edit macro nav(e: varargs[untyped]): untyped
-  Generates the HTML 
navelement. Source Edit macro noscript(e: varargs[untyped]): untyped
-  Generates the HTML 
noscriptelement. Source Edit macro `object`(e: varargs[untyped]): untyped
-  Generates the HTML 
objectelement. Source Edit macro ol(e: varargs[untyped]): untyped
-  Generates the HTML 
olelement. Source Edit macro optgroup(e: varargs[untyped]): untyped
-  Generates the HTML 
optgroupelement. Source Edit macro option(e: varargs[untyped]): untyped
-  Generates the HTML 
optionelement. Source Edit macro output(e: varargs[untyped]): untyped
-  Generates the HTML 
outputelement. Source Edit macro p(e: varargs[untyped]): untyped
-  Generates the HTML 
pelement. Source Edit macro param(e: varargs[untyped]): untyped
-  Generates the HTML 
paramelement. Source Edit macro picture(e: varargs[untyped]): untyped
-  Generates the HTML 
pictureelement. Source Edit macro pre(e: varargs[untyped]): untyped
-  Generates the HTML 
preelement. Source Edit macro progress(e: varargs[untyped]): untyped
-  Generates the HTML 
progresselement. Source Edit macro q(e: varargs[untyped]): untyped
-  Generates the HTML 
qelement. Source Edit macro rb(e: varargs[untyped]): untyped
-  Generates the HTML 
rbelement. Source Edit macro rp(e: varargs[untyped]): untyped
-  Generates the HTML 
rpelement. Source Edit macro rt(e: varargs[untyped]): untyped
-  Generates the HTML 
rtelement. Source Edit macro rtc(e: varargs[untyped]): untyped
-  Generates the HTML 
rtcelement. Source Edit macro ruby(e: varargs[untyped]): untyped
-  Generates the HTML 
rubyelement. Source Edit macro s(e: varargs[untyped]): untyped
-  Generates the HTML 
selement. Source Edit macro samp(e: varargs[untyped]): untyped
-  Generates the HTML 
sampelement. Source Edit macro script(e: varargs[untyped]): untyped
-  Generates the HTML 
scriptelement. Source Edit macro section(e: varargs[untyped]): untyped
-  Generates the HTML 
sectionelement. Source Edit macro select(e: varargs[untyped]): untyped
-  Generates the HTML 
selectelement. Source Edit macro slot(e: varargs[untyped]): untyped
-  Generates the HTML 
slotelement. Source Edit macro small(e: varargs[untyped]): untyped
-  Generates the HTML 
smallelement. Source Edit macro source(e: varargs[untyped]): untyped
-  Generates the HTML 
sourceelement. Source Edit macro span(e: varargs[untyped]): untyped
-  Generates the HTML 
spanelement. Source Edit macro strong(e: varargs[untyped]): untyped
-  Generates the HTML 
strongelement. Source Edit macro style(e: varargs[untyped]): untyped
-  Generates the HTML 
styleelement. Source Edit macro sub(e: varargs[untyped]): untyped
-  Generates the HTML 
subelement. Source Edit macro summary(e: varargs[untyped]): untyped
-  Generates the HTML 
summaryelement. Source Edit macro sup(e: varargs[untyped]): untyped
-  Generates the HTML 
supelement. Source Edit macro table(e: varargs[untyped]): untyped
-  Generates the HTML 
tableelement. Source Edit macro tbody(e: varargs[untyped]): untyped
-  Generates the HTML 
tbodyelement. Source Edit macro td(e: varargs[untyped]): untyped
-  Generates the HTML 
tdelement. Source Edit macro `template`(e: varargs[untyped]): untyped
-  Generates the HTML 
templateelement. Source Edit macro textarea(e: varargs[untyped]): untyped
-  Generates the HTML 
textareaelement. Source Edit macro tfoot(e: varargs[untyped]): untyped
-  Generates the HTML 
tfootelement. Source Edit macro th(e: varargs[untyped]): untyped
-  Generates the HTML 
thelement. Source Edit macro thead(e: varargs[untyped]): untyped
-  Generates the HTML 
theadelement. Source Edit macro time(e: varargs[untyped]): untyped
-  Generates the HTML 
timeelement. Source Edit macro title(e: varargs[untyped]): untyped
-  Generates the HTML 
titleelement. Source Edit macro tr(e: varargs[untyped]): untyped
-  Generates the HTML 
trelement. Source Edit macro track(e: varargs[untyped]): untyped
-  Generates the HTML 
trackelement. Source Edit macro tt(e: varargs[untyped]): untyped
-  Generates the HTML 
ttelement. Source Edit macro u(e: varargs[untyped]): untyped
-  Generates the HTML 
uelement. Source Edit macro ul(e: varargs[untyped]): untyped
-  Generates the HTML 
ulelement. Source Edit macro `var`(e: varargs[untyped]): untyped
-  Generates the HTML 
varelement. Source Edit macro video(e: varargs[untyped]): untyped
-  Generates the HTML 
videoelement. Source Edit macro wbr(e: varargs[untyped]): untyped
-  Generates the HTML 
wbrelement. Source Edit macro math(e: varargs[untyped]): untyped
-  Generates the HTML 
mathelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#Examples Source Edit macro maction(e: varargs[untyped]): untyped
-  Generates the HTML 
mactionelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/maction Source Edit macro menclose(e: varargs[untyped]): untyped
-  Generates the HTML 
mencloseelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/menclose Source Edit macro merror(e: varargs[untyped]): untyped
-  Generates the HTML 
merrorelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/merror Source Edit macro mfenced(e: varargs[untyped]): untyped
-  Generates the HTML 
mfencedelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfenced Source Edit macro mfrac(e: varargs[untyped]): untyped
-  Generates the HTML 
mfracelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfrac Source Edit macro mglyph(e: varargs[untyped]): untyped
-  Generates the HTML 
mglyphelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mglyph Source Edit macro mi(e: varargs[untyped]): untyped
-  Generates the HTML 
mielement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mi Source Edit macro mlabeledtr(e: varargs[untyped]): untyped
-  Generates the HTML 
mlabeledtrelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mlabeledtr Source Edit macro mmultiscripts(e: varargs[untyped]): untyped
-  Generates the HTML 
mmultiscriptselement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mmultiscripts Source Edit macro mn(e: varargs[untyped]): untyped
-  Generates the HTML 
mnelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mn Source Edit macro mo(e: varargs[untyped]): untyped
-  Generates the HTML 
moelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo Source Edit macro mover(e: varargs[untyped]): untyped
-  Generates the HTML 
moverelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mover Source Edit macro mpadded(e: varargs[untyped]): untyped
-  Generates the HTML 
mpaddedelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mpadded Source Edit macro mphantom(e: varargs[untyped]): untyped
-  Generates the HTML 
mphantomelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mphantom Source Edit macro mroot(e: varargs[untyped]): untyped
-  Generates the HTML 
mrootelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mroot Source Edit macro mrow(e: varargs[untyped]): untyped
-  Generates the HTML 
mrowelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mrow Source Edit macro ms(e: varargs[untyped]): untyped
-  Generates the HTML 
mselement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/ms Source Edit macro mspace(e: varargs[untyped]): untyped
-  Generates the HTML 
mspaceelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mspace Source Edit macro msqrt(e: varargs[untyped]): untyped
-  Generates the HTML 
msqrtelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msqrt Source Edit macro mstyle(e: varargs[untyped]): untyped
-  Generates the HTML 
mstyleelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mstyle Source Edit macro msub(e: varargs[untyped]): untyped
-  Generates the HTML 
msubelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msub Source Edit macro msubsup(e: varargs[untyped]): untyped
-  Generates the HTML 
msubsupelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msubsup Source Edit macro msup(e: varargs[untyped]): untyped
-  Generates the HTML 
msupelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msup Source Edit macro mtable(e: varargs[untyped]): untyped
-  Generates the HTML 
mtableelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtable Source Edit macro mtd(e: varargs[untyped]): untyped
-  Generates the HTML 
mtdelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtd Source Edit macro mtext(e: varargs[untyped]): untyped
-  Generates the HTML 
mtextelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtext Source Edit macro munder(e: varargs[untyped]): untyped
-  Generates the HTML 
munderelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munder Source Edit macro munderover(e: varargs[untyped]): untyped
-  Generates the HTML 
munderoverelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munderover Source Edit macro semantics(e: varargs[untyped]): untyped
-  Generates the HTML 
semanticselement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit macro annotation(e: varargs[untyped]): untyped
-  Generates the HTML 
annotationelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit macro annotation-xml(e: varargs[untyped]): untyped
-  Generates the HTML 
annotation-xmlelement. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit 
    © 2006–2021 Andreas Rumpf
Licensed under the MIT License.
    https://nim-lang.org/docs/htmlgen.html