Code Duplication    Length = 15-20 lines in 2 locations

pythonx/markdown_lib/blockprocessors.py 2 locations

@@ 431-450 (lines=20) @@
428
    def test(self, parent, block):
429
        return bool(self.RE.search(block))
430
431
    def run(self, parent, blocks):
432
        block = blocks.pop(0)
433
        m = self.RE.search(block)
434
        if m:
435
            before = block[:m.start()]  # All lines before header
436
            after = block[m.end():]     # All lines after header
437
            if before:
438
                # As the header was not the first line of the block and the
439
                # lines before the header must be parsed first,
440
                # recursively parse this lines as a block.
441
                self.parser.parseBlocks(parent, [before])
442
            # Create header using named groups from RE
443
            h = util.etree.SubElement(parent, 'h%d' % len(m.group('level')))
444
            h.text = m.group('header').strip()
445
            if after:
446
                # Insert remaining lines as first block for future parsing.
447
                blocks.insert(0, after)
448
        else:  # pragma: no cover
449
            # This should never happen, but just in case...
450
            logger.warn("We've got a problem header: %r" % block)
451
452
453
class SetextHeaderProcessor(BlockProcessor):
@@ 494-508 (lines=15) @@
491
            return True
492
        return False
493
494
    def run(self, parent, blocks):
495
        block = blocks.pop(0)
496
        match = self.match
497
        # Check for lines in block before hr.
498
        prelines = block[:match.start()].rstrip('\n')
499
        if prelines:
500
            # Recursively parse lines before hr so they get parsed first.
501
            self.parser.parseBlocks(parent, [prelines])
502
        # create hr
503
        util.etree.SubElement(parent, 'hr')
504
        # check for lines in block after hr.
505
        postlines = block[match.end():].lstrip('\n')
506
        if postlines:
507
            # Add lines after hr to master blocks for later parsing.
508
            blocks.insert(0, postlines)
509
510
511
class EmptyBlockProcessor(BlockProcessor):