diff options
-rw-r--r-- | markdown/extensions/footnotes.py | 16 | ||||
-rwxr-xr-x | setup.py | 7 | ||||
-rw-r--r-- | tests/extensions/extra/footnote_placeholder.html | 10 | ||||
-rw-r--r-- | tests/extensions/extra/footnote_placeholder.txt | 5 |
4 files changed, 26 insertions, 12 deletions
diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index f9e5101..2bdabe9 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -84,10 +84,10 @@ class FootnoteExtension(markdown.Extension): for child in element: if child.text: if child.text.find(self.getConfig("PLACE_MARKER")) > -1: - return child, True + return child, element, True if child.tail: if child.tail.find(self.getConfig("PLACE_MARKER")) > -1: - return (child, element), False + return child, element, False finder(child) return None @@ -282,16 +282,14 @@ class FootnoteTreeprocessor(markdown.treeprocessors.Treeprocessor): if footnotesDiv: result = self.footnotes.findFootnotesPlaceholder(root) if result: - node, isText = result + child, parent, isText = result + ind = parent.getchildren().index(child) if isText: - node.text = None - node.getchildren().insert(0, footnotesDiv) + parent.remove(child) + parent.insert(ind, footnotesDiv) else: - child, element = node - ind = element.getchildren().find(child) - element.getchildren().insert(ind + 1, footnotesDiv) + parent.insert(ind + 1, footnotesDiv) child.tail = None - fnPlaceholder.parent.replaceChild(fnPlaceholder, footnotesDiv) else: root.append(footnotesDiv) @@ -36,9 +36,10 @@ class md_install_scripts(install_scripts): f = file(bat_path, 'w') f.write(bat_str) f.close() - print 'Created:', bat_path - except Exception, e: - print 'ERROR: Unable to create %s: %s' % (bat_path, e) + print ('Created: %s' % bat_path) + except Exception: + _, err, _ = sys.exc_info() # for both 2.x & 3.x compatability + print ('ERROR: Unable to create %s: %s' % (bat_path, err)) class build_docs(Command): diff --git a/tests/extensions/extra/footnote_placeholder.html b/tests/extensions/extra/footnote_placeholder.html new file mode 100644 index 0000000..7aaf4b2 --- /dev/null +++ b/tests/extensions/extra/footnote_placeholder.html @@ -0,0 +1,10 @@ +<div class="footnote"> +<hr /> +<ol> +<li id="fn:1"> +<p>A Footnote. + <a href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">↩</a></p> +</li> +</ol> +</div> +<p>Some text with a footnote<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>.</p>
\ No newline at end of file diff --git a/tests/extensions/extra/footnote_placeholder.txt b/tests/extensions/extra/footnote_placeholder.txt new file mode 100644 index 0000000..0b0af42 --- /dev/null +++ b/tests/extensions/extra/footnote_placeholder.txt @@ -0,0 +1,5 @@ +///Footnotes Go Here/// + +Some text with a footnote[^1]. + +[^1]: A Footnote. |