2005-12-01 00:53:12 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: help
|
2005-12-19 02:12:40 -05:00
|
|
|
USING: arrays gadgets gadgets-panes gadgets-presentations
|
|
|
|
hashtables words io kernel lists namespaces prettyprint
|
|
|
|
sequences strings styles ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
|
|
|
! Simple markup language.
|
|
|
|
|
|
|
|
! <element> ::== <string> | <simple-element> | <fancy-element>
|
|
|
|
! <simple-element> ::== { <element>* }
|
|
|
|
! <fancy-element> ::== { <type> <element> }
|
|
|
|
|
|
|
|
! Element types are words whose name begins with $.
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
PREDICATE: array simple-element
|
|
|
|
dup empty? [ drop t ] [ first word? not ] if ;
|
|
|
|
|
|
|
|
M: string print-element format* ;
|
|
|
|
|
|
|
|
M: array print-element
|
|
|
|
dup first >r 1 swap tail r> execute ;
|
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
: ($span) ( content style -- )
|
2005-12-19 02:12:40 -05:00
|
|
|
[ print-element ] with-style ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: ($block) ( content style -- )
|
|
|
|
terpri dup [
|
|
|
|
[ print-element terpri ] with-style
|
|
|
|
] with-nesting terpri ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
|
|
|
: $see ( content -- ) first see ;
|
|
|
|
|
|
|
|
! Some spans
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: $heading heading-style ($block) ;
|
|
|
|
|
|
|
|
: $subheading subheading-style ($block) ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: $parameter parameter-style ($span) ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
|
|
|
! Some blocks
|
2005-12-19 02:12:40 -05:00
|
|
|
: wrap-string ( string -- )
|
|
|
|
" " split [
|
|
|
|
dup empty? [ dup format* bl ] unless drop
|
|
|
|
] each ;
|
|
|
|
|
|
|
|
: ($paragraph) ( element style -- )
|
|
|
|
dup [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
dup string?
|
|
|
|
[ wrap-string ] [ print-element bl ] if
|
|
|
|
] each
|
|
|
|
] with-style
|
|
|
|
] with-nesting terpri ;
|
|
|
|
|
|
|
|
M: simple-element print-element paragraph-style ($paragraph) ;
|
|
|
|
|
|
|
|
: $code code-style ($block) ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
|
|
|
! Some links
|
2005-12-02 01:02:08 -05:00
|
|
|
TUPLE: link name ;
|
|
|
|
|
|
|
|
M: link article-title link-name article-title ;
|
|
|
|
|
|
|
|
M: link article-content link-name article-content ;
|
|
|
|
|
|
|
|
DEFER: help
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: ($link) dup article-title swap ;
|
|
|
|
|
2005-12-01 00:53:12 -05:00
|
|
|
: $subsection ( object -- )
|
2005-12-19 02:12:40 -05:00
|
|
|
subheading-style [
|
|
|
|
first <link> ($link) dup [ link-name help ] curry
|
|
|
|
simple-outliner
|
|
|
|
] with-style ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: $link ( article -- ) first <link> ($link) simple-object ;
|
2005-12-01 00:53:12 -05:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: $glossary ( element -- ) first <term> ($link) simple-object ;
|