'Convert markdown to serialized XHTML or HTML.
Keyword arguments:
* source: Source text as a Unicode string.
Markdown processing takes place in five steps:
1. A bunch of "preprocessors" munge the input text.
2. BlockParser() parses the high-level structural elements of the
pre-processed text into an ElementTree.
3. A bunch of "treeprocessors" are run against the ElementTree. One
such treeprocessor runs InlinePatterns against the ElementTree,
detecting inline markup.
4. Some post-processors are run against the text after the ElementTree
has been serialized into text.
5. The output is written to a string.'

def convert(self, source):

    if (not source.strip()):
        return u''
    try:
        source = util.text_type(source)
    except UnicodeDecodeError as e:
        e.reason += u'.    --    Note:    Markdown    only    accepts    unicode    input!'
        raise
    self.lines = source.split(u'\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 is not None):
            root = newRoot
    output = self.serializer(root)
    if self.stripTopLevelTags:
        try:
            start = ((output.index((u'<%s>' % self.doc_tag)) + len(self.doc_tag)) + 2)
            end = output.rindex((u'</%s>' % self.doc_tag))
            output = output[start:end].strip()
        except ValueError:
            if output.strip().endswith((u'<%s    />' % self.doc_tag)):
                output = u''
            else:
                raise ValueError((u'Markdown    failed    to    strip    top-level    tags.    Document=%r' % output.strip()))
    for pp in self.postprocessors.values():
        output = pp.run(output)
    return output.strip()
