help.markup: new logic for preventing accidental double blank lines
$subsections emits a blank line after the final link so that subsequent span text is nicely spaced away from the group of links. Prior to this bug fix, if you were to put a $heading immediately after a $subsections element, there would be 2 blank lines between them. This fixes it so that there is only a single blank line between them. I also added a bunch of unit tests for span, block, $heading and $nl layout interactions.db4
parent
69829a534d
commit
1a44b22f14
|
@ -26,3 +26,46 @@ TUPLE: blahblah quux ;
|
||||||
[ "a string, a fixnum, or an integer" ]
|
[ "a string, a fixnum, or an integer" ]
|
||||||
[ [ { $or string fixnum integer } print-element ] with-string-writer ] unit-test
|
[ [ { $or string fixnum integer } print-element ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
! Layout
|
||||||
|
|
||||||
|
[ "span" ]
|
||||||
|
[ [ { "span" } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "span1span2" ]
|
||||||
|
[ [ { "span1" "span2" } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "span1\n\nspan2" ]
|
||||||
|
[ [ { "span1" { $nl } "span2" } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "\nspan" ]
|
||||||
|
[ [ { { $nl } "span" } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "2 2 +\nspan" ]
|
||||||
|
[ [ { { $code "2 2 +" } "span" } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "2 2 +" ]
|
||||||
|
[ [ { { $code "2 2 +" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "span\n2 2 +" ]
|
||||||
|
[ [ { "span" { $code "2 2 +" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "\n2 2 +" ]
|
||||||
|
[ [ { { $nl } { $code "2 2 +" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "span\n\n2 2 +" ]
|
||||||
|
[ [ { "span" { $nl } { $code "2 2 +" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "Heading" ]
|
||||||
|
[ [ { { $heading "Heading" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "Heading1\n\nHeading2" ]
|
||||||
|
[ [ { { $heading "Heading1" } { $heading "Heading2" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "span\n\nHeading" ]
|
||||||
|
[ [ { "span" { $heading "Heading" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "\nHeading" ]
|
||||||
|
[ [ { { $nl } { $heading "Heading" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
||||||
|
[ "span\n\nHeading" ]
|
||||||
|
[ [ { "span" { $nl } { $heading "Heading" } } print-content ] with-string-writer ] unit-test
|
||||||
|
|
|
@ -15,9 +15,16 @@ PREDICATE: simple-element < array
|
||||||
SYMBOL: last-element
|
SYMBOL: last-element
|
||||||
SYMBOL: span
|
SYMBOL: span
|
||||||
SYMBOL: block
|
SYMBOL: block
|
||||||
|
SYMBOL: blank-line
|
||||||
|
|
||||||
: last-span? ( -- ? ) last-element get span eq? ;
|
: last-span? ( -- ? ) last-element get span eq? ;
|
||||||
: last-block? ( -- ? ) last-element get block eq? ;
|
: last-block? ( -- ? ) last-element get block eq? ;
|
||||||
|
: last-blank-line? ( -- ? ) last-element get blank-line eq? ;
|
||||||
|
|
||||||
|
: ?nl ( -- )
|
||||||
|
last-element get
|
||||||
|
last-blank-line? not
|
||||||
|
and [ nl ] when ;
|
||||||
|
|
||||||
: ($span) ( quot -- )
|
: ($span) ( quot -- )
|
||||||
last-block? [ nl ] when
|
last-block? [ nl ] when
|
||||||
|
@ -45,7 +52,7 @@ M: f print-element drop ;
|
||||||
[ print-element ] with-default-style ;
|
[ print-element ] with-default-style ;
|
||||||
|
|
||||||
: ($block) ( quot -- )
|
: ($block) ( quot -- )
|
||||||
last-element get [ nl ] when
|
?nl
|
||||||
span last-element set
|
span last-element set
|
||||||
call
|
call
|
||||||
block last-element set ; inline
|
block last-element set ; inline
|
||||||
|
@ -71,11 +78,12 @@ ALIAS: $slot $snippet
|
||||||
] ($span) ;
|
] ($span) ;
|
||||||
|
|
||||||
: $nl ( children -- )
|
: $nl ( children -- )
|
||||||
nl last-block? [ nl ] unless drop ;
|
drop nl last-element get [ nl ] when
|
||||||
|
blank-line last-element set ;
|
||||||
|
|
||||||
! Some blocks
|
! Some blocks
|
||||||
: ($heading) ( children quot -- )
|
: ($heading) ( children quot -- )
|
||||||
last-element get [ nl ] when ($block) ; inline
|
?nl ($block) ; inline
|
||||||
|
|
||||||
: $heading ( element -- )
|
: $heading ( element -- )
|
||||||
[ heading-style get print-element* ] ($heading) ;
|
[ heading-style get print-element* ] ($heading) ;
|
||||||
|
@ -212,7 +220,7 @@ PRIVATE>
|
||||||
] ($subsection) ;
|
] ($subsection) ;
|
||||||
|
|
||||||
: $subsections ( children -- )
|
: $subsections ( children -- )
|
||||||
[ $subsection* ] each nl ;
|
[ $subsection* ] each nl nl blank-line last-element set ;
|
||||||
|
|
||||||
: $subsection ( element -- )
|
: $subsection ( element -- )
|
||||||
first $subsection* ;
|
first $subsection* ;
|
||||||
|
|
Loading…
Reference in New Issue