aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2009-07-21 21:56:19 -0400
committerWaylan Limberg <waylan@gmail.com>2009-07-21 21:56:19 -0400
commite719047b9b9514977e766f1aed932c1d11dfccaf (patch)
treef1c9509df75d620d5d9a6a5dd983d96708dcd510
parent383916493d8d05feb8df72e61cbec15d9b5fb937 (diff)
downloadmarkdown-e719047b9b9514977e766f1aed932c1d11dfccaf.tar.gz
markdown-e719047b9b9514977e766f1aed932c1d11dfccaf.tar.bz2
markdown-e719047b9b9514977e766f1aed932c1d11dfccaf.zip
Fixed Ticket 37. When multiple markdown documents are displayed on one page and
contain footnotes with the same name, they will no longer collide when 'UNIQUE_IDS' is set to True. Thanks to Paul Stansifer for report and patch.
-rw-r--r--docs/AUTHORS1
-rw-r--r--markdown/extensions/footnotes.py24
2 files changed, 20 insertions, 5 deletions
diff --git a/docs/AUTHORS b/docs/AUTHORS
index cfe2b34..2843b56 100644
--- a/docs/AUTHORS
+++ b/docs/AUTHORS
@@ -37,6 +37,7 @@ Daniel Krech
Steward Midwinter
Jack Miller
Neale Pickett
+Paul Stansifer
John Szakmeister
Malcolm Tredinnick
Ben Wilson
diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py
index 6dacab7..e1a9cda 100644
--- a/markdown/extensions/footnotes.py
+++ b/markdown/extensions/footnotes.py
@@ -38,11 +38,18 @@ class FootnoteExtension(markdown.Extension):
""" Setup configs. """
self.config = {'PLACE_MARKER':
["///Footnotes Go Here///",
- "The text string that marks where the footnotes go"]}
+ "The text string that marks where the footnotes go"],
+ 'UNIQUE_IDS':
+ [False,
+ "Avoid name collisions across "
+ "multiple calls to reset()."]}
for key, value in configs:
self.config[key][0] = value
-
+
+ # In multiple invocations, emit links that don't get tangled.
+ self.unique_prefix = 0
+
self.reset()
def extendMarkdown(self, md, md_globals):
@@ -66,8 +73,9 @@ class FootnoteExtension(markdown.Extension):
">amp_substitute")
def reset(self):
- """ Clear the footnotes on reset. """
+ """ Clear the footnotes on reset, and prepare for a distinct document. """
self.footnotes = markdown.odict.OrderedDict()
+ self.unique_prefix += 1
def findFootnotesPlaceholder(self, root):
""" Return ElementTree Element that contains Footnote placeholder. """
@@ -91,11 +99,17 @@ class FootnoteExtension(markdown.Extension):
def makeFootnoteId(self, id):
""" Return footnote link id. """
- return 'fn:%s' % id
+ if self.getConfig("UNIQUE_IDS"):
+ return 'fn:%d-%s' % (self.unique_prefix, id)
+ else:
+ return 'fn:%s' % id
def makeFootnoteRefId(self, id):
""" Return footnote back-link id. """
- return 'fnref:%s' % id
+ if self.getConfig("UNIQUE_IDS"):
+ return 'fnref:%d-%s' % (self.unique_prefix, id)
+ else:
+ return 'fnref:%s' % id
def makeFootnotesDiv(self, root):
""" Return div of footnotes as et Element. """