html.parser.printer: fixed to use repeated write calls instead of surround

db4
Björn Lindqvist 2013-08-05 13:57:55 +02:00 committed by John Benediktsson
parent 1ca18b215f
commit 978009e484
2 changed files with 9 additions and 7 deletions

View File

@ -2,13 +2,14 @@ USING:
html.parser html.parser.printer
io.streams.string
namespaces
strings
tools.test ;
IN: html.parser.printer.tests
[
" "
] [
[ 5 #indentations set 2 tab-width set tabs ] with-scope
[ 5 #indentations set 2 tab-width set tabs >string ] with-scope
] unit-test
[

View File

@ -1,7 +1,7 @@
USING: accessors assocs html.parser html.parser.utils combinators
continuations hashtables
hashtables.private io kernel make math
namespaces prettyprint quotations sequences sequences.repeating splitting
namespaces prettyprint quotations sequences splitting
strings unicode.categories ;
IN: html.parser.printer
@ -73,17 +73,18 @@ SYMBOL: tagstack
print-tags
] with-scope ;
: tabs ( -- str )
" " tab-width get #indentations get * repeat ;
: tabs ( -- vseq )
tab-width get #indentations get * CHAR: \s <repetition> ;
M: html-prettyprinter print-opening-tag ( tag -- )
name>>
[ tabs "<" append ">\n" surround write ]
[ tabs write "<" write write ">\n" write ]
! These tags usually don't have any closing tag associated with them.
[ { "br" "img" } member? [ #indentations inc ] unless ] bi ;
M: html-prettyprinter print-closing-tag ( tag -- )
#indentations dec name>> tabs "</" append ">\n" surround write ;
#indentations dec
tabs write "</" write name>> write ">\n" write ;
M: html-prettyprinter print-text-tag ( tag -- )
text>> [ blank? ] trim [ tabs "\n" surround write ] unless-empty ;
text>> [ blank? ] trim [ tabs write write "\n" write ] unless-empty ;