retroforth/example/HTML.retro
crc 6a4aaf8eac prefix: namespace is now sigil:, rename words, update examples, update docs
FossilOrigin-Name: 25cf19660ab7728d7bfee2722ea826a8a438faf92b2504b28d922d2958906aed
2021-03-30 11:58:25 +00:00

24 lines
747 B
Forth

# HTML Generation
This is a little experiment in combinator-driven HTML generation.
~~~
:a:href (ss-) '<a_href=' s:put s:put ''> s:put s:put '</a> s:put ;
:p (q-) '<p> s:put call '</p> s:put nl ;
:strong (q-) '<strong> s:put call '</strong> s:put nl ;
:em (q-) '<em> s:put call '</em> s:put nl ;
:h1 (s-) '<h1> s:put s:put '</h1> s:put nl ;
:div (q-) '<div> s:put call '</div> s:put nl ;
:body (q-) '<body> s:put call '</body> s:put nl ;
:sigil:" s:keep &s:put compile:call ; immediate
~~~
Test case:
```
[ 'Hello h1
[ 'This_is_a_test_of_HTML_generation._Please_
'follow_the_link 'page2.html a:href '. ] p
[ 'This_is_a_second_paragraph ] p
] body
```