code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(46 lines)
1 lang HTML
2 HEADER := $HTML"<!DOCTYPE HTML>"
3 convert(t:Text->HTML)
4 t = t.translate({
5 "&": "&amp;",
6 "<": "&lt;",
7 ">": "&gt;",
8 '"': "&quot",
9 "'": "&#39;",
10 })
12 return HTML.from_text(t)
14 convert(i:Int->HTML)
15 return HTML.from_text("$i")
17 func paragraph(content:HTML->HTML)
18 return $HTML"<p>$content</p>"
20 struct Bold(text:Text)
21 convert(b:Bold -> HTML)
22 return $HTML"<b>$(b.text)</b>"
24 func main()
25 assert HTML.HEADER == $HTML"<!DOCTYPE HTML>"
27 assert HTML.HEADER[1] == $HTML"<"
29 assert HTML.HEADER.text == "<!DOCTYPE HTML>"
31 >> user := "I <3 hax"
32 html := $HTML"Hello $user!"
33 assert html == $HTML"Hello I &lt;3 hax!"
34 assert html ++ $HTML"<br>" == $HTML"Hello I &lt;3 hax!<br>"
36 assert $HTML"$(1 + 2)" == $HTML"3"
38 assert $HTML"$(Int8(3))" == $HTML"3"
40 assert html.paragraph() == $HTML"<p>Hello I &lt;3 hax!</p>"
42 assert Text(html) == '\$HTML"Hello I &lt;3 hax!"'
44 >> b := Bold("Some <text> with junk")
45 assert $HTML"Your text: $b" == $HTML"Your text: <b>Some &lt;text&gt; with junk</b>"