tomo/test/lang.tm

56 lines
971 B
Plaintext
Raw Permalink Normal View History

2025-04-06 13:07:23 -07:00
lang HTML
HEADER := $HTML"<!DOCTYPE HTML>"
2025-04-06 13:07:23 -07:00
convert(t:Text->HTML)
t = t.translate({
2025-04-01 11:05:10 -07:00
"&"="&amp;",
"<"="&lt;",
">"="&gt;",
'"'="&quot",
"'"="&#39;",
})
return HTML.from_text(t)
2024-03-09 16:03:35 -08:00
2025-04-06 13:07:23 -07:00
convert(i:Int->HTML)
return HTML.from_text("$i")
2024-03-09 16:03:35 -08:00
2025-04-06 13:07:23 -07:00
func paragraph(content:HTML->HTML)
return $HTML"<p>$content</p>"
2024-03-09 16:03:35 -08:00
2025-04-06 13:07:23 -07:00
struct Bold(text:Text)
convert(b:Bold -> HTML)
return $HTML"<b>$(b.text)</b>"
2025-04-06 13:07:23 -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
>> html.paragraph()
2024-04-12 10:09:31 -07:00
= $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>"