html.streams now emits clickable URLs for $url markup elements
parent
ded36a2279
commit
e62f068db7
|
@ -71,7 +71,10 @@ ALIAS: $slot $snippet
|
|||
[ strong-style get print-element* ] ($span) ;
|
||||
|
||||
: $url ( children -- )
|
||||
[ url-style get print-element* ] ($span) ;
|
||||
[
|
||||
dup first href associate url-style get assoc-union
|
||||
print-element*
|
||||
] ($span) ;
|
||||
|
||||
: $nl ( children -- )
|
||||
nl nl drop ;
|
||||
|
|
|
@ -13,13 +13,13 @@ HELP: <html-stream>
|
|||
{ $values { "stream" "an output stream" } { "html-stream" html-stream } }
|
||||
{ $description "Creates a new formatted output stream which emits HTML markup on " { $snippet "stream" } "." } ;
|
||||
|
||||
HELP: with-html-stream
|
||||
HELP: with-html-writer
|
||||
{ $values { "quot" quotation } }
|
||||
{ $description "Calls the quotation in a new dynamic scope with " { $link output-stream } " rebound to an " { $link html-stream } " wrapping the current " { $link output-stream } "." }
|
||||
{ $examples
|
||||
{ $example
|
||||
"USING: io io.styles html.streams ;"
|
||||
"[ \"Hello\" { { font-style bold } } format nl ] with-html-stream"
|
||||
"[ \"Hello\" { { font-style bold } } format nl ] with-html-writer"
|
||||
"<span style='font-style: normal; font-weight: bold; '>Hello</span><br/>"
|
||||
}
|
||||
} ;
|
||||
|
@ -28,6 +28,6 @@ ARTICLE: "html.streams" "HTML streams"
|
|||
"The " { $vocab-link "html.streams" } " vocabulary provides a stream which implements " { $link "styles" } " by writing HTML markup to the wrapped stream."
|
||||
{ $subsection html-stream }
|
||||
{ $subsection <html-stream> }
|
||||
{ $subsection with-html-stream } ;
|
||||
{ $subsection with-html-writer } ;
|
||||
|
||||
ABOUT: "html.streams"
|
||||
|
|
|
@ -4,7 +4,7 @@ xml.writer sbufs sequences inspector colors ;
|
|||
IN: html.streams.tests
|
||||
|
||||
: make-html-string
|
||||
[ with-html-stream ] with-string-writer ; inline
|
||||
[ with-html-writer ] with-string-writer ; inline
|
||||
|
||||
[ [ ] make-html-string ] must-infer
|
||||
|
||||
|
@ -71,4 +71,4 @@ M: funky browser-link-href
|
|||
[ H{ } [ ] with-nesting nl ] make-html-string
|
||||
] unit-test
|
||||
|
||||
[ ] [ [ { 1 2 3 } describe ] with-html-stream ] unit-test
|
||||
[ ] [ [ { 1 2 3 } describe ] with-html-writer ] unit-test
|
||||
|
|
|
@ -22,7 +22,7 @@ TUPLE: html-stream stream last-div ;
|
|||
: not-a-div ( stream -- stream )
|
||||
f >>last-div ; inline
|
||||
|
||||
: a-div ( stream -- straem )
|
||||
: a-div ( stream -- stream )
|
||||
t >>last-div ; inline
|
||||
|
||||
: <html-stream> ( stream -- html-stream )
|
||||
|
@ -48,6 +48,9 @@ TUPLE: html-sub-stream < html-stream style parent ;
|
|||
] [ call ] if*
|
||||
] [ call ] if* ; inline
|
||||
|
||||
: href-link-tag ( style quot -- )
|
||||
href pick at [ <a =href a> call </a> ] [ call ] if* ; inline
|
||||
|
||||
: hex-color, ( color -- )
|
||||
[ red>> ] [ green>> ] [ blue>> ] tri
|
||||
[ 255 * >fixnum >hex 2 CHAR: 0 pad-left % ] tri@ ;
|
||||
|
@ -95,7 +98,7 @@ TUPLE: html-sub-stream < html-stream style parent ;
|
|||
|
||||
: format-html-span ( string style stream -- )
|
||||
stream>> [
|
||||
[ [ drop write ] span-tag ] object-link-tag
|
||||
[ [ [ drop write ] span-tag ] href-link-tag ] object-link-tag
|
||||
] with-output-stream* ;
|
||||
|
||||
TUPLE: html-span-stream < html-sub-stream ;
|
||||
|
@ -192,5 +195,5 @@ M: html-stream stream-write-table
|
|||
|
||||
M: html-stream dispose stream>> dispose ;
|
||||
|
||||
: with-html-stream ( quot -- )
|
||||
: with-html-writer ( quot -- )
|
||||
output-stream get <html-stream> swap with-output-stream* ; inline
|
||||
|
|
|
@ -20,6 +20,8 @@ SYMBOL: presented
|
|||
SYMBOL: presented-path
|
||||
SYMBOL: presented-printer
|
||||
|
||||
SYMBOL: href
|
||||
|
||||
! Paragraph styles
|
||||
SYMBOL: page-color
|
||||
SYMBOL: border-color
|
||||
|
|
Loading…
Reference in New Issue