From 5cc7bfb067fd24e9fafdae8474c3dee7cc5c785c Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 20 Apr 2015 09:31:40 -0700 Subject: [PATCH] html.parser.printer: add helper words with string output. --- extra/html/parser/printer/printer.factor | 10 ++++++++-- extra/wikipedia/wikipedia.factor | 2 +- extra/xkcd/xkcd.factor | 9 ++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/extra/html/parser/printer/printer.factor b/extra/html/parser/printer/printer.factor index 552d807e3f..4401e1f229 100644 --- a/extra/html/parser/printer/printer.factor +++ b/extra/html/parser/printer/printer.factor @@ -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 ] } diff --git a/extra/wikipedia/wikipedia.factor b/extra/wikipedia/wikipedia.factor index 67db2d124e..9d609659f2 100644 --- a/extra/wikipedia/wikipedia.factor +++ b/extra/wikipedia/wikipedia.factor @@ -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 ; diff --git a/extra/xkcd/xkcd.factor b/extra/xkcd/xkcd.factor index e6c356daae..c9cfcbad52 100644 --- a/extra/xkcd/xkcd.factor +++ b/extra/xkcd/xkcd.factor @@ -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 ; -- 2.34.1