def reduced_markdown(text, *args, **kwargs):
    """
    Monkey patch for standart markdown library, removes heading tag support
    and adds prettyprint to pre tags. (for google code prettyfy
    """

    from markdown import blockprocessors as bp
    from markdown import util
    from markdown import markdown

    def run_with_prettify(self, parent, blocks):
        """ Run method is overriden to render pre tag with prettify class """

        sibling = self.lastChild(parent)
        block = blocks.pop(0)
        theRest = ''
        if sibling and sibling.tag == "pre" and len(sibling) \
            and sibling[0].tag == "code":
            # The previous block was a code block. As blank lines do not start
            # new code blocks, append this block to the previous, adding back
            # linebreaks removed from the split into a list.
            code = sibling[0]
            block, theRest = self.detab(block)
            code.text = util.AtomicString('%s\n%s\n' %
                (code.text, block.rstrip()))
        else:
            # This is a new codeblock. Create the elements and insert text.
            pre = util.etree.SubElement(parent, 'pre')
            pre.attrib['class'] = 'prettyprint'
            code = util.etree.SubElement(pre, 'code')
            block, theRest = self.detab(block)
            code.text = util.AtomicString('%s\n' % block.rstrip())
        if theRest:
            # This block contained unindented line(s) after the first indented
            # line. Insert these lines as the first block of the master blocks
            # list for future processing.
            blocks.insert(0, theRest)

    def build_block_parser(md_instance, **kwargs):
        """ Build reduced block parser used by Markdown. """
        parser = bp.BlockParser(md_instance)
        parser.blockprocessors['empty'] = bp.EmptyBlockProcessor(parser)
        parser.blockprocessors['code'] = bp.CodeBlockProcessor(parser)
        parser.blockprocessors['olist'] = bp.OListProcessor(parser)
        parser.blockprocessors['ulist'] = bp.UListProcessor(parser)
        parser.blockprocessors['quote'] = bp.BlockQuoteProcessor(parser)
        parser.blockprocessors['paragraph'] = bp.ParagraphProcessor(parser)
        return parser

    bp.build_block_parser = build_block_parser
    bp.CodeBlockProcessor.run = run_with_prettify

    return markdown(text, *args, **kwargs)
dataset/ETHPy150Open linkfloyd/linkfloyd/linkfloyd/utils.py/reduced_markdown/original