From 1059143a90599670c379d338a35337c5917ebc93 Mon Sep 17 00:00:00 2001
From: Oh Jinkyun
Date: Sun, 5 Apr 2015 20:19:20 +0900
Subject: [PATCH] Reset footnotes after postprocessing
Signed-off-by: Oh Jinkyun
---
markdown/extensions/footnotes.py | 4 +++-
tests/test_extensions.py | 37 ++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py
index d8caae27c..5cb0331e3 100644
--- a/markdown/extensions/footnotes.py
+++ b/markdown/extensions/footnotes.py
@@ -311,7 +311,9 @@ def run(self, text):
text = text.replace(
FN_BACKLINK_TEXT, self.footnotes.getConfig("BACKLINK_TEXT")
)
- return text.replace(NBSP_PLACEHOLDER, " ")
+ result = text.replace(NBSP_PLACEHOLDER, " ")
+ self.footnotes.reset()
+ return result
def makeExtension(*args, **kwargs):
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index 38f0be3c9..9427c376d 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -858,3 +858,40 @@ def testCustomSubstitutions(self):
is the ‚mdash‘: \u2014
Must not be confused with ‚ndash‘ (\u2013) \u2026 ]
"""
self.assertEqual(self.md.convert(text), correct)
+
+
+class TestFootnotes(unittest.TestCase):
+ """ Test Footnotes extension. """
+
+ def setUp(self):
+ self.md = markdown.Markdown(extensions=['markdown.extensions.footnotes'])
+
+ def testSimpleFootnotes(self):
+ """ Test Footnotes. """
+ text = "Foo[^1] Bar\n[^1]: Baz"
+ self.assertEqual(
+ self.md.convert(text),
+ 'Foo Bar
\n'
+ ''
+ )
+
+ def testFootnotesReset(self):
+ """ Test whether FootnotesExtension got reset properly """
+ text1 = "Foo[^1] Bar\n[^1]: Baz"
+ text2 = "Foo"
+ self.md.convert(text1)
+ self.assertEqual(
+ self.md.convert(text2),
+ 'Foo
'
+ )