From 9b6220486d7591c3204c82edff4376bfe40fdc19 Mon Sep 17 00:00:00 2001
From: Hsiaoming Yang
Date: Tue, 23 Dec 2025 16:43:33 +0900
Subject: [PATCH] fix: render correct html for footnotes
https://github.com/lepture/mistune/issues/428
---
src/mistune/plugins/footnotes.py | 6 +++++-
tests/fixtures/footnotes.txt | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/mistune/plugins/footnotes.py b/src/mistune/plugins/footnotes.py
index e426865..a41dc11 100644
--- a/src/mistune/plugins/footnotes.py
+++ b/src/mistune/plugins/footnotes.py
@@ -108,7 +108,11 @@ def render_footnotes(renderer: "BaseRenderer", text: str) -> str:
def render_footnote_item(renderer: "BaseRenderer", text: str, key: str, index: int) -> str:
i = str(index)
back = ''
- text = text.rstrip()[:-4] + back + "
"
+ text = text.rstrip()
+ if text.endswith(""):
+ text = text[:-4] + back + ""
+ else:
+ text = text + "\n" + back
return '' + text + "\n"
diff --git a/tests/fixtures/footnotes.txt b/tests/fixtures/footnotes.txt
index aa85d5c..55175e5 100644
--- a/tests/fixtures/footnotes.txt
+++ b/tests/fixtures/footnotes.txt
@@ -96,6 +96,8 @@ third
````````````````````````````````
+https://github.com/lepture/mistune/issues/378
+
```````````````````````````````` example
This is a foo [^foo].
@@ -115,6 +117,8 @@ This is a bar [^bar].
````````````````````````````````
+https://github.com/lepture/mistune/issues/378
+
```````````````````````````````` example
This is body text, and a footnote.[^f]
@@ -129,3 +133,22 @@ This is body text, and a footnote.[^f]
````````````````````````````````
+
+https://github.com/lepture/mistune/issues/428
+
+```````````````````````````````` example
+paragraph [^fn]
+[^fn]: *emph*
+ > aaa
+.
+paragraph
+
+````````````````````````````````