Do yourself a favor and import the module as from std/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 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.
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:
import std/htmlgen
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>""" 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 "
coreAttr = " accesskey class contenteditable dir hidden id lang spellcheck style tabindex title translate "
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 "
macro annotation(e: varargs[untyped]): untyped
annotation element. 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
annotation-xml element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit macro maction(e: varargs[untyped]): untyped
maction element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/maction Source Edit macro math(e: varargs[untyped]): untyped
math element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#Examples Source Edit macro menclose(e: varargs[untyped]): untyped
menclose element. 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
merror element. 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
mfenced element. 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
mfrac element. 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
mglyph element. 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
mi element. 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
mlabeledtr element. 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
mmultiscripts element. 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
mn element. 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
mo element. 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
mover element. 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
mpadded element. 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
mphantom element. 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
mroot element. 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
mrow element. 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
ms element. 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
mspace element. 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
msqrt element. 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
mstyle element. 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
msub element. 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
msubsup element. 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
msup element. 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
mtable element. 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
mtd element. 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
mtext element. 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
munder element. 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
munderover element. 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
semantics element. MathML https://wikipedia.org/wiki/MathML https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics Source Edit
© 2006–2024 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/htmlgen.html