'Convert markdown to serialized XHTML or HTML.
Keyword arguments:
* source: Source text as a Unicode string.'

def convert(self, source):

    if (not source.strip()):
        return u''
    try:
        source = unicode(source)
    except UnicodeDecodeError:
        message(CRITICAL, 'UnicodeDecodeError:    Markdown    only    accepts    unicode    or    ascii    input.')
        return u''
    source = source.replace(STX, '').replace(ETX, '')
    source = (source.replace('\r\n', '\n').replace('\r', '\n') + '\n\n')
    source = re.sub('\\n\\s+\\n', '\n\n', source)
    source = source.expandtabs(TAB_LENGTH)
    self.lines = source.split('\n')
    for prep in self.preprocessors.values():
        self.lines = prep.run(self.lines)
    root = self.parser.parseDocument(self.lines).getroot()
    for treeprocessor in self.treeprocessors.values():
        newRoot = treeprocessor.run(root)
        if newRoot:
            root = newRoot
    (output, length) = codecs.utf_8_decode(self.serializer(root, encoding='utf-8'))
    if self.stripTopLevelTags:
        try:
            start = ((output.index(('<%s>' % DOC_TAG)) + len(DOC_TAG)) + 2)
            end = output.rindex(('</%s>' % DOC_TAG))
            output = output[start:end].strip()
        except ValueError:
            if output.strip().endswith(('<%s    />' % DOC_TAG)):
                output = ''
            else:
                message(CRITICAL, 'Failed    to    strip    top    level    tags.')
    for pp in self.postprocessors.values():
        output = pp.run(output)
    return output.strip()
