std/htmlgen (original) (raw)

Source Edit

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

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:

Nim

Example:

import std/htmlgen let nim = "Nim" assert h1(a(href = "https://nim-lang.org", nim)) == """

Nim

""" assert form(action = "test", accept-charset = "Content-Type") == """"""

assert math( semantics( mrow( msup( mi("x"), mn("42") ) ) ) ) == "x42"

assert math( semantics( annotation(encoding = "application/x-tex", title = "Latex on Web", r"x^{2} + y") ) ) == """x^{2} + y"""

Consts

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 AttributesSource Edit

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

HTML DOM Core AttributesSource 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 AttributesSource Edit

Procs

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

use this procedure to define a new XML tagSource Edit