Source Edit

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

  1. var nim = "Nim"
  2. echo h1(a(href="https://nim-lang.org", nim))

Writes the string:

  1. <h1><a href="https://nim-lang.org">Nim</a></h1>

Example:

  1. import std/htmlgen
  2. let nim = "Nim"
  3. assert h1(a(href = "https://nim-lang.org", nim)) ==
  4. """<h1><a href="https://nim-lang.org">Nim</a></h1>"""
  5. assert form(action = "test", `accept-charset` = "Content-Type") ==
  6. """<form action="test" accept-charset="Content-Type"></form>"""
  7. assert math(
  8. semantics(
  9. mrow(
  10. msup(
  11. mi("x"),
  12. mn("42")
  13. )
  14. )
  15. )
  16. ) == "<math><semantics><mrow><msup><mi>x</mi><mn>42</mn></msup></mrow></semantics></math>"
  17. assert math(
  18. semantics(
  19. annotation(encoding = "application/x-tex", title = "Latex on Web", r"x^{2} + y")
  20. )
  21. ) == """<math><semantics><annotation encoding="application/x-tex" title="Latex on Web">x^{2} + y</annotation></semantics></math>"""

Imports

macros, strutils

Consts

  1. ariaAttr = " role "

HTML DOM Aria Attributes Source Edit

  1. 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

  1. coreAttr = " accesskey class contenteditable dir hidden id lang spellcheck style tabindex title translate "

HTML DOM Core Attributes Source Edit

  1. 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

Procs

  1. proc xmlCheckedTag(argsList: NimNode; tag: string; optAttr = ""; reqAttr = "";
  2. isLeaf = false): NimNode {....raises: [], tags: [], forbids: [].}

use this procedure to define a new XML tag Source Edit

Macros

  1. macro a(e: varargs[untyped]): untyped

Generates the HTML a element. Source Edit

  1. macro abbr(e: varargs[untyped]): untyped

Generates the HTML abbr element. Source Edit

  1. macro address(e: varargs[untyped]): untyped

Generates the HTML address element. Source Edit

  1. macro annotation(e: varargs[untyped]): untyped

Generates the HTML annotation element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit

  1. macro annotation-xml(e: varargs[untyped]): untyped

Generates the HTML annotation-xml element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit

  1. macro area(e: varargs[untyped]): untyped

Generates the HTML area element. Source Edit

  1. macro article(e: varargs[untyped]): untyped

Generates the HTML article element. Source Edit

  1. macro aside(e: varargs[untyped]): untyped

Generates the HTML aside element. Source Edit

  1. macro audio(e: varargs[untyped]): untyped

Generates the HTML audio element. Source Edit

  1. macro b(e: varargs[untyped]): untyped

Generates the HTML b element. Source Edit

  1. macro base(e: varargs[untyped]): untyped

Generates the HTML base element. Source Edit

  1. macro bdi(e: varargs[untyped]): untyped

Generates the HTML bdi element. Source Edit

  1. macro bdo(e: varargs[untyped]): untyped

Generates the HTML bdo element. Source Edit

  1. macro big(e: varargs[untyped]): untyped

Generates the HTML big element. Source Edit

  1. macro blockquote(e: varargs[untyped]): untyped

Generates the HTML blockquote element. Source Edit

  1. macro body(e: varargs[untyped]): untyped

Generates the HTML body element. Source Edit

  1. macro br(e: varargs[untyped]): untyped

Generates the HTML br element. Source Edit

  1. macro button(e: varargs[untyped]): untyped

Generates the HTML button element. Source Edit

  1. macro canvas(e: varargs[untyped]): untyped

Generates the HTML canvas element. Source Edit

  1. macro caption(e: varargs[untyped]): untyped

Generates the HTML caption element. Source Edit

  1. macro center(e: varargs[untyped]): untyped

Generates the HTML center element. Source Edit

  1. macro cite(e: varargs[untyped]): untyped

Generates the HTML cite element. Source Edit

  1. macro code(e: varargs[untyped]): untyped

Generates the HTML code element. Source Edit

  1. macro col(e: varargs[untyped]): untyped

Generates the HTML col element. Source Edit

  1. macro colgroup(e: varargs[untyped]): untyped

Generates the HTML colgroup element. Source Edit

  1. macro data(e: varargs[untyped]): untyped

