# 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:
                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)
doc-pelican (0.7)$ python3 test.py
Markdown 2.6.9
Traceback (most recent call last):
File "test.py", line 22, in <module>
print(md.convert(text))
File "/usr/lib/python3/dist-packages/markdown/__init__.py", line 371, in convert
root = self.parser.parseDocument(self.lines).getroot()
File "/usr/lib/python3/dist-packages/markdown/blockparser.py", line 65, in parseDocument
self.parseChunk(self.root, '\n'.join(lines))
File "/usr/lib/python3/dist-packages/markdown/blockparser.py", line 80, in parseChunk
self.parseBlocks(parent, text.split('\n\n'))
File "/usr/lib/python3/dist-packages/markdown/blockparser.py", line 98, in parseBlocks
if processor.run(parent, blocks) is not False:
File "/usr/lib/python3/dist-packages/markdown/extensions/extra.py", line 130, in run
block = self._process_nests(element, block)
File "/usr/lib/python3/dist-packages/markdown/extensions/extra.py", line 97, in _process_nests
self.run(element, block[nest_index[-1][0]:nest_index[-1][1]],  # last
IndexError: list index out of range

# Fixed 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