 : html-src ( vector -- string )
     [ html-src. ] with-string-writer ;
 
+SYMBOLS: preformatted? script? style? ;
+
 M: text-printer print-opening-tag
     name>> {
         { "br" [ nl indent ] }
-        ! { "ol" [ nl indent ] }
-        ! { "ul" [ nl indent ] }
+        { "ol" [ nl indent ] }
+        { "ul" [ nl indent ] }
         { "li" [ " * " write ] }
         { "blockquote" [ #indentations inc indent ] }
+        { "pre" [ preformatted? on ] }
+        { "script" [ script? on ] }
+        { "style" [ style? on ] }
         [ drop ]
     } case ;
 

        [
            { "ul" "ol" "li" "tr" } member? [ nl indent ] when
        ]
        [ "td" = [ bl ] when ]
    } cleave ;

M: text-printer print-comment-tag drop ;

M: html-printer print-text-tag ( tag -- )
    text>> write ;

M: html-printer print-comment-tag ( tag -- )
    "<!--" write text>> write "-->" write ;

M: html-printer print-dtd-tag ( tag -- )
    "<!" write text>> write ">" write ;

: print-attributes ( hashtable -- )
    [ [ bl write "=" write ] [ ?quote write ] bi* ] assoc-each ;

M: src-printer print-opening-tag ( tag -- )
    "<" write
    [ name>> write ] [ attributes>> print-attributes ] bi
    ">" write ;

M: src-printer print-closing-tag ( tag -- )
    "</" write name>> write ">" write ;

: prettyprint-html ( vector -- )
    T{ html-prettyprinter } html-printer [ print-tags ] with-variable ;

M: html-prettyprinter print-opening-tag ( tag -- )
    name>>
    [ indent "<" 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 -- )
    ! These tags usually don't have any closing tag associated with them.
    [ { "br" "img" } member? [ #indentations dec ] unless ]
    [ indent "</" write name>> write ">\n" write ] bi ;

M: html-prettyprinter print-text-tag ( tag -- )
    text>> [ blank? ] trim [ indent write "\n" write ] unless-empty ;

USING: accessors assocs combinators fry html.parser
html.parser.utils io io.streams.string kernel math namespaces
regexp sequences strings unicode ;
IN: html.parser.printer

SYMBOL: indentation "  " indentation set-global
