waylan/Python-Markdown — Issue #49: TOC crashes on invalidly formatted links
Author: Wilfred
Created: 2011-10-17 15:34:26+00:00
State: open

If there's an invalid URL following a change in indentation of the form:

### bar

# foo

[a][(b)

I get the following crash:

In [1]: from markdown import markdown

In [2]: s = """### bar
...:
...: # foo
...:
...: [a][(b)"""

In [3]: markdown(s, extensions=['toc'])
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/home/wilfred/work/potatopedia/ in ()
----> 1 markdown(s, extensions=['toc'])

/home/wilfred/work/potatopedia/markdown/__init__.py in markdown(text, *args, **kwargs)
375 """
376 md = Markdown(*args, **kwargs)
--> 377 return md.convert(text)
378
379

/home/wilfred/work/potatopedia/markdown/__init__.py in convert(self, source)
281 # Run the tree-processors

282 for treeprocessor in self.treeprocessors.values():
--> 283 newRoot = treeprocessor.run(root)
284 if newRoot:
285 root = newRoot

/home/wilfred/work/potatopedia/markdown/extensions/toc.py in run(self, doc)
106 c.append(anchor)
107
--> 108 list_stack[-1].append(last_li)
109
110 class TocExtension(markdown.Extension):

IndexError: list index out of range

Many thanks.