         [ unknown-tag-error ]
     } cond ;
 
-: print-tags ( vector -- ) [ print-tag ] each ;
+: print-tags ( vector -- )
+    0 #indentations [ [ print-tag ] each ] with-variable ;
 
 : html-text. ( vector -- )
     T{ text-printer } html-printer [ print-tags ] with-variable ;


M: text-printer print-opening-tag
    name>> {
        { "br" [ nl ] }
        { "ol" [ nl ] }
        { "ul" [ nl ] }
        { "li" [ " * " write ] }
        [ drop ]
    } case ;

M: text-printer print-closing-tag
    name>>
    [
        { "p" "blockquote" "h1" "h2" "h3" "h4" "h5" }
        member? [ nl nl ] when
    ]
    [
        { "ul" "ol" "li" "tr" } member? [ nl ] when
    ]
    [ "td" = [ bl ] when ] tri ;

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


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

SYMBOL: indentation "  " indentation set-global
SYMBOL: #indentations

: indent ( -- )
    #indentations get indentation get '[ _ write ] times ;

TUPLE: html-printer ;
TUPLE: text-printer < html-printer ;
