'@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 = min(int((round((float(style.marginTop) / style.fontSize)) - 1)), self.MAX_EM)
        if (ems >= 1):
            text.append((u'\n\n\xa0' * ems))
    if (tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'div')):
        if (tag == 'div'):
            tag = 'p'
        text.append(self.build_block(tag, style, attribs, stylizer))
        text.append('.    ')
        tags.append('\n')
    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):
                if self.in_a_link:
                    text.append('_')
                    tags.append('_')
                else:
                    text.append('[_')
                    tags.append('_]')
                self.style_embed.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):
                if self.in_a_link:
                    text.append('*')
                    tags.append('*')
                else:
                    text.append('[*')
                    tags.append('*]')
                self.style_embed.append('*')
                self.style_bold = True
    if ((style['text-decoration'] == 'underline') or (tag in ('u', 'ins'))):
        if (tag != 'a'):
            if (self.style_under == False):
                text.append('[+')
                tags.append('+]')
                self.style_embed.append('+')
                self.style_under = True
    if ((style['text-decoration'] == 'line-through') or (tag in ('strike', 'del', 's'))):
        if (self.style_strike == False):
            text.append('[-')
            tags.append('-]')
            self.style_embed.append('-')
            self.style_strike = True
    if (tag == 'br'):
        for i in reversed(self.style_embed):
            text.append(i)
        text.append('\n')
        for i in self.style_embed:
            text.append(i)
        tags.append('')
        self.remove_space_after_newline = True
    if (tag == 'blockquote'):
        text.append('\nbq.    ')
        tags.append('\n')
    elif (tag in ('abbr', 'acronym')):
        text.append('')
        txt = attribs['title']
        tags.append((('(' + txt) + ')'))
    elif (tag == 'sup'):
        text.append('^')
        tags.append('^')
    elif (tag == 'sub'):
        text.append('~')
        tags.append('~')
    elif (tag == 'code'):
        if self.in_pre:
            text.append('\nbc.    ')
            tags.append('')
        else:
            text.append('@')
            tags.append('@')
    elif (tag == 'cite'):
        text.append('??')
        tags.append('??')
    elif (tag == 'hr'):
        text.append('\n***')
        tags.append('\n')
    elif (tag == 'pre'):
        self.in_pre = True
        text.append('\npre.    ')
        tags.append('pre\n')
    elif (tag == 'a'):
        if self.opts.keep_links:
            if attribs.has_key('href'):
                text.append('"')
                tags.append('a')
                tags.append(('":' + attribs['href']))
                self.our_links.append(attribs['href'])
                if attribs.has_key('title'):
                    tags.append((('(' + attribs['title']) + ')'))
                self.in_a_link = True
            else:
                text.append('%')
                tags.append('%')
    elif (tag == 'img'):
        if self.opts.keep_image_references:
            txt = ('!' + self.check_halign(style))
            txt += self.check_valign(style)
            txt += attribs['src']
            text.append(txt)
            if attribs.has_key('alt'):
                txt = attribs['alt']
                if (txt != ''):
                    text.append((('(' + txt) + ')'))
            tags.append('!')
    elif (tag in ('ol', 'ul')):
        self.list.append({'name': tag, 'num': 0})
        text.append('')
        tags.append(tag)
    elif (tag == 'li'):
        if self.list:
            li = self.list[(-1)]
        else:
            li = {'name': 'ul', 'num': 0}
        text.append('\n')
        if (li['name'] == 'ul'):
            text.append((('*' * len(self.list)) + '    '))
        elif (li['name'] == 'ol'):
            text.append((('#' * len(self.list)) + '    '))
        tags.append('')
    elif (tag == 'dl'):
        text.append('\n')
        tags.append('')
    elif (tag == 'dt'):
        text.append('')
        tags.append('\n')
    elif (tag == 'dd'):
        text.append('                ')
        tags.append('')
    elif (tag == 'dd'):
        text.append('')
        tags.append('\n')
    elif (tag == 'table'):
        txt = self.build_block(tag, style, attribs, stylizer)
        txt += '.    \n'
        if (txt != '\ntable.    \n'):
            text.append(txt)
        else:
            text.append('\n')
        tags.append('')
    elif (tag == 'tr'):
        txt = self.build_block('', style, attribs, stylizer)
        txt += '.    '
        if (txt != '\n.    '):
            txt = re.sub('\n', '', txt)
            text.append(txt)
        tags.append('|\n')
    elif (tag == 'td'):
        text.append('|')
        txt = ''
        txt += self.check_halign(style)
        txt += self.check_valign(style)
        if attribs.has_key('colspan'):
            txt += ('\\' + attribs['colspan'])
        if attribs.has_key('rowspan'):
            txt += ('/' + attribs['rowspan'])
        txt += self.check_styles(style)
        if (txt != ''):
            text.append((txt + '.    '))
        tags.append('')
    elif (tag == 'th'):
        text.append('|_.    ')
        tags.append('')
    elif (tag == 'span'):
        if (style['font-variant'] == 'small-caps'):
            if (self.style_smallcap == False):
                text.append('&')
                tags.append('&')
                self.style_smallcap = True
        elif (self.in_a_link == False):
            txt = '%'
            if self.opts.keep_links:
                txt += self.check_id_tag(attribs)
                txt += self.check_styles(style)
            if (txt != '%'):
                text.append(txt)
                tags.append('%')
    if (self.opts.keep_links and attribs.has_key('id')):
        if (tag not in ('body', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'span', 'table')):
            text.append(self.check_id_tag(attribs))
    if (tag not in ('body', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'hr', 'a', 'img', 'span', 'table', 'tr', 'td')):
        if (not self.in_a_link):
            text.append(self.check_styles(style))
    if (hasattr(elem, 'text') and elem.text):
        txt = elem.text
        if (not self.in_pre):
            txt = self.prepare_string_for_textile(self.remove_newlines(txt))
        text.append(txt)
        self.id_no_text = u''
    for item in elem:
        text += self.dump_text(item, stylizer)
    tags.reverse()
    for t in tags:
        if (t in ('pre', 'ul', 'ol', 'li', 'table')):
            if (t == 'pre'):
                self.in_pre = False
            elif (t in ('ul', 'ol')):
                if self.list:
                    self.list.pop()
                if (not self.list):
                    text.append('\n')
        else:
            if (t == 'a'):
                self.in_a_link = False
                t = ''
            text.append(self.id_no_text)
            self.id_no_text = u''
            if (t in ('*]', '*')):
                self.style_bold = False
            elif (t in ('_]', '_')):
                self.style_italic = False
            elif (t == '+]'):
                self.style_under = False
            elif (t == '-]'):
                self.style_strike = False
            elif (t == '&'):
                self.style_smallcap = False
            if (t in ('*]', '_]', '+]', '-]', '*', '_')):
                txt = self.style_embed.pop()
            text.append(('%s' % t))
    if (('margin-bottom' in style.cssdict()) and (style['margin-bottom'] != 'auto')):
        ems = min(int(round(((float(style.marginBottom) / style.fontSize) - 1))), self.MAX_EM)
        if (ems >= 1):
            text.append((u'\n\n\xa0' * ems))
    if (hasattr(elem, 'tail') and elem.tail):
        tail = elem.tail
        if (not self.in_pre):
            tail = self.prepare_string_for_textile(self.remove_newlines(tail))
        text.append(tail)
    return text
