s:put
~~~
### Support Code
The first couple of words are a variation of `s:put` that
generates HTML codes for specific characters. This ensures
that code output displays correctly.
~~~
:c:put
$< [ '< s:put ] case
$> [ '> s:put ] case
$& [ '& s:put ] case
ASCII:SPACE [ ' s:put ] case
c:put ;
:s:put
[ c:put
] s:for-each ;
~~~
For regular text, there are a couple of inline formatting things
to deal with.
These are:
* emphasis
* strong (bold)
* escaped characters
* code
~~~
'Emphasis var
'Strong var
'Escape var
'Code var
~~~
~~~
:format
$` [ @Escape [ &Escape v:off $* c:put ] if;
@Code n:zero? [ '
;
:s:put
;
:end '
;
:end ' '_ s:put ;
---reveal---
:format-code (s-)
(ignore_empty_tokens)
dup s:length n:zero? [ ' s:put drop ] if;
(tokens_with_sigils)
dup fetch
$: [ 'colon span ] case
$( [ 'note span ] case
$' [ 'str span ] case
$# [ 'num span ] case
$. [ 'fnum span ] case
$& [ 'ptr span ] case
$$ [ 'char span ] case
$` [ 'inst span ] case
$\ [ 'inst span ] case
$| [ 'defer span ] case
$@ [ 'fetch span ] case
$! [ 'store span ] case
(immediate_and_primitives)
drop dup
d:lookup d:class fetch
&class:macro [ 'imm span ] case
&class:primitive [ 'prim span ] case
drop
(normal_words)
s:put
sp ;
:colorize
ASCII:SPACE s:tokenize &format-code a:for-each ;
:format:code
'
s:put nl ;
}}
~~~
*Headers*
After this, I define detection and formatting of headers. The
headers should look like:
# Level 1
## Level 2
### Level 3
~~~
:header?
dup [ '#_ s:begins-with? ]
[ '##_ s:begins-with? ]
[ '###_ s:begins-with? ] tri or or
over '####_ s:begins-with? or ;
:format:head
ASCII:SPACE s:split/char
'# [ '
' s:put nl ;
~~~
*Horizontal Rules*
Horizonal rules consist of four or more - characters on
a line. E.g.,
----
--------
This also accepts sequences of `-+-+` which were used in
some older RETRO source files.
~~~
:rule?
dup [ '---- s:begins-with? ] [ '-+-+ s:begins-with? ] bi or ;
:format:rule drop '
s:put nl ;
:indented-list?
dup [ '__-_ s:begins-with? ] [ '__*_ s:begins-with? ] bi or ;
:format:indented-list
'
s:put nl ;
~~~
*Paragraphs*
Blank lines denote paragraph breaks.
~~~
:blank? dup s:length n:zero? ;
'InParagraph var
~~~
*The Formatter*
This ties together the various words above, generating the
output.
~~~
:format
s:keep
code-block? [ toggle-code ] if;
in-code-block? [ format:code ] if;
test-block? [ toggle-test ] if;
in-test-block? [ format:code ] if;
blank? [ drop '
s:put nl ] if;
header? [ format:head ] if;
inline-code? [ format:inline-code ] if;
list? [ format:list ] if;
indented-list? [ format:indented-list ] if;
rule? [ format:rule ] if;
s:put