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
a
element. Source Edit macro abbr(e: varargs[untyped]): untyped
- Generates the HTML
abbr
element. Source Edit macro address(e: varargs[untyped]): untyped
- Generates the HTML
address
element. Source Edit macro area(e: varargs[untyped]): untyped
- Generates the HTML
area
element. Source Edit macro article(e: varargs[untyped]): untyped
- Generates the HTML
article
element. Source Edit macro aside(e: varargs[untyped]): untyped
- Generates the HTML
aside
element. Source Edit macro audio(e: varargs[untyped]): untyped
- Generates the HTML
audio
element. Source Edit macro b(e: varargs[untyped]): untyped
- Generates the HTML
b
element. Source Edit macro base(e: varargs[untyped]): untyped
- Generates the HTML
base
element. Source Edit macro bdi(e: varargs[untyped]): untyped
- Generates the HTML
bdi
element. Source Edit macro bdo(e: varargs[untyped]): untyped
- Generates the HTML
bdo
element. Source Edit macro big(e: varargs[untyped]): untyped
- Generates the HTML
big
element. Source Edit macro blockquote(e: varargs[untyped]): untyped
- Generates the HTML
blockquote
element. Source Edit macro body(e: varargs[untyped]): untyped
- Generates the HTML
body
element. Source Edit macro br(e: varargs[untyped]): untyped
- Generates the HTML
br
element. Source Edit macro button(e: varargs[untyped]): untyped
- Generates the HTML
button
element. Source Edit macro canvas(e: varargs[untyped]): untyped
- Generates the HTML
canvas
element. Source Edit macro caption(e: varargs[untyped]): untyped
- Generates the HTML
caption
element. Source Edit macro center(e: varargs[untyped]): untyped
- Generates the HTML
center
element. Source Edit macro cite(e: varargs[untyped]): untyped
- Generates the HTML
cite
element. Source Edit macro code(e: varargs[untyped]): untyped
- Generates the HTML
code
element. Source Edit macro col(e: varargs[untyped]): untyped
- Generates the HTML
col
element. Source Edit macro colgroup(e: varargs[untyped]): untyped
- Generates the HTML
colgroup
element. Source Edit macro data(e: varargs[untyped]): untyped
- Generates the HTML
data
element. Source Edit macro datalist(e: varargs[untyped]): untyped
- Generates the HTML
datalist
element. Source Edit macro dd(e: varargs[untyped]): untyped
- Generates the HTML
dd
element. Source Edit macro del(e: varargs[untyped]): untyped
- Generates the HTML
del
element. Source Edit macro details(e: varargs[untyped]): untyped
- Generates the HTML
details
element. Source Edit macro dfn(e: varargs[untyped]): untyped
- Generates the HTML
dfn
element. Source Edit macro dialog(e: varargs[untyped]): untyped
- Generates the HTML
dialog
element. Source Edit macro `div`(e: varargs[untyped]): untyped
- Generates the HTML
div
element. Source Edit macro dl(e: varargs[untyped]): untyped
- Generates the HTML
dl
element. Source Edit macro dt(e: varargs[untyped]): untyped
- Generates the HTML
dt
element. Source Edit macro em(e: varargs[untyped]): untyped
- Generates the HTML
em
element. Source Edit macro embed(e: varargs[untyped]): untyped
- Generates the HTML
embed
element. Source Edit macro fieldset(e: varargs[untyped]): untyped
- Generates the HTML
fieldset
element. Source Edit macro figure(e: varargs[untyped]): untyped
- Generates the HTML
figure
element. Source Edit macro figcaption(e: varargs[untyped]): untyped
- Generates the HTML
figcaption
element. Source Edit macro footer(e: varargs[untyped]): untyped
- Generates the HTML
footer
element. Source Edit macro form(e: varargs[untyped]): untyped
- Generates the HTML
form
element. Source Edit macro h1(e: varargs[untyped]): untyped
- Generates the HTML
h1
element. Source Edit macro h2(e: varargs[untyped]): untyped
- Generates the HTML
h2
element. Source Edit macro h3(e: varargs[untyped]): untyped
- Generates the HTML
h3
element. Source Edit macro h4(e: varargs[untyped]): untyped
- Generates the HTML
h4
element. Source Edit macro h5(e: varargs[untyped]): untyped
- Generates the HTML
h5
element. Source Edit macro h6(e: varargs[untyped]): untyped
- Generates the HTML
h6
element. Source Edit macro head(e: varargs[untyped]): untyped
- Generates the HTML
head
element. Source Edit macro header(e: varargs[untyped]): untyped
- Generates the HTML
header
element. Source Edit macro html(e: varargs[untyped]): untyped
- Generates the HTML
html
element. Source Edit macro hr(): untyped
- Generates the HTML
hr
element. Source Edit macro i(e: varargs[untyped]): untyped
- Generates the HTML
i
element. Source Edit macro iframe(e: varargs[untyped]): untyped
- Generates the HTML
iframe
element. Source Edit macro img(e: varargs[untyped]): untyped
- Generates the HTML
img
element. Source Edit macro input(e: varargs[untyped]): untyped
- Generates the HTML
input
element. Source Edit macro ins(e: varargs[untyped]): untyped
- Generates the HTML
ins
element. Source Edit macro kbd(e: varargs[untyped]): untyped
- Generates the HTML
kbd
element. Source Edit macro keygen(e: varargs[untyped]): untyped
- Generates the HTML
keygen
element. Source Edit macro label(e: varargs[untyped]): untyped
- Generates the HTML
label
element. Source Edit macro legend(e: varargs[untyped]): untyped
- Generates the HTML
legend
element. Source Edit macro li(e: varargs[untyped]): untyped
- Generates the HTML
li
element. Source Edit macro link(e: varargs[untyped]): untyped
- Generates the HTML
link
element. Source Edit macro main(e: varargs[untyped]): untyped
- Generates the HTML
main
element. Source Edit macro map(e: varargs[untyped]): untyped
- Generates the HTML
map
element. Source Edit macro mark(e: varargs[untyped]): untyped
- Generates the HTML
mark
element. Source Edit macro marquee(e: varargs[untyped]): untyped
- Generates the HTML
marquee
element. Source Edit macro meta(e: varargs[untyped]): untyped
- Generates the HTML
meta
element. Source Edit macro meter(e: varargs[untyped]): untyped
- Generates the HTML
meter
element. Source Edit macro nav(e: varargs[untyped]): untyped
- Generates the HTML
nav
element. Source Edit macro noscript(e: varargs[untyped]): untyped
- Generates the HTML
noscript
element. Source Edit macro `object`(e: varargs[untyped]): untyped
- Generates the HTML
object
element. Source Edit macro ol(e: varargs[untyped]): untyped
- Generates the HTML
ol
element. Source Edit macro optgroup(e: varargs[untyped]): untyped
- Generates the HTML
optgroup
element. Source Edit macro option(e: varargs[untyped]): untyped
- Generates the HTML
option
element. Source Edit macro output(e: varargs[untyped]): untyped
- Generates the HTML
output
element. Source Edit macro p(e: varargs[untyped]): untyped
- Generates the HTML
p
element. Source Edit macro param(e: varargs[untyped]): untyped
- Generates the HTML
param
element. Source Edit macro picture(e: varargs[untyped]): untyped
- Generates the HTML
picture
element. Source Edit macro pre(e: varargs[untyped]): untyped
- Generates the HTML
pre
element. Source Edit macro progress(e: varargs[untyped]): untyped
- Generates the HTML
progress
element. Source Edit macro q(e: varargs[untyped]): untyped
- Generates the HTML
q
element. Source Edit macro rb(e: varargs[untyped]): untyped
- Generates the HTML
rb
element. Source Edit macro rp(e: varargs[untyped]): untyped
- Generates the HTML
rp
element. Source Edit macro rt(e: varargs[untyped]): untyped
- Generates the HTML
rt
element. Source Edit macro rtc(e: varargs[untyped]): untyped
- Generates the HTML
rtc
element. Source Edit macro ruby(e: varargs[untyped]): untyped
- Generates the HTML
ruby
element. Source Edit macro s(e: varargs[untyped]): untyped
- Generates the HTML
s
element. Source Edit macro samp(e: varargs[untyped]): untyped
- Generates the HTML
samp
element. Source Edit macro script(e: varargs[untyped]): untyped
- Generates the HTML
script
element. Source Edit macro section(e: varargs[untyped]): untyped
- Generates the HTML
section
element. Source Edit macro select(e: varargs[untyped]): untyped
- Generates the HTML
select
element. Source Edit macro slot(e: varargs[untyped]): untyped
- Generates the HTML
slot
element. Source Edit macro small(e: varargs[untyped]): untyped
- Generates the HTML
small
element. Source Edit macro source(e: varargs[untyped]): untyped
- Generates the HTML
source
element. Source Edit macro span(e: varargs[untyped]): untyped
- Generates the HTML
span
element. Source Edit macro strong(e: varargs[untyped]): untyped
- Generates the HTML
strong
element. Source Edit macro style(e: varargs[untyped]): untyped
- Generates the HTML
style
element. Source Edit macro sub(e: varargs[untyped]): untyped
- Generates the HTML
sub
element. Source Edit macro summary(e: varargs[untyped]): untyped
- Generates the HTML
summary
element. Source Edit macro sup(e: varargs[untyped]): untyped
- Generates the HTML
sup
element. Source Edit macro table(e: varargs[untyped]): untyped
- Generates the HTML
table
element. Source Edit macro tbody(e: varargs[untyped]): untyped
- Generates the HTML
tbody
element. Source Edit macro td(e: varargs[untyped]): untyped
- Generates the HTML
td
element. Source Edit macro `template`(e: varargs[untyped]): untyped
- Generates the HTML
template
element. Source Edit macro textarea(e: varargs[untyped]): untyped
- Generates the HTML
textarea
element. Source Edit macro tfoot(e: varargs[untyped]): untyped
- Generates the HTML
tfoot
element. Source Edit macro th(e: varargs[untyped]): untyped
- Generates the HTML
th
element. Source Edit macro thead(e: varargs[untyped]): untyped
- Generates the HTML
thead
element. Source Edit macro time(e: varargs[untyped]): untyped
- Generates the HTML
time
element. Source Edit macro title(e: varargs[untyped]): untyped
- Generates the HTML
title
element. Source Edit macro tr(e: varargs[untyped]): untyped
- Generates the HTML
tr
element. Source Edit macro track(e: varargs[untyped]): untyped
- Generates the HTML
track
element. Source Edit macro tt(e: varargs[untyped]): untyped
- Generates the HTML
tt
element. Source Edit macro u(e: varargs[untyped]): untyped
- Generates the HTML
u
element. Source Edit macro ul(e: varargs[untyped]): untyped
- Generates the HTML
ul
element. Source Edit macro `var`(e: varargs[untyped]): untyped
- Generates the HTML
var
element. Source Edit macro video(e: varargs[untyped]): untyped
- Generates the HTML
video
element. Source Edit macro wbr(e: varargs[untyped]): untyped
- Generates the HTML
wbr
element. Source Edit 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/htmlgen.html