Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions markdown/extensions/footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
10 changes: 4 additions & 6 deletions tests/extensions/extra/footnote.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
<p>Footnote that ends with a list:</p>
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 2&#160;<a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></li>
</ul>
<p><a class="footnote-backref" href="#fnref:1" rev="footnote" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
<li id="fn:2">
<blockquote>
<p>This footnote is a blockquote.</p>
<p>This footnote is a blockquote.&#160;<a class="footnote-backref" href="#fnref:2" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</blockquote>
<p><a class="footnote-backref" href="#fnref:2" rev="footnote" title="Jump back to footnote 2 in the text">&#8617;</a></p>
</li>
<li id="fn:3">
<p>A simple oneliner.&#160;<a class="footnote-backref" href="#fnref:3" rev="footnote" title="Jump back to footnote 3 in the text">&#8617;</a></p>
Expand All @@ -26,8 +24,8 @@
</li>
<li id="fn:5">
<p>First line of first paragraph.
Second line of first paragraph is not intended.
Second line of first paragraph is not indented.
Nor is third...&#160;<a class="footnote-backref" href="#fnref:5" rev="footnote" title="Jump back to footnote 5 in the text">&#8617;</a></p>
</li>
</ol>
</div>
</div>
2 changes: 1 addition & 1 deletion tests/extensions/extra/footnote.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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...