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 ;
: 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 ] }
: 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 ;
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
: 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 ;