diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py index d8caae27c..80d09d8da 100644 --- a/markdown/extensions/footnotes.py +++ b/markdown/extensions/footnotes.py @@ -153,14 +153,17 @@ def makeFootnotesDiv(self, root): ) backlink.text = FN_BACKLINK_TEXT - if li.getchildren(): - node = li[-1] - if node.tag == "p": - node.text = node.text + NBSP_PLACEHOLDER - node.append(backlink) - else: - p = etree.SubElement(li, "p") - p.append(backlink) + #appending backlink to the lowermost element + #of last tag in footnote + elem = li + while True: + children = elem.getchildren(); + if len(children) == 0: + break; + elem = children[-1] + + elem.text += NBSP_PLACEHOLDER + elem.append(backlink) return div diff --git a/tests/extensions/extra/footnote.html b/tests/extensions/extra/footnote.html index e5b41a729..dfe6dfb5a 100644 --- a/tests/extensions/extra/footnote.html +++ b/tests/extensions/extra/footnote.html @@ -7,15 +7,13 @@

Footnote that ends with a list:

-

  • -

    This footnote is a blockquote.

    +

    This footnote is a blockquote. 

    -

  • A simple oneliner. 

    @@ -26,8 +24,8 @@
  • First line of first paragraph. -Second line of first paragraph is not intended. +Second line of first paragraph is not indented. Nor is third... 

  • - \ No newline at end of file + diff --git a/tests/extensions/extra/footnote.txt b/tests/extensions/extra/footnote.txt index c5c1c92b4..77bd8b46e 100644 --- a/tests/extensions/extra/footnote.txt +++ b/tests/extensions/extra/footnote.txt @@ -16,5 +16,5 @@ Also a reference that does not exist[^6]. Paragraph two. [^5]: First line of first paragraph. -Second line of first paragraph is not intended. +Second line of first paragraph is not indented. Nor is third...