]> gitweb.factorcode.org Git - factor.git/commitdiff
html.parser.printer: add helper words with string output.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 20 Apr 2015 16:31:40 +0000 (09:31 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 20 Apr 2015 16:31:40 +0000 (09:31 -0700)
extra/html/parser/printer/printer.factor
extra/wikipedia/wikipedia.factor
extra/xkcd/xkcd.factor

index 552d807e3ffc10d43fa248d862a4c04c89927dad..4401e1f22946b0c8236b07b766c31e09d37135b1 100644 (file)
@@ -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 ] }
index 67db2d124edea7f3f536fe003b355d9aa75bef32..9d609659f2bac3be634e91ff4f184544e8d43c4f 100644 (file)
@@ -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 ;
index e6c356daaef80ab153733a8dd472d29f8db90af2..c9cfcbad523255086c69e5586533938a3ba56cb6 100644 (file)
@@ -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 ;