aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/extensions/footnotes.py17
-rw-r--r--tests/extensions/extra/footnote.html1
-rw-r--r--tests/extensions/extra/footnote.txt2
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 @@
<p>This is the body with a footnote<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> or two<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> or more<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup> <sup id="fnref:4"><a href="#fn:4" rel="footnote">4</a></sup>.</p>
+<p>Also a reference that does not exist[^5].</p>
<div class="footnote">
<hr />
<ol>
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