From 5ee12763465d123a313d43fc0fb497636f727d34 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Wed, 25 Aug 2010 11:06:17 -0400 Subject: Fixed Ticket 70 and added a test. Footnote references whithout a coresponding definition no longer raise an error. They now pass through as plain text - which is the same behavior as PHP Markdown Extra. Thanks for the report Benjamin Bach. --- markdown/extensions/footnotes.py | 17 ++++++++++------- tests/extensions/extra/footnote.html | 1 + tests/extensions/extra/footnote.txt | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index 2bdabe9..644e89f 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -261,14 +261,17 @@ class FootnotePattern(markdown.inlinepatterns.Pattern): self.footnotes = footnotes def handleMatch(self, m): - sup = etree.Element("sup") - a = etree.SubElement(sup, "a") id = m.group(2) - sup.set('id', self.footnotes.makeFootnoteRefId(id)) - a.set('href', '#' + self.footnotes.makeFootnoteId(id)) - a.set('rel', 'footnote') - a.text = str(self.footnotes.footnotes.index(id) + 1) - return sup + if id in self.footnotes.footnotes.keys(): + sup = etree.Element("sup") + a = etree.SubElement(sup, "a") + sup.set('id', self.footnotes.makeFootnoteRefId(id)) + a.set('href', '#' + self.footnotes.makeFootnoteId(id)) + a.set('rel', 'footnote') + a.text = unicode(self.footnotes.footnotes.index(id) + 1) + return sup + else: + return None class FootnoteTreeprocessor(markdown.treeprocessors.Treeprocessor): diff --git a/tests/extensions/extra/footnote.html b/tests/extensions/extra/footnote.html index 6556dab..d7d8b92 100644 --- a/tests/extensions/extra/footnote.html +++ b/tests/extensions/extra/footnote.html @@ -1,4 +1,5 @@

This is the body with a footnote1 or two2 or more3 4.

+

Also a reference that does not exist[^5].


    diff --git a/tests/extensions/extra/footnote.txt b/tests/extensions/extra/footnote.txt index 07188d0..9f89397 100644 --- a/tests/extensions/extra/footnote.txt +++ b/tests/extensions/extra/footnote.txt @@ -1,5 +1,7 @@ This is the body with a footnote[^1] or two[^2] or more[^3] [^4]. +Also a reference that does not exist[^5]. + [^1]: Footnote that ends with a list: * item 1 -- cgit v1.2.3