htmlgen.nim 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## **Warning**: This module uses ``immediate`` macros which are known to
  10. ## cause problems. Do yourself a favor and import the module
  11. ## as ``from htmlgen import nil`` and then fully qualify the macros.
  12. ##
  13. ##
  14. ## This module implements a simple `XML`:idx: and `HTML`:idx: code
  15. ## generator. Each commonly used HTML tag has a corresponding macro
  16. ## that generates a string with its HTML representation.
  17. ##
  18. ## Example:
  19. ##
  20. ## .. code-block:: Nim
  21. ## var nim = "Nim"
  22. ## echo h1(a(href="http://nim-lang.org", nim))
  23. ##
  24. ## Writes the string::
  25. ##
  26. ## <h1><a href="http://nim-lang.org">Nim</a></h1>
  27. ##
  28. import
  29. macros, strutils
  30. const
  31. coreAttr* = " accesskey class contenteditable dir hidden id lang " &
  32. "spellcheck style tabindex title translate " ## HTML DOM Core Attributes
  33. eventAttr* = "onabort onblur oncancel oncanplay oncanplaythrough onchange " &
  34. "onclick oncuechange ondblclick ondurationchange onemptied onended " &
  35. "onerror onfocus oninput oninvalid onkeydown onkeypress onkeyup onload " &
  36. "onloadeddata onloadedmetadata onloadstart onmousedown onmouseenter " &
  37. "onmouseleave onmousemove onmouseout onmouseover onmouseup onmousewheel " &
  38. "onpause onplay onplaying onprogress onratechange onreset onresize " &
  39. "onscroll onseeked onseeking onselect onshow onstalled onsubmit " &
  40. "onsuspend ontimeupdate ontoggle onvolumechange onwaiting " ## HTML DOM Event Attributes
  41. ariaAttr* = " role " ## HTML DOM Aria Attributes
  42. commonAttr* = coreAttr & eventAttr & ariaAttr ## HTML DOM Common Attributes
  43. proc getIdent(e: NimNode): string {.compileTime.} =
  44. case e.kind
  45. of nnkIdent:
  46. result = e.strVal.normalize
  47. of nnkAccQuoted:
  48. result = getIdent(e[0])
  49. for i in 1 .. e.len-1:
  50. result.add getIdent(e[i])
  51. else: error("cannot extract identifier from node: " & toStrLit(e).strVal)
  52. proc delete[T](s: var seq[T], attr: T): bool =
  53. var idx = find(s, attr)
  54. if idx >= 0:
  55. var L = s.len
  56. s[idx] = s[L-1]
  57. setLen(s, L-1)
  58. result = true
  59. proc xmlCheckedTag*(e: NimNode, tag: string, optAttr = "", reqAttr = "",
  60. isLeaf = false): NimNode {.compileTime.} =
  61. ## use this procedure to define a new XML tag
  62. # copy the attributes; when iterating over them these lists
  63. # will be modified, so that each attribute is only given one value
  64. var req = splitWhitespace(reqAttr)
  65. var opt = splitWhitespace(optAttr)
  66. result = newNimNode(nnkBracket, e)
  67. result.add(newStrLitNode("<"))
  68. result.add(newStrLitNode(tag))
  69. # first pass over attributes:
  70. for i in 1..e.len-1:
  71. if e[i].kind == nnkExprEqExpr:
  72. var name = getIdent(e[i][0])
  73. if delete(req, name) or delete(opt, name):
  74. result.add(newStrLitNode(" "))
  75. result.add(newStrLitNode(name))
  76. result.add(newStrLitNode("=\""))
  77. result.add(e[i][1])
  78. result.add(newStrLitNode("\""))
  79. else:
  80. error("invalid attribute for '" & tag & "' element: " & name)
  81. # check each required attribute exists:
  82. if req.len > 0:
  83. error(req[0] & " attribute for '" & tag & "' element expected")
  84. if isLeaf:
  85. for i in 1..e.len-1:
  86. if e[i].kind != nnkExprEqExpr:
  87. error("element " & tag & " cannot be nested")
  88. result.add(newStrLitNode(" />"))
  89. else:
  90. result.add(newStrLitNode(">"))
  91. # second pass over elements:
  92. for i in 1..e.len-1:
  93. if e[i].kind != nnkExprEqExpr: result.add(e[i])
  94. result.add(newStrLitNode("</"))
  95. result.add(newStrLitNode(tag))
  96. result.add(newStrLitNode(">"))
  97. when compiles(nestList(ident"&", result)):
  98. result = nestList(ident"&", result)
  99. else:
  100. result = nestList(!"&", result)
  101. macro a*(e: varargs[untyped]): untyped =
  102. ## generates the HTML ``a`` element.
  103. let e = callsite()
  104. result = xmlCheckedTag(e, "a", "href target download rel hreflang type " &
  105. commonAttr)
  106. macro abbr*(e: varargs[untyped]): untyped =
  107. ## generates the HTML ``abbr`` element.
  108. let e = callsite()
  109. result = xmlCheckedTag(e, "abbr", commonAttr)
  110. macro address*(e: varargs[untyped]): untyped =
  111. ## generates the HTML ``address`` element.
  112. let e = callsite()
  113. result = xmlCheckedTag(e, "address", commonAttr)
  114. macro area*(e: varargs[untyped]): untyped =
  115. ## generates the HTML ``area`` element.
  116. let e = callsite()
  117. result = xmlCheckedTag(e, "area", "coords download href hreflang rel " &
  118. "shape target type" & commonAttr, "alt", true)
  119. macro article*(e: varargs[untyped]): untyped =
  120. ## generates the HTML ``article`` element.
  121. let e = callsite()
  122. result = xmlCheckedTag(e, "article", commonAttr)
  123. macro aside*(e: varargs[untyped]): untyped =
  124. ## generates the HTML ``aside`` element.
  125. let e = callsite()
  126. result = xmlCheckedTag(e, "aside", commonAttr)
  127. macro audio*(e: varargs[untyped]): untyped =
  128. ## generates the HTML ``audio`` element.
  129. let e = callsite()
  130. result = xmlCheckedTag(e, "audio", "src crossorigin preload " &
  131. "autoplay mediagroup loop muted controls" & commonAttr)
  132. macro b*(e: varargs[untyped]): untyped =
  133. ## generates the HTML ``b`` element.
  134. let e = callsite()
  135. result = xmlCheckedTag(e, "b", commonAttr)
  136. macro base*(e: varargs[untyped]): untyped =
  137. ## generates the HTML ``base`` element.
  138. let e = callsite()
  139. result = xmlCheckedTag(e, "base", "href target" & commonAttr, "", true)
  140. macro bdi*(e: varargs[untyped]): untyped =
  141. ## generates the HTML ``bdi`` element.
  142. let e = callsite()
  143. result = xmlCheckedTag(e, "bdi", commonAttr)
  144. macro bdo*(e: varargs[untyped]): untyped =
  145. ## generates the HTML ``bdo`` element.
  146. let e = callsite()
  147. result = xmlCheckedTag(e, "bdo", commonAttr)
  148. macro big*(e: varargs[untyped]): untyped =
  149. ## generates the HTML ``big`` element.
  150. let e = callsite()
  151. result = xmlCheckedTag(e, "big", commonAttr)
  152. macro blockquote*(e: varargs[untyped]): untyped =
  153. ## generates the HTML ``blockquote`` element.
  154. let e = callsite()
  155. result = xmlCheckedTag(e, "blockquote", " cite" & commonAttr)
  156. macro body*(e: varargs[untyped]): untyped =
  157. ## generates the HTML ``body`` element.
  158. let e = callsite()
  159. result = xmlCheckedTag(e, "body", "onafterprint onbeforeprint " &
  160. "onbeforeunload onhashchange onmessage onoffline ononline onpagehide " &
  161. "onpageshow onpopstate onstorage onunload" & commonAttr)
  162. macro br*(e: varargs[untyped]): untyped =
  163. ## generates the HTML ``br`` element.
  164. let e = callsite()
  165. result = xmlCheckedTag(e, "br", commonAttr, "", true)
  166. macro button*(e: varargs[untyped]): untyped =
  167. ## generates the HTML ``button`` element.
  168. let e = callsite()
  169. result = xmlCheckedTag(e, "button", "autofocus disabled form formaction " &
  170. "formenctype formmethod formnovalidate formtarget menu name type value" &
  171. commonAttr)
  172. macro canvas*(e: varargs[untyped]): untyped =
  173. ## generates the HTML ``canvas`` element.
  174. let e = callsite()
  175. result = xmlCheckedTag(e, "canvas", "width height" & commonAttr)
  176. macro caption*(e: varargs[untyped]): untyped =
  177. ## generates the HTML ``caption`` element.
  178. let e = callsite()
  179. result = xmlCheckedTag(e, "caption", commonAttr)
  180. macro center*(e: varargs[untyped]): untyped =
  181. ## Generates the HTML ``center`` element.
  182. let e = callsite()
  183. result = xmlCheckedTag(e, "center", commonAttr)
  184. macro cite*(e: varargs[untyped]): untyped =
  185. ## generates the HTML ``cite`` element.
  186. let e = callsite()
  187. result = xmlCheckedTag(e, "cite", commonAttr)
  188. macro code*(e: varargs[untyped]): untyped =
  189. ## generates the HTML ``code`` element.
  190. let e = callsite()
  191. result = xmlCheckedTag(e, "code", commonAttr)
  192. macro col*(e: varargs[untyped]): untyped =
  193. ## generates the HTML ``col`` element.
  194. let e = callsite()
  195. result = xmlCheckedTag(e, "col", "span" & commonAttr, "", true)
  196. macro colgroup*(e: varargs[untyped]): untyped =
  197. ## generates the HTML ``colgroup`` element.
  198. let e = callsite()
  199. result = xmlCheckedTag(e, "colgroup", "span" & commonAttr)
  200. macro data*(e: varargs[untyped]): untyped =
  201. ## generates the HTML ``data`` element.
  202. let e = callsite()
  203. result = xmlCheckedTag(e, "data", "value" & commonAttr)
  204. macro datalist*(e: varargs[untyped]): untyped =
  205. ## generates the HTML ``datalist`` element.
  206. let e = callsite()
  207. result = xmlCheckedTag(e, "datalist", commonAttr)
  208. macro dd*(e: varargs[untyped]): untyped =
  209. ## generates the HTML ``dd`` element.
  210. let e = callsite()
  211. result = xmlCheckedTag(e, "dd", commonAttr)
  212. macro del*(e: varargs[untyped]): untyped =
  213. ## generates the HTML ``del`` element.
  214. let e = callsite()
  215. result = xmlCheckedTag(e, "del", "cite datetime" & commonAttr)
  216. macro details*(e: varargs[untyped]): untyped =
  217. ## Generates the HTML ``details`` element.
  218. let e = callsite()
  219. result = xmlCheckedTag(e, "details", commonAttr & "open")
  220. macro dfn*(e: varargs[untyped]): untyped =
  221. ## generates the HTML ``dfn`` element.
  222. let e = callsite()
  223. result = xmlCheckedTag(e, "dfn", commonAttr)
  224. macro dialog*(e: varargs[untyped]): untyped =
  225. ## Generates the HTML ``dialog`` element.
  226. let e = callsite()
  227. result = xmlCheckedTag(e, "dialog", commonAttr & "open")
  228. macro `div`*(e: varargs[untyped]): untyped =
  229. ## generates the HTML ``div`` element.
  230. let e = callsite()
  231. result = xmlCheckedTag(e, "div", commonAttr)
  232. macro dl*(e: varargs[untyped]): untyped =
  233. ## generates the HTML ``dl`` element.
  234. let e = callsite()
  235. result = xmlCheckedTag(e, "dl", commonAttr)
  236. macro dt*(e: varargs[untyped]): untyped =
  237. ## generates the HTML ``dt`` element.
  238. let e = callsite()
  239. result = xmlCheckedTag(e, "dt", commonAttr)
  240. macro em*(e: varargs[untyped]): untyped =
  241. ## generates the HTML ``em`` element.
  242. let e = callsite()
  243. result = xmlCheckedTag(e, "em", commonAttr)
  244. macro embed*(e: varargs[untyped]): untyped =
  245. ## generates the HTML ``embed`` element.
  246. let e = callsite()
  247. result = xmlCheckedTag(e, "embed", "src type height width" &
  248. commonAttr, "", true)
  249. macro fieldset*(e: varargs[untyped]): untyped =
  250. ## generates the HTML ``fieldset`` element.
  251. let e = callsite()
  252. result = xmlCheckedTag(e, "fieldset", "disabled form name" & commonAttr)
  253. macro figure*(e: varargs[untyped]): untyped =
  254. ## generates the HTML ``figure`` element.
  255. let e = callsite()
  256. result = xmlCheckedTag(e, "figure", commonAttr)
  257. macro figcaption*(e: varargs[untyped]): untyped =
  258. ## generates the HTML ``figcaption`` element.
  259. let e = callsite()
  260. result = xmlCheckedTag(e, "figcaption", commonAttr)
  261. macro footer*(e: varargs[untyped]): untyped =
  262. ## generates the HTML ``footer`` element.
  263. let e = callsite()
  264. result = xmlCheckedTag(e, "footer", commonAttr)
  265. macro form*(e: varargs[untyped]): untyped =
  266. ## generates the HTML ``form`` element.
  267. let e = callsite()
  268. result = xmlCheckedTag(e, "form", "accept-charset action autocomplete " &
  269. "enctype method name novalidate target" & commonAttr)
  270. macro h1*(e: varargs[untyped]): untyped =
  271. ## generates the HTML ``h1`` element.
  272. let e = callsite()
  273. result = xmlCheckedTag(e, "h1", commonAttr)
  274. macro h2*(e: varargs[untyped]): untyped =
  275. ## generates the HTML ``h2`` element.
  276. let e = callsite()
  277. result = xmlCheckedTag(e, "h2", commonAttr)
  278. macro h3*(e: varargs[untyped]): untyped =
  279. ## generates the HTML ``h3`` element.
  280. let e = callsite()
  281. result = xmlCheckedTag(e, "h3", commonAttr)
  282. macro h4*(e: varargs[untyped]): untyped =
  283. ## generates the HTML ``h4`` element.
  284. let e = callsite()
  285. result = xmlCheckedTag(e, "h4", commonAttr)
  286. macro h5*(e: varargs[untyped]): untyped =
  287. ## generates the HTML ``h5`` element.
  288. let e = callsite()
  289. result = xmlCheckedTag(e, "h5", commonAttr)
  290. macro h6*(e: varargs[untyped]): untyped =
  291. ## generates the HTML ``h6`` element.
  292. let e = callsite()
  293. result = xmlCheckedTag(e, "h6", commonAttr)
  294. macro head*(e: varargs[untyped]): untyped =
  295. ## generates the HTML ``head`` element.
  296. let e = callsite()
  297. result = xmlCheckedTag(e, "head", commonAttr)
  298. macro header*(e: varargs[untyped]): untyped =
  299. ## generates the HTML ``header`` element.
  300. let e = callsite()
  301. result = xmlCheckedTag(e, "header", commonAttr)
  302. macro html*(e: varargs[untyped]): untyped =
  303. ## generates the HTML ``html`` element.
  304. let e = callsite()
  305. result = xmlCheckedTag(e, "html", "xmlns", "")
  306. macro hr*(): untyped =
  307. ## generates the HTML ``hr`` element.
  308. let e = callsite()
  309. result = xmlCheckedTag(e, "hr", commonAttr, "", true)
  310. macro i*(e: varargs[untyped]): untyped =
  311. ## generates the HTML ``i`` element.
  312. let e = callsite()
  313. result = xmlCheckedTag(e, "i", commonAttr)
  314. macro iframe*(e: varargs[untyped]): untyped =
  315. ## generates the HTML ``iframe`` element.
  316. let e = callsite()
  317. result = xmlCheckedTag(e, "iframe", "src srcdoc name sandbox width height" &
  318. commonAttr)
  319. macro img*(e: varargs[untyped]): untyped =
  320. ## generates the HTML ``img`` element.
  321. let e = callsite()
  322. result = xmlCheckedTag(e, "img", "crossorigin usemap ismap height width" &
  323. commonAttr, "src alt", true)
  324. macro input*(e: varargs[untyped]): untyped =
  325. ## generates the HTML ``input`` element.
  326. let e = callsite()
  327. result = xmlCheckedTag(e, "input", "accept alt autocomplete autofocus " &
  328. "checked dirname disabled form formaction formenctype formmethod " &
  329. "formnovalidate formtarget height inputmode list max maxlength min " &
  330. "minlength multiple name pattern placeholder readonly required size " &
  331. "src step type value width" & commonAttr, "", true)
  332. macro ins*(e: varargs[untyped]): untyped =
  333. ## generates the HTML ``ins`` element.
  334. let e = callsite()
  335. result = xmlCheckedTag(e, "ins", "cite datetime" & commonAttr)
  336. macro kbd*(e: varargs[untyped]): untyped =
  337. ## generates the HTML ``kbd`` element.
  338. let e = callsite()
  339. result = xmlCheckedTag(e, "kbd", commonAttr)
  340. macro keygen*(e: varargs[untyped]): untyped =
  341. ## generates the HTML ``keygen`` element.
  342. let e = callsite()
  343. result = xmlCheckedTag(e, "keygen", "autofocus challenge disabled " &
  344. "form keytype name" & commonAttr)
  345. macro label*(e: varargs[untyped]): untyped =
  346. ## generates the HTML ``label`` element.
  347. let e = callsite()
  348. result = xmlCheckedTag(e, "label", "form for" & commonAttr)
  349. macro legend*(e: varargs[untyped]): untyped =
  350. ## generates the HTML ``legend`` element.
  351. let e = callsite()
  352. result = xmlCheckedTag(e, "legend", commonAttr)
  353. macro li*(e: varargs[untyped]): untyped =
  354. ## generates the HTML ``li`` element.
  355. let e = callsite()
  356. result = xmlCheckedTag(e, "li", "value" & commonAttr)
  357. macro link*(e: varargs[untyped]): untyped =
  358. ## generates the HTML ``link`` element.
  359. let e = callsite()
  360. result = xmlCheckedTag(e, "link", "href crossorigin rel media hreflang " &
  361. "type sizes" & commonAttr, "", true)
  362. macro main*(e: varargs[untyped]): untyped =
  363. ## generates the HTML ``main`` element.
  364. let e = callsite()
  365. result = xmlCheckedTag(e, "main", commonAttr)
  366. macro map*(e: varargs[untyped]): untyped =
  367. ## generates the HTML ``map`` element.
  368. let e = callsite()
  369. result = xmlCheckedTag(e, "map", "name" & commonAttr)
  370. macro mark*(e: varargs[untyped]): untyped =
  371. ## generates the HTML ``mark`` element.
  372. let e = callsite()
  373. result = xmlCheckedTag(e, "mark", commonAttr)
  374. macro marquee*(e: varargs[untyped]): untyped =
  375. ## Generates the HTML ``marquee`` element.
  376. let e = callsite()
  377. result = xmlCheckedTag(e, "marquee", coreAttr &
  378. "behavior bgcolor direction height hspace loop scrollamount " &
  379. "scrolldelay truespeed vspace width onbounce onfinish onstart")
  380. macro meta*(e: varargs[untyped]): untyped =
  381. ## generates the HTML ``meta`` element.
  382. let e = callsite()
  383. result = xmlCheckedTag(e, "meta", "name http-equiv content charset" &
  384. commonAttr, "", true)
  385. macro meter*(e: varargs[untyped]): untyped =
  386. ## generates the HTML ``meter`` element.
  387. let e = callsite()
  388. result = xmlCheckedTag(e, "meter", "value min max low high optimum" &
  389. commonAttr)
  390. macro nav*(e: varargs[untyped]): untyped =
  391. ## generates the HTML ``nav`` element.
  392. let e = callsite()
  393. result = xmlCheckedTag(e, "nav", commonAttr)
  394. macro noscript*(e: varargs[untyped]): untyped =
  395. ## generates the HTML ``noscript`` element.
  396. let e = callsite()
  397. result = xmlCheckedTag(e, "noscript", commonAttr)
  398. macro `object`*(e: varargs[untyped]): untyped =
  399. ## generates the HTML ``object`` element.
  400. let e = callsite()
  401. result = xmlCheckedTag(e, "object", "data type typemustmatch name usemap " &
  402. "form width height" & commonAttr)
  403. macro ol*(e: varargs[untyped]): untyped =
  404. ## generates the HTML ``ol`` element.
  405. let e = callsite()
  406. result = xmlCheckedTag(e, "ol", "reversed start type" & commonAttr)
  407. macro optgroup*(e: varargs[untyped]): untyped =
  408. ## generates the HTML ``optgroup`` element.
  409. let e = callsite()
  410. result = xmlCheckedTag(e, "optgroup", "disabled" & commonAttr, "label", false)
  411. macro option*(e: varargs[untyped]): untyped =
  412. ## generates the HTML ``option`` element.
  413. let e = callsite()
  414. result = xmlCheckedTag(e, "option", "disabled label selected value" &
  415. commonAttr)
  416. macro output*(e: varargs[untyped]): untyped =
  417. ## generates the HTML ``output`` element.
  418. let e = callsite()
  419. result = xmlCheckedTag(e, "output", "for form name" & commonAttr)
  420. macro p*(e: varargs[untyped]): untyped =
  421. ## generates the HTML ``p`` element.
  422. let e = callsite()
  423. result = xmlCheckedTag(e, "p", commonAttr)
  424. macro param*(e: varargs[untyped]): untyped =
  425. ## generates the HTML ``param`` element.
  426. let e = callsite()
  427. result = xmlCheckedTag(e, "param", commonAttr, "name value", true)
  428. macro picture*(e: varargs[untyped]): untyped =
  429. ## Generates the HTML ``picture`` element.
  430. let e = callsite()
  431. result = xmlCheckedTag(e, "picture", commonAttr)
  432. macro pre*(e: varargs[untyped]): untyped =
  433. ## generates the HTML ``pre`` element.
  434. let e = callsite()
  435. result = xmlCheckedTag(e, "pre", commonAttr)
  436. macro progress*(e: varargs[untyped]): untyped =
  437. ## generates the HTML ``progress`` element.
  438. let e = callsite()
  439. result = xmlCheckedTag(e, "progress", "value max" & commonAttr)
  440. macro q*(e: varargs[untyped]): untyped =
  441. ## generates the HTML ``q`` element.
  442. let e = callsite()
  443. result = xmlCheckedTag(e, "q", "cite" & commonAttr)
  444. macro rb*(e: varargs[untyped]): untyped =
  445. ## generates the HTML ``rb`` element.
  446. let e = callsite()
  447. result = xmlCheckedTag(e, "rb", commonAttr)
  448. macro rp*(e: varargs[untyped]): untyped =
  449. ## generates the HTML ``rp`` element.
  450. let e = callsite()
  451. result = xmlCheckedTag(e, "rp", commonAttr)
  452. macro rt*(e: varargs[untyped]): untyped =
  453. ## generates the HTML ``rt`` element.
  454. let e = callsite()
  455. result = xmlCheckedTag(e, "rt", commonAttr)
  456. macro rtc*(e: varargs[untyped]): untyped =
  457. ## generates the HTML ``rtc`` element.
  458. let e = callsite()
  459. result = xmlCheckedTag(e, "rtc", commonAttr)
  460. macro ruby*(e: varargs[untyped]): untyped =
  461. ## generates the HTML ``ruby`` element.
  462. let e = callsite()
  463. result = xmlCheckedTag(e, "ruby", commonAttr)
  464. macro s*(e: varargs[untyped]): untyped =
  465. ## generates the HTML ``s`` element.
  466. let e = callsite()
  467. result = xmlCheckedTag(e, "s", commonAttr)
  468. macro samp*(e: varargs[untyped]): untyped =
  469. ## generates the HTML ``samp`` element.
  470. let e = callsite()
  471. result = xmlCheckedTag(e, "samp", commonAttr)
  472. macro script*(e: varargs[untyped]): untyped =
  473. ## generates the HTML ``script`` element.
  474. let e = callsite()
  475. result = xmlCheckedTag(e, "script", "src type charset async defer " &
  476. "crossorigin" & commonAttr)
  477. macro section*(e: varargs[untyped]): untyped =
  478. ## generates the HTML ``section`` element.
  479. let e = callsite()
  480. result = xmlCheckedTag(e, "section", commonAttr)
  481. macro select*(e: varargs[untyped]): untyped =
  482. ## generates the HTML ``select`` element.
  483. let e = callsite()
  484. result = xmlCheckedTag(e, "select", "autofocus disabled form multiple " &
  485. "name required size" & commonAttr)
  486. macro slot*(e: varargs[untyped]): untyped =
  487. ## Generates the HTML ``slot`` element.
  488. let e = callsite()
  489. result = xmlCheckedTag(e, "slot", commonAttr)
  490. macro small*(e: varargs[untyped]): untyped =
  491. ## generates the HTML ``small`` element.
  492. let e = callsite()
  493. result = xmlCheckedTag(e, "small", commonAttr)
  494. macro source*(e: varargs[untyped]): untyped =
  495. ## generates the HTML ``source`` element.
  496. let e = callsite()
  497. result = xmlCheckedTag(e, "source", "type" & commonAttr, "src", true)
  498. macro span*(e: varargs[untyped]): untyped =
  499. ## generates the HTML ``span`` element.
  500. let e = callsite()
  501. result = xmlCheckedTag(e, "span", commonAttr)
  502. macro strong*(e: varargs[untyped]): untyped =
  503. ## generates the HTML ``strong`` element.
  504. let e = callsite()
  505. result = xmlCheckedTag(e, "strong", commonAttr)
  506. macro style*(e: varargs[untyped]): untyped =
  507. ## generates the HTML ``style`` element.
  508. let e = callsite()
  509. result = xmlCheckedTag(e, "style", "media type" & commonAttr)
  510. macro sub*(e: varargs[untyped]): untyped =
  511. ## generates the HTML ``sub`` element.
  512. let e = callsite()
  513. result = xmlCheckedTag(e, "sub", commonAttr)
  514. macro summary*(e: varargs[untyped]): untyped =
  515. ## Generates the HTML ``summary`` element.
  516. let e = callsite()
  517. result = xmlCheckedTag(e, "summary", commonAttr)
  518. macro sup*(e: varargs[untyped]): untyped =
  519. ## generates the HTML ``sup`` element.
  520. let e = callsite()
  521. result = xmlCheckedTag(e, "sup", commonAttr)
  522. macro table*(e: varargs[untyped]): untyped =
  523. ## generates the HTML ``table`` element.
  524. let e = callsite()
  525. result = xmlCheckedTag(e, "table", "border sortable" & commonAttr)
  526. macro tbody*(e: varargs[untyped]): untyped =
  527. ## generates the HTML ``tbody`` element.
  528. let e = callsite()
  529. result = xmlCheckedTag(e, "tbody", commonAttr)
  530. macro td*(e: varargs[untyped]): untyped =
  531. ## generates the HTML ``td`` element.
  532. let e = callsite()
  533. result = xmlCheckedTag(e, "td", "colspan rowspan headers" & commonAttr)
  534. macro `template`*(e: varargs[untyped]): untyped =
  535. ## generates the HTML ``template`` element.
  536. let e = callsite()
  537. result = xmlCheckedTag(e, "template", commonAttr)
  538. macro textarea*(e: varargs[untyped]): untyped =
  539. ## generates the HTML ``textarea`` element.
  540. let e = callsite()
  541. result = xmlCheckedTag(e, "textarea", "autocomplete autofocus cols " &
  542. "dirname disabled form inputmode maxlength minlength name placeholder " &
  543. "readonly required rows wrap" & commonAttr)
  544. macro tfoot*(e: varargs[untyped]): untyped =
  545. ## generates the HTML ``tfoot`` element.
  546. let e = callsite()
  547. result = xmlCheckedTag(e, "tfoot", commonAttr)
  548. macro th*(e: varargs[untyped]): untyped =
  549. ## generates the HTML ``th`` element.
  550. let e = callsite()
  551. result = xmlCheckedTag(e, "th", "colspan rowspan headers abbr scope axis" &
  552. " sorted" & commonAttr)
  553. macro thead*(e: varargs[untyped]): untyped =
  554. ## generates the HTML ``thead`` element.
  555. let e = callsite()
  556. result = xmlCheckedTag(e, "thead", commonAttr)
  557. macro time*(e: varargs[untyped]): untyped =
  558. ## generates the HTML ``time`` element.
  559. let e = callsite()
  560. result = xmlCheckedTag(e, "time", "datetime" & commonAttr)
  561. macro title*(e: varargs[untyped]): untyped =
  562. ## generates the HTML ``title`` element.
  563. let e = callsite()
  564. result = xmlCheckedTag(e, "title", commonAttr)
  565. macro tr*(e: varargs[untyped]): untyped =
  566. ## generates the HTML ``tr`` element.
  567. let e = callsite()
  568. result = xmlCheckedTag(e, "tr", commonAttr)
  569. macro track*(e: varargs[untyped]): untyped =
  570. ## generates the HTML ``track`` element.
  571. let e = callsite()
  572. result = xmlCheckedTag(e, "track", "kind srclang label default" &
  573. commonAttr, "src", true)
  574. macro tt*(e: varargs[untyped]): untyped =
  575. ## generates the HTML ``tt`` element.
  576. let e = callsite()
  577. result = xmlCheckedTag(e, "tt", commonAttr)
  578. macro u*(e: varargs[untyped]): untyped =
  579. ## generates the HTML ``u`` element.
  580. let e = callsite()
  581. result = xmlCheckedTag(e, "u", commonAttr)
  582. macro ul*(e: varargs[untyped]): untyped =
  583. ## generates the HTML ``ul`` element.
  584. let e = callsite()
  585. result = xmlCheckedTag(e, "ul", commonAttr)
  586. macro `var`*(e: varargs[untyped]): untyped =
  587. ## generates the HTML ``var`` element.
  588. let e = callsite()
  589. result = xmlCheckedTag(e, "var", commonAttr)
  590. macro video*(e: varargs[untyped]): untyped =
  591. ## generates the HTML ``video`` element.
  592. let e = callsite()
  593. result = xmlCheckedTag(e, "video", "src crossorigin poster preload " &
  594. "autoplay mediagroup loop muted controls width height" & commonAttr)
  595. macro wbr*(e: varargs[untyped]): untyped =
  596. ## generates the HTML ``wbr`` element.
  597. let e = callsite()
  598. result = xmlCheckedTag(e, "wbr", commonAttr, "", true)
  599. runnableExamples:
  600. let nim = "Nim"
  601. assert h1(a(href="http://nim-lang.org", nim)) ==
  602. """<h1><a href="http://nim-lang.org">Nim</a></h1>"""
  603. assert form(action="test", `accept-charset` = "Content-Type") ==
  604. """<form action="test" accept-charset="Content-Type"></form>"""