 { deep_merge, indent, new_attrs, safe } = require './util'
 EVENTS = ['add', 'attr', 'attr:remove', 'text', 'remove', 'close']
 
-new_tag = (name, attrs, children, opts) ->
+new_tag = (builder, name, attrs, children, opts) ->
     unless typeof attrs is 'object'
         [opts, children, attrs] = [children, attrs, {}]
     else

        attrs ?= {}
    opts ?= {}
    pipe = {}
    opts.level = @level+1
    opts = deep_merge @opts, opts # possibility to overwrite existing opts, like pretty


    @pending.push tag = new @Tag name, attrs, _children, opts

    tag.up = (opts = {}) => # set parent
        opts.end ?= true

        @headers = "<#{@name}#{new_attrs @attrs}"
        @children children, @opts

    tag: (args...) =>
        @builder._new_tag.apply this, [this].concat args

    $tag: (args...) =>
        @builder._new_sync_tag.apply this, [this].concat args

    attr: (key, value) =>
        if typeof key is 'string'
