Commits

Waylan Limberg committed 6c73564

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.

Comments (0)

Files changed (2)

 Steward Midwinter
 Jack Miller
 Neale Pickett
+Paul Stansifer
 John Szakmeister
 Malcolm Tredinnick
 Ben Wilson

markdown/extensions/footnotes.py

         """ 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):
                                   ">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. """
 
     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. """