factor/library/help/markup.factor

77 lines
1.8 KiB
Factor
Raw Normal View History

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
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 $.
PREDICATE: array simple-element
dup empty? [ drop t ] [ first word? not ] if ;
2005-12-19 23:18:15 -05:00
M: string print-element
" " split [ format* bl ] each ;
M: array print-element
dup first >r 1 swap tail r> execute ;
2005-12-01 00:53:12 -05:00
: ($span) ( content style -- )
[ print-element ] with-style ;
2005-12-01 00:53:12 -05:00
: ($block) ( content style -- )
2005-12-19 23:18:15 -05:00
terpri*
[ [ print-element ] with-nesting* ] with-style
terpri* ;
2005-12-01 00:53:12 -05:00
2005-12-19 23:18:15 -05:00
: $see ( content -- )
code-style [ [ first see ] with-nesting* ] with-style ;
2005-12-01 00:53:12 -05:00
! Some spans
: $heading heading-style ($block) ;
: $subheading subheading-style ($block) ;
2005-12-01 00:53:12 -05:00
: $parameter parameter-style ($span) ;
2005-12-01 00:53:12 -05:00
2005-12-19 23:18:15 -05:00
: $emphasis emphasis-style ($span) ;
: $terpri terpri drop ;
2005-12-01 00:53:12 -05:00
! Some blocks
2005-12-19 23:18:15 -05:00
M: simple-element print-element
current-style [ [ print-element ] each ] with-nesting ;
: $code
terpri*
first code-style [ [ format* ] with-nesting* ] with-style
terpri* ;
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
: ($link) dup article-title swap ;
2005-12-01 00:53:12 -05:00
: $subsection ( object -- )
subheading-style [
first <link> ($link) dup [ link-name help ] curry
simple-outliner
] with-style ;
2005-12-01 00:53:12 -05:00
: $link ( article -- ) first <link> ($link) simple-object ;
2005-12-01 00:53:12 -05:00
: $glossary ( element -- ) first <term> ($link) simple-object ;