Generates the HTML data element. Source Edit

  1. macro datalist(e: varargs[untyped]): untyped

Generates the HTML datalist element. Source Edit

  1. macro dd(e: varargs[untyped]): untyped

Generates the HTML dd element. Source Edit

  1. macro del(e: varargs[untyped]): untyped

Generates the HTML del element. Source Edit

  1. macro details(e: varargs[untyped]): untyped

Generates the HTML details element. Source Edit

  1. macro dfn(e: varargs[untyped]): untyped

Generates the HTML dfn element. Source Edit

  1. macro dialog(e: varargs[untyped]): untyped

Generates the HTML dialog element. Source Edit

  1. macro `div`(e: varargs[untyped]): untyped

Generates the HTML div element. Source Edit

  1. macro dl(e: varargs[untyped]): untyped

Generates the HTML dl element. Source Edit

  1. macro dt(e: varargs[untyped]): untyped

Generates the HTML dt element. Source Edit

  1. macro em(e: varargs[untyped]): untyped

Generates the HTML em element. Source Edit

  1. macro embed(e: varargs[untyped]): untyped

Generates the HTML embed element. Source Edit

  1. macro fieldset(e: varargs[untyped]): untyped

Generates the HTML fieldset element. Source Edit

  1. macro figcaption(e: varargs[untyped]): untyped

Generates the HTML figcaption element. Source Edit

  1. macro figure(e: varargs[untyped]): untyped

Generates the HTML figure element. Source Edit

  1. macro footer(e: varargs[untyped]): untyped

Generates the HTML footer element. Source Edit

  1. macro form(e: varargs[untyped]): untyped

Generates the HTML form element. Source Edit

  1. macro h1(e: varargs[untyped]): untyped

Generates the HTML h1 element. Source Edit

  1. macro h2(e: varargs[untyped]): untyped

Generates the HTML h2 element. Source Edit

  1. macro h3(e: varargs[untyped]): untyped

Generates the HTML h3 element. Source Edit

  1. macro h4(e: varargs[untyped]): untyped

Generates the HTML h4 element. Source Edit

  1. macro h5(e: varargs[untyped]): untyped

Generates the HTML h5 element. Source Edit

  1. macro h6(e: varargs[untyped]): untyped

Generates the HTML h6 element. Source Edit

  1. macro head(e: varargs[untyped]): untyped

Generates the HTML head element. Source Edit

  1. macro header(e: varargs[untyped]): untyped

Generates the HTML header element. Source Edit

  1. macro hr(): untyped

Generates the HTML hr element. Source Edit

  1. macro html(e: varargs[untyped]): untyped

Generates the HTML html element. Source Edit

  1. macro i(e: varargs[untyped]): untyped

Generates the HTML i element. Source Edit

  1. macro iframe(e: varargs[untyped]): untyped

Generates the HTML iframe element. Source Edit

  1. macro img(e: varargs[untyped]): untyped

Generates the HTML img element. Source Edit

  1. macro input(e: varargs[untyped]): untyped

Generates the HTML input element. Source Edit

  1. macro ins(e: varargs[untyped]): untyped

Generates the HTML ins element. Source Edit

  1. macro kbd(e: varargs[untyped]): untyped

Generates the HTML kbd element. Source Edit

  1. macro keygen(e: varargs[untyped]): untyped

Generates the HTML keygen element. Source Edit

  1. macro label(e: varargs[untyped]): untyped

Generates the HTML label element. Source Edit

  1. macro legend(e: varargs[untyped]): untyped

Generates the HTML legend element. Source Edit

  1. macro li(e: varargs[untyped]): untyped

Generates the HTML li element. Source Edit

  1. macro link(e: varargs[untyped]): untyped

Generates the HTML link element. Source Edit

  1. macro maction(e: varargs[untyped]): untyped

Generates the HTML maction element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/maction Source Edit

  1. macro main(e: varargs[untyped]): untyped

Generates the HTML main element. Source Edit

  1. macro map(e: varargs[untyped]): untyped

Generates the HTML map element. Source Edit

  1. macro mark(e: varargs[untyped]): untyped

Generates the HTML mark element. Source Edit

  1. macro marquee(e: varargs[untyped]): untyped

Generates the HTML marquee element. Source Edit

  1. macro math(e: varargs[untyped]): untyped

