html.parser.printer: add helper words with string output.
parent
94cc259ba2
commit
5cc7bfb067
|
@ -1,6 +1,6 @@
|
|||
USING: accessors assocs combinators html.parser
|
||||
html.parser.utils io kernel math math.order namespaces sequences
|
||||
strings unicode.categories ;
|
||||
html.parser.utils io io.streams.string kernel math math.order
|
||||
namespaces sequences strings unicode.categories ;
|
||||
IN: html.parser.printer
|
||||
|
||||
TUPLE: html-printer ;
|
||||
|
@ -35,9 +35,15 @@ ERROR: unknown-tag-error tag ;
|
|||
: html-text. ( vector -- )
|
||||
T{ text-printer } html-printer [ print-tags ] with-variable ;
|
||||
|
||||
: html-text ( vector -- string )
|
||||
[ html-text. ] with-string-writer ;
|
||||
|
||||
: html-src. ( vector -- )
|
||||
T{ src-printer } html-printer [ print-tags ] with-variable ;
|
||||
|
||||
: html-src ( vector -- string )
|
||||
[ html-src. ] with-string-writer ;
|
||||
|
||||
M: text-printer print-opening-tag
|
||||
name>> {
|
||||
{ "br" [ nl ] }
|
||||
|
|
|
@ -76,7 +76,7 @@ PRIVATE>
|
|||
: article. ( name -- )
|
||||
wikipedia-url http-get nip parse-html
|
||||
"content" find-by-id-between
|
||||
[ html-text. ] with-string-writer string-lines
|
||||
html-text string-lines
|
||||
[ [ blank? ] trim ] map harvest [
|
||||
html-unescape 72 wrap-string print nl
|
||||
] each ;
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
|
||||
USING: accessors formatting html.entities html.parser
|
||||
html.parser.analyzer html.parser.printer http.client images.http
|
||||
images.viewer images.viewer.prettyprint io io.streams.string
|
||||
kernel parser prettyprint.custom prettyprint.sections regexp
|
||||
sequences strings ui wrap.strings ;
|
||||
images.viewer images.viewer.prettyprint io kernel parser
|
||||
prettyprint.custom prettyprint.sections regexp sequences strings
|
||||
ui wrap.strings ;
|
||||
|
||||
IN: xkcd
|
||||
|
||||
|
@ -22,8 +22,7 @@ IN: xkcd
|
|||
: comic-text ( url -- string )
|
||||
http-get nip parse-html
|
||||
"transcript" find-by-id-between
|
||||
[ html-text. ] with-string-writer
|
||||
html-unescape ;
|
||||
html-text html-unescape ;
|
||||
|
||||
: comic-text. ( url -- )
|
||||
comic-text 80 wrap-string print ;
|
||||
|
|
Loading…
Reference in New Issue