'Convert the given text.'

def convert(self, text):

    self.reset()
    if (not isinstance(text, unicode)):
        text = unicode(text, 'utf-8')
    if self.use_file_vars:
        emacs_vars = self._get_emacs_vars(text)
        if ('markdown-extras' in emacs_vars):
            splitter = re.compile('[    ,]+')
            for e in splitter.split(emacs_vars['markdown-extras']):
                if ('=' in e):
                    (ename, earg) = e.split('=', 1)
                    try:
                        earg = int(earg)
                    except ValueError:
                        pass
                else:
                    (ename, earg) = (e, None)
                self.extras[ename] = earg
    text = re.sub('\r\n|\r', '\n', text)
    text += '\n\n'
    text = self._detab(text)
    text = self._ws_only_line_re.sub('', text)
    if ('metadata' in self.extras):
        text = self._extract_metadata(text)
    text = self.preprocess(text)
    if (('fenced-code-blocks' in self.extras) and (not self.safe_mode)):
        text = self._do_fenced_code_blocks(text)
    if self.safe_mode:
        text = self._hash_html_spans(text)
    text = self._hash_html_blocks(text, raw=True)
    if (('fenced-code-blocks' in self.extras) and self.safe_mode):
        text = self._do_fenced_code_blocks(text)
    if ('footnotes' in self.extras):
        text = self._strip_footnote_definitions(text)
    text = self._strip_link_definitions(text)
    text = self._run_block_gamut(text)
    if ('footnotes' in self.extras):
        text = self._add_footnotes(text)
    text = self.postprocess(text)
    text = self._unescape_special_chars(text)
    if self.safe_mode:
        text = self._unhash_html_spans(text)
    if ('nofollow' in self.extras):
        text = self._a_nofollow.sub('<\\1    rel="nofollow"\\2', text)
    text += '\n'
    rv = UnicodeWithAttrs(text)
    if ('toc' in self.extras):
        rv._toc = self._toc
    if ('metadata' in self.extras):
        rv.metadata = self.metadata
    return rv
