     [ SBUF" " clone >>temporary-buffer drop ] bi ;
 
 : emit-eof ( document -- ) drop "emit-eof" print ;
-: emit-char ( char document -- ) drop "emit-char:" write . ;
+: emit-char ( char document -- ) drop "emit-char: " write 1string . ;
 : emit-temporary-buffer-with ( string document -- ) "emit-temp-buffer: " write temporary-buffer>> append . ;
-: emit-string ( char document -- ) drop "emit-string:" write . ;
-: emit-tag ( document -- ) "emit tag: " write . ;
+: emit-string ( char document -- ) drop "emit-string: " write . ;
+: emit-tag ( document -- )
+    "emit tag: " write
+    [ tag-name>> >string . ]
+    [ SBUF" " clone >>tag-name drop ] bi ;
 : emit-end-tag ( document -- ) "emit end tag: " write . ;
 : emit-doctype-token ( document -- )
     "emit doctype: " write

    ; inline

TUPLE: document
tree
tree-insert-mode
doctype-token
tag-name
end-tag-name
attribute-name
attribute-value
temporary-buffer

    next-char-from (bogus-comment-state) ;


: markup-declaration-open-state ( document n/f string -- document n'/f string )
    {
        { [ "--" take-from? ] [ comment-start-state ] }
        { [ "DOCTYPE" take-from-insensitive? ] [ doctype-state ] }
        { [ "[CDATA[" take-from-insensitive? ] [ unimplemented* ] }
