# Buggy code
def extendMarkdown(self, md):
    """Add pieces to Markdown."""
    md.registerExtension(self)
    self.parser = md.parser
    self.md = md
    # Insert a preprocessor before ReferencePreprocessor
    md.preprocessors.register(FootnotePreprocessor(self), "footnote", 15)

    # Insert an inline pattern before ImageReferencePattern
    FOOTNOTE_RE = r"\[\^([^\]]*)\]"  # blah blah [^1] blah
    md.inlinePatterns.register(
        FootnoteInlineProcessor(FOOTNOTE_RE, self), "footnote", 175
    )
    # Insert a tree-processor that would actually add the footnote div
    # This must be before all other treeprocessors (i.e., inline and
    # codehilite) so they can run on the the contents of the div.
    md.treeprocessors.register(FootnoteTreeprocessor(self), "footnote", 50)

    # Insert a tree-processor that will run after inline is done.
    # In this tree-processor we want to check our duplicate footnote tracker
    # And add additional backrefs to the footnote pointing back to the
    # duplicated references.
    md.treeprocessors.register(
        FootnotePostTreeprocessor(self), "footnote-duplicate", 15
    )

    # Insert a postprocessor after amp_substitute processor
    md.postprocessors.register(FootnotePostprocessor(self), "footnote", 25)


# Traceback (IndexError)
Traceback (most recent call last):
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/test_tools.py", line 117, in test
output = markdown(input, **kwargs)
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/core.py", line 391, in markdown
return md.convert(text)
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/core.py", line 268, in convert
root = self.parser.parseDocument(self.lines).getroot()
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/blockparser.py", line 92, in parseDocument
self.parseChunk(self.root, '\n'.join(lines))
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/blockparser.py", line 107, in parseChunk
self.parseBlocks(parent, text.split('\n\n'))
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/blockparser.py", line 125, in parseBlocks
if processor.run(parent, blocks) is not False:
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/extensions/extra.py", line 127, in run
block = self._process_nests(element, block)
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/extensions/extra.py", line 95, in _process_nests
block[nest_index[-1][1]:], True)                      # nest
File "/home/ikus060/workspace/PDSL/markdown.git/markdown/extensions/extra.py", line 101, in run
tag = self._tag_data[self.parser.blockprocessors.tag_counter]
IndexError: list index out of range

# Fixed code
def extendMarkdown(self, md):
    """Add pieces to Markdown."""
    md.registerExtension(self)
    self.parser = md.parser
    self.md = md
    # Insert a blockprocessor before ReferencePreprocessor
    md.parser.blockprocessors.register(FootnoteBlockProcessor(self), "footnote", 17)

    # Insert an inline pattern before ImageReferencePattern
    FOOTNOTE_RE = r"\[\^([^\]]*)\]"  # blah blah [^1] blah
    md.inlinePatterns.register(
        FootnoteInlineProcessor(FOOTNOTE_RE, self), "footnote", 175
    )
    # Insert a tree-processor that would actually add the footnote div
    # This must be before all other treeprocessors (i.e., inline and
    # codehilite) so they can run on the the contents of the div.
    md.treeprocessors.register(FootnoteTreeprocessor(self), "footnote", 50)

    # Insert a tree-processor that will run after inline is done.
    # In this tree-processor we want to check our duplicate footnote tracker
    # And add additional backrefs to the footnote pointing back to the
    # duplicated references.
    md.treeprocessors.register(
        FootnotePostTreeprocessor(self), "footnote-duplicate", 15
    )

    # Insert a postprocessor after amp_substitute processor
    md.postprocessors.register(FootnotePostprocessor(self), "footnote", 25)