html.parser.printer: fixed to use repeated write calls instead of surround
parent
1ca18b215f
commit
978009e484
|
@ -2,13 +2,14 @@ USING:
|
||||||
html.parser html.parser.printer
|
html.parser html.parser.printer
|
||||||
io.streams.string
|
io.streams.string
|
||||||
namespaces
|
namespaces
|
||||||
|
strings
|
||||||
tools.test ;
|
tools.test ;
|
||||||
IN: html.parser.printer.tests
|
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
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
USING: accessors assocs html.parser html.parser.utils combinators
|
USING: accessors assocs html.parser html.parser.utils combinators
|
||||||
continuations hashtables
|
continuations hashtables
|
||||||
hashtables.private io kernel make math
|
hashtables.private io kernel make math
|
||||||
namespaces prettyprint quotations sequences sequences.repeating splitting
|
namespaces prettyprint quotations sequences splitting
|
||||||
strings unicode.categories ;
|
strings unicode.categories ;
|
||||||
IN: html.parser.printer
|
IN: html.parser.printer
|
||||||
|
|
||||||
|
@ -73,17 +73,18 @@ SYMBOL: tagstack
|
||||||
print-tags
|
print-tags
|
||||||
] with-scope ;
|
] with-scope ;
|
||||||
|
|
||||||
: tabs ( -- str )
|
: tabs ( -- vseq )
|
||||||
" " tab-width get #indentations get * repeat ;
|
tab-width get #indentations get * CHAR: \s <repetition> ;
|
||||||
|
|
||||||
M: html-prettyprinter print-opening-tag ( tag -- )
|
M: html-prettyprinter print-opening-tag ( tag -- )
|
||||||
name>>
|
name>>
|
||||||
[ tabs "<" append ">\n" surround write ]
|
[ tabs write "<" write write ">\n" write ]
|
||||||
! These tags usually don't have any closing tag associated with them.
|
! These tags usually don't have any closing tag associated with them.
|
||||||
[ { "br" "img" } member? [ #indentations inc ] unless ] bi ;
|
[ { "br" "img" } member? [ #indentations inc ] unless ] bi ;
|
||||||
|
|
||||||
M: html-prettyprinter print-closing-tag ( tag -- )
|
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 -- )
|
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 ;
|
||||||
|
|
Loading…
Reference in New Issue