tomo/test/lang.tm

56 lines
998 B
Plaintext
Raw Normal View History

2024-04-28 11:58:55 -07:00
lang HTML:
HEADER := $HTML"<!DOCTYPE HTML>"
convert(t:Text->HTML):
t = t:replace_all({
$/&/="&amp;",
$/</="&lt;",
$/>/="&gt;",
$/"/="&quot",
$/'/="&#39;",
})
return HTML.without_escaping(t)
2024-03-09 16:03:35 -08:00
convert(i:Int->HTML):
return HTML.without_escaping("$i")
2024-03-09 16:03:35 -08:00
func paragraph(content:HTML->HTML):
return $HTML"<p>$content</p>"
2024-03-09 16:03:35 -08:00
struct Bold(text:Text):
convert(b:Bold -> HTML):
return $HTML"<b>$(b.text)</b>"
2024-04-28 11:58:55 -07:00
func main():
2024-04-12 10:09:31 -07:00
>> HTML.HEADER
= $HTML"<!DOCTYPE HTML>"
2024-03-09 16:03:35 -08:00
2024-12-26 14:32:10 -08:00
>> HTML.HEADER[1]
= $HTML"<"
>> HTML.HEADER.text
= "<!DOCTYPE HTML>"
2024-04-12 10:09:31 -07:00
>> user := "I <3 hax"
>> html := $HTML"Hello $user!"
2024-04-12 10:09:31 -07:00
= $HTML"Hello I &lt;3 hax!"
>> html ++ $HTML"<br>"
2024-04-12 10:09:31 -07:00
= $HTML"Hello I &lt;3 hax!<br>"
2024-03-09 16:03:35 -08:00
>> $HTML"$(1 + 2)"
2024-04-12 10:09:31 -07:00
= $HTML"3"
2024-03-09 16:03:35 -08:00
>> $HTML"$(Int8(3))"
2024-04-12 10:09:31 -07:00
= $HTML"3"
2024-03-09 16:03:35 -08:00
2024-04-12 10:09:31 -07:00
>> html:paragraph()
= $HTML"<p>Hello I &lt;3 hax!</p>"
2024-08-18 09:52:53 -07:00
>> Text(html)
= '$HTML"Hello I &lt;3 hax!"'
>> b := Bold("Some <text> with junk")
>> $HTML"Your text: $b"
= $HTML"Your text: <b>Some &lt;text&gt; with junk</b>"