(self, source)
return output.strip()
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.
Convert markdown to serialized XHTML or HTML.
Convert markdown to serialized XHTML or HTML .
def convert(self, source):
        """
        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.

        """

        # Fixup the source text
        if not source.strip():
            return u""  # a blank unicode string

        try:
            source = unicode(source)
        except UnicodeDecodeError, e:
            # Customise error message while maintaining original trackback
            e.reason += '. -- Note: Markdown only accepts unicode input!'
            raise

        source = source.replace(util.STX, "").replace(util.ETX, "")
        source = source.replace("\r\n", "\n").replace("\r", "\n") + "\n\n"
        source = re.sub(r'\n\s+\n', '\n\n', source)
        source = source.expandtabs(self.tab_length)

        # Split into lines and run the line preprocessors.
        self.lines = source.split("\n")
        for prep in self.preprocessors.values():
            self.lines = prep.run(self.lines)

        # Parse the high-level elements.
        root = self.parser.parseDocument(self.lines).getroot()

        # Run the tree-processors
        for treeprocessor in self.treeprocessors.values():
            newRoot = treeprocessor.run(root)
            if newRoot:
                root = newRoot

        # Serialize _properly_.  Strip top-level tags.
        output = self.serializer(root)
        if self.stripTopLevelTags:
            try:
                start = output.index('<%s>'%self.doc_tag)+len(self.doc_tag)+2
                end = output.rindex('</%s>'%self.doc_tag)
                output = output[start:end].strip()
            except ValueError:
                if output.strip().endswith('<%s />'%self.doc_tag):
                    # We have an empty document
                    output = ''
                else:
                    # We have a serious problem
                    raise ValueError('Markdown failed to strip top-level tags. Document=%r' % output.strip())

        # Run the text post-processors
        for pp in self.postprocessors.values():
            output = pp.run(output)

        return output.strip()
def convert ( self , source ) : # Fixup the source text if not source . strip ( ) : return u"" # a blank unicode string try : source = unicode ( source ) except UnicodeDecodeError , e : # Customise error message while maintaining original trackback e . reason += '. -- Note: Markdown only accepts unicode input!' raise source = source . replace ( util . STX , "" ) . replace ( util . ETX , "" ) source = source . replace ( "\r\n" , "\n" ) . replace ( "\r" , "\n" ) + "\n\n" source = re . sub ( r'\n\s+\n' , '\n\n' , source ) source = source . expandtabs ( self . tab_length ) # Split into lines and run the line preprocessors. self . lines = source . split ( "\n" ) for prep in self . preprocessors . values ( ) : self . lines = prep . run ( self . lines ) # Parse the high-level elements. root = self . parser . parseDocument ( self . lines ) . getroot ( ) # Run the tree-processors for treeprocessor in self . treeprocessors . values ( ) : newRoot = treeprocessor . run ( root ) if newRoot : root = newRoot # Serialize _properly_.  Strip top-level tags. output = self . serializer ( root ) if self . stripTopLevelTags : try : start = output . index ( '<%s>' % self . doc_tag ) + len ( self . doc_tag ) + 2 end = output . rindex ( '</%s>' % self . doc_tag ) output = output [ start : end ] . strip ( ) except ValueError : if output . strip ( ) . endswith ( '<%s />' % self . doc_tag ) : # We have an empty document output = '' else : # We have a serious problem raise ValueError ( 'Markdown failed to strip top-level tags. Document=%r' % output . strip ( ) ) # Run the text post-processors for pp in self . postprocessors . values ( ) : output = pp . run ( output ) return output . strip ( )