 _ = require 'underscore'
 $ = require '../cheerio'
+parser = require '../parser'
 
 removeChild = (parent, elem) ->
  $.each parent.children, (i, child) ->

  this.each ->
    this.children = []

html = exports.html = (htmlString) ->
  if htmlString is undefined
    if this[0] and this[0].type is "tag"
      return $.html this[0]

dom = exports.dom = (domObject) ->
  if domObject is undefined
    if this[0] and this[0].type is "tag"
      return $.dom this[0]

text = exports.text = (textString) ->
  if _.isFunction textString
    this.each (i) ->

  
  # Set the text
  if typeof textString isnt "object" and textString isnt undefined
    textElement = parser.parse textString
    this.each (i) ->
      if this.children
        this.children = textElement
    return this
  else  
    return $.text this
  
module.exports = $.fn.extend exports