Generates the HTML math element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#Examples Source Edit

  1. macro menclose(e: varargs[untyped]): untyped

Generates the HTML menclose element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/menclose Source Edit

  1. macro merror(e: varargs[untyped]): untyped

Generates the HTML merror element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/merror Source Edit

  1. macro meta(e: varargs[untyped]): untyped

Generates the HTML meta element. Source Edit

  1. macro meter(e: varargs[untyped]): untyped

Generates the HTML meter element. Source Edit

  1. macro mfenced(e: varargs[untyped]): untyped

Generates the HTML mfenced element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfenced Source Edit

  1. macro mfrac(e: varargs[untyped]): untyped

Generates the HTML mfrac element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mfrac Source Edit

  1. macro mglyph(e: varargs[untyped]): untyped

Generates the HTML mglyph element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mglyph Source Edit

  1. macro mi(e: varargs[untyped]): untyped

Generates the HTML mi element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mi Source Edit

  1. macro mlabeledtr(e: varargs[untyped]): untyped

Generates the HTML mlabeledtr element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mlabeledtr Source Edit

  1. macro mmultiscripts(e: varargs[untyped]): untyped

Generates the HTML mmultiscripts element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mmultiscripts Source Edit

  1. macro mn(e: varargs[untyped]): untyped

Generates the HTML mn element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mn Source Edit

  1. macro mo(e: varargs[untyped]): untyped

Generates the HTML mo element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mo Source Edit

  1. macro mover(e: varargs[untyped]): untyped

Generates the HTML mover element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mover Source Edit

  1. macro mpadded(e: varargs[untyped]): untyped

Generates the HTML mpadded element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mpadded Source Edit

  1. macro mphantom(e: varargs[untyped]): untyped

Generates the HTML mphantom element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mphantom Source Edit

  1. macro mroot(e: varargs[untyped]): untyped

Generates the HTML mroot element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mroot Source Edit

  1. macro mrow(e: varargs[untyped]): untyped

Generates the HTML mrow element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mrow Source Edit

  1. macro ms(e: varargs[untyped]): untyped

Generates the HTML ms element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/ms Source Edit

  1. macro mspace(e: varargs[untyped]): untyped

Generates the HTML mspace element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mspace Source Edit

  1. macro msqrt(e: varargs[untyped]): untyped

Generates the HTML msqrt element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msqrt Source Edit

  1. macro mstyle(e: varargs[untyped]): untyped

Generates the HTML mstyle element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mstyle Source Edit

  1. macro msub(e: varargs[untyped]): untyped

Generates the HTML msub element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msub Source Edit

  1. macro msubsup(e: varargs[untyped]): untyped

Generates the HTML msubsup element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msubsup Source Edit

  1. macro msup(e: varargs[untyped]): untyped

Generates the HTML msup element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/msup Source Edit

  1. macro mtable(e: varargs[untyped]): untyped

Generates the HTML mtable element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtable Source Edit

  1. macro mtd(e: varargs[untyped]): untyped

Generates the HTML mtd element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtd Source Edit

  1. macro mtext(e: varargs[untyped]): untyped

Generates the HTML mtext element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/mtext Source Edit

  1. macro munder(e: varargs[untyped]): untyped

Generates the HTML munder element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munder Source Edit

  1. macro munderover(e: varargs[untyped]): untyped

Generates the HTML munderover element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/munderover Source Edit

  1. macro nav(e: varargs[untyped]): untyped

Generates the HTML nav element. Source Edit

  1. macro noscript(e: varargs[untyped]): untyped

Generates the HTML noscript element. Source Edit

  1. macro `object`(e: varargs[untyped]): untyped

Generates the HTML object element. Source Edit

  1. macro ol(e: varargs[untyped]): untyped

Generates the HTML ol element. Source Edit

  1. macro optgroup(e: varargs[untyped]): untyped

Generates the HTML optgroup element. Source Edit

  1. macro option(e: varargs[untyped]): untyped

Generates the HTML option element. Source Edit

  1. macro output(e: varargs[untyped]): untyped

Generates the HTML output element. Source Edit

  1. macro p(e: varargs[untyped]): untyped

Generates the HTML p element. Source Edit

  1. macro param(e: varargs[untyped]): untyped

