'@elem: The element in the etree that we are working on.
@stylizer: The style information attached to the element.'

def dump_text(self, elem, stylizer):

    if ((not isinstance(elem.tag, basestring)) or (namespace(elem.tag) != XHTML_NS)):
        p = elem.getparent()
        if ((p is not None) and isinstance(p.tag, basestring) and (namespace(p.tag) == XHTML_NS) and elem.tail):
            return [elem.tail]
        return ['']
    text = []
    style = stylizer.style(elem)
    tags = []
    tag = barename(elem.tag)
    attribs = elem.attrib
    if ((style['display'] in ('none', 'oeb-page-head', 'oeb-page-foot')) or (style['visibility'] == 'hidden')):
        if (hasattr(elem, 'tail') and elem.tail):
            return [elem.tail]
        return ['']
    if (('margin-top' in style.cssdict()) and (style['margin-top'] != 'auto')):
        ems = int((round((float(style.marginTop) / style.fontSize)) - 1))
        if (ems >= 1):
            text.append((u'\n\n' * ems))
    bq = ('>    ' * self.blockquotes)
    if (tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div')):
        h_tag = ''
        if (tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6')):
            h_tag = (('#' * int(tag[1])) + '    ')
        text.append((('\n' + bq) + h_tag))
        tags.append('\n')
        self.remove_space_after_newline = True
    if ((style['font-style'] == 'italic') or (tag in ('i', 'em'))):
        if (tag not in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite')):
            if (self.style_italic == False):
                text.append('*')
                tags.append('*')
                self.style_italic = True
    if ((style['font-weight'] in ('bold', 'bolder')) or (tag in ('b', 'strong'))):
        if (tag not in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'th')):
            if (self.style_bold == False):
                text.append('**')
                tags.append('**')
                self.style_bold = True
    if (tag == 'br'):
        text.append('        \n')
        self.remove_space_after_newline = True
    if (tag == 'blockquote'):
        self.blockquotes += 1
        tags.append('>')
        text.append(('>    ' * self.blockquotes))
    elif (tag == 'code'):
        if ((not self.in_pre) and (not self.in_code)):
            text.append('`')
            tags.append('`')
            self.in_code = True
    elif (tag == 'pre'):
        if (not self.in_pre):
            text.append('\n')
            tags.append('pre')
            self.in_pre = True
    elif (tag == 'hr'):
        text.append('\n*    *    *')
        tags.append('\n')
    elif (tag == 'a'):
        if (self.opts.keep_links and attribs.has_key('href') and ('://' in attribs['href'])):
            title = ''
            if attribs.has_key('title'):
                title = (('    "' + attribs['title']) + '"')
                remove_space = self.remove_space_after_newline
                title = self.remove_newlines(title)
                self.remove_space_after_newline = remove_space
            text.append('[')
            tags.append(((('](' + attribs['href']) + title) + ')'))
    elif (tag == 'img'):
        if self.opts.keep_image_references:
            txt = '!'
            if attribs.has_key('alt'):
                remove_space = self.remove_space_after_newline
                txt += (('[' + self.remove_newlines(attribs['alt'])) + ']')
                self.remove_space_after_newline = remove_space
            txt += (('(' + attribs['src']) + ')')
            text.append(txt)
    elif (tag in ('ol', 'ul')):
        tags.append(tag)
        self.list.append({'name': tag, 'num': 0})
    elif (tag == 'li'):
        if self.list:
            li = self.list[(-1)]
        else:
            li = {'name': 'ul', 'num': 0}
        text.append('\n')
        list_count = len(self.list)
        if ((list_count - 1) > 0):
            text.append((' DCTB ' * (list_count - 1)))
        text.append(bq)
        if (li['name'] == 'ul'):
            text.append('+    ')
        elif (li['name'] == 'ol'):
            li['num'] += 1
            text.append((unicode(li['num']) + '.    '))
    if (hasattr(elem, 'text') and elem.text):
        txt = elem.text
        if self.in_pre:
            txt = self.prepare_string_for_pre(txt)
        elif self.in_code:
            txt = self.remove_newlines(txt)
        else:
            txt = self.prepare_string_for_markdown(self.remove_newlines(txt))
        text.append(txt)
    for item in elem:
        text += self.dump_text(item, stylizer)
    tags.reverse()
    for t in tags:
        if (t in ('pre', 'ul', 'ol', '>')):
            if (t == 'pre'):
                self.in_pre = False
                text.append('\n')
            elif (t == '>'):
                self.blockquotes -= 1
            elif (t in ('ul', 'ol')):
                if self.list:
                    self.list.pop()
                text.append('\n')
        else:
            if (t == '**'):
                self.style_bold = False
            elif (t == '*'):
                self.style_italic = False
            elif (t == '`'):
                self.in_code = False
            text.append(('%s' % t))
    if (('margin-bottom' in style.cssdict()) and (style['margin-bottom'] != 'auto')):
        ems = int(round(((float(style.marginBottom) / style.fontSize) - 1)))
        if (ems >= 1):
            text.append((u'\n\n' * ems))
    if (hasattr(elem, 'tail') and elem.tail):
        tail = elem.tail
        if self.in_pre:
            tail = self.prepare_string_for_pre(tail)
        elif self.in_code:
            tail = self.remove_newlines(tail)
        else:
            tail = self.prepare_string_for_markdown(self.remove_newlines(tail))
        text.append(tail)
    return text
