# Buggy code
def detectTabbed(self, lines):
    """Find indented text and remove indent before further proccesing.

    Keyword arguments:

    * lines: an array of strings

    Returns: a list of post processed items and the index of last line.

    """
    items = []
    blank_line = False  # have we encountered a blank line yet?
    i = 0  # to keep track of where we are

    def detab(line):
        match = TABBED_RE.match(line)
        if match:
            return match.group(4)

    for line in lines:
        if line.strip():  # Non-blank line
            detabbed_line = detab(line)
            if detabbed_line:
                items.append(detabbed_line)
                i += 1
                continue
            elif not blank_line and not DEF_RE.match(line):
                # not tabbed but still part of first par.
                items.append(line)
                i += 1
                continue
            else:
                return items, i + 1

        else:  # Blank line: _maybe_ we are done.
            blank_line = True
            i += 1  # advance

            # Find the next non-blank line
            for j in range(i, len(lines)):
                if lines[j].strip():
                    next_line = lines[j]
                    break
                else:
                    # Include extreaneous padding to prevent raw HTML
                    # parsing issue: https://github.com/Python-Markdown/markdown/issues/584
                    items.append("")
                    i += 1
            else:
                break  # There is no more text; we are done.

            # Check if the next non-blank line is tabbed
            if detab(next_line):  # Yes, more work to do.
                items.append("")
                continue
            else:
                break  # No, we are done.
    else:
        i += 1

    return items, i


# 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 detectTabbed(self, blocks):
    """Find indented text and remove indent before further proccesing.

    Returns: a list of blocks with indentation removed.
    """
    fn_blocks = []
    while blocks:
        if blocks[0].startswith(" " * 4):
            block = blocks.pop(0)
            # Check for new footnotes within this block and split at new footnote.
            m = self.RE.search(block)
            if m:
                # Another footnote exists in this block.
                # Any content before match is continuation of this footnote, which may be lazily indented.
                before = block[: m.start()].rstrip("\n")
                fn_blocks.append(self.detab(before))
                # Add back to blocks everything from begining of match forward for next iteration.
                blocks.insert(0, block[m.start() :])
                # End of this footnote.
                break
            else:
                # Entire block is part of this footnote.
                fn_blocks.append(self.detab(block))
        else:
            # End of this footnote.
            break
    return fn_blocks