Generates the HTML param element. Source Edit

  1. macro picture(e: varargs[untyped]): untyped

Generates the HTML picture element. Source Edit

  1. macro portal(e: varargs[untyped]): untyped

Generates the HTML portal element. Source Edit

  1. macro pre(e: varargs[untyped]): untyped

Generates the HTML pre element. Source Edit

  1. macro progress(e: varargs[untyped]): untyped

Generates the HTML progress element. Source Edit

  1. macro q(e: varargs[untyped]): untyped

Generates the HTML q element. Source Edit

  1. macro rb(e: varargs[untyped]): untyped

Generates the HTML rb element. Source Edit

  1. macro rp(e: varargs[untyped]): untyped

Generates the HTML rp element. Source Edit

  1. macro rt(e: varargs[untyped]): untyped

Generates the HTML rt element. Source Edit

  1. macro rtc(e: varargs[untyped]): untyped

Generates the HTML rtc element. Source Edit

  1. macro ruby(e: varargs[untyped]): untyped

Generates the HTML ruby element. Source Edit

  1. macro s(e: varargs[untyped]): untyped

Generates the HTML s element. Source Edit

  1. macro samp(e: varargs[untyped]): untyped

Generates the HTML samp element. Source Edit

  1. macro script(e: varargs[untyped]): untyped

Generates the HTML script element. Source Edit

  1. macro section(e: varargs[untyped]): untyped

Generates the HTML section element. Source Edit

  1. macro select(e: varargs[untyped]): untyped

Generates the HTML select element. Source Edit

  1. macro semantics(e: varargs[untyped]): untyped

Generates the HTML semantics element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit

  1. macro slot(e: varargs[untyped]): untyped

Generates the HTML slot element. Source Edit

  1. macro small(e: varargs[untyped]): untyped

Generates the HTML small element. Source Edit

  1. macro source(e: varargs[untyped]): untyped

Generates the HTML source element. Source Edit

  1. macro span(e: varargs[untyped]): untyped

Generates the HTML span element. Source Edit

  1. macro strong(e: varargs[untyped]): untyped

Generates the HTML strong element. Source Edit

  1. macro style(e: varargs[untyped]): untyped

Generates the HTML style element. Source Edit

  1. macro sub(e: varargs[untyped]): untyped

Generates the HTML sub element. Source Edit

  1. macro summary(e: varargs[untyped]): untyped

Generates the HTML summary element. Source Edit

  1. macro sup(e: varargs[untyped]): untyped

Generates the HTML sup element. Source Edit

  1. macro table(e: varargs[untyped]): untyped

Generates the HTML table element. Source Edit

  1. macro tbody(e: varargs[untyped]): untyped

Generates the HTML tbody element. Source Edit

  1. macro td(e: varargs[untyped]): untyped

Generates the HTML td element. Source Edit

  1. macro `template`(e: varargs[untyped]): untyped

Generates the HTML template element. Source Edit

  1. macro textarea(e: varargs[untyped]): untyped

Generates the HTML textarea element. Source Edit

  1. macro tfoot(e: varargs[untyped]): untyped

Generates the HTML tfoot element. Source Edit

  1. macro th(e: varargs[untyped]): untyped

Generates the HTML th element. Source Edit

  1. macro thead(e: varargs[untyped]): untyped

Generates the HTML thead element. Source Edit

  1. macro time(e: varargs[untyped]): untyped

Generates the HTML time element. Source Edit

  1. macro title(e: varargs[untyped]): untyped

Generates the HTML title element. Source Edit

  1. macro tr(e: varargs[untyped]): untyped

Generates the HTML tr element. Source Edit

  1. macro track(e: varargs[untyped]): untyped

Generates the HTML track element. Source Edit

  1. macro tt(e: varargs[untyped]): untyped

Generates the HTML tt element. Source Edit

  1. macro u(e: varargs[untyped]): untyped

Generates the HTML u element. Source Edit

  1. macro ul(e: varargs[untyped]): untyped

Generates the HTML ul element. Source Edit

  1. macro `var`(e: varargs[untyped]): untyped

Generates the HTML var element. Source Edit

  1. macro video(e: varargs[untyped]): untyped

Generates the HTML video element. Source Edit

  1. macro wbr(e: varargs[untyped]): untyped

Generates the HTML wbr element. Source Edit