From 6b7ac10f49c31d438cf76650baa43f6c11338353 Mon Sep 17 00:00:00 2001 From: RavSinghChandan Date: Fri, 30 Oct 2026 22:15:37 +0530 Subject: [PATCH 1/2] Don't add an empty footnotes block when no footnote is referenced --- lib/markdown2.py | 3 ++- test/tm-cases/footnotes_unreferenced.opts | 1 + test/tm-cases/footnotes_unreferenced.text | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test/tm-cases/footnotes_unreferenced.opts create mode 100644 test/tm-cases/footnotes_unreferenced.text diff --git a/lib/markdown2.py b/lib/markdown2.py index 3632a54e..346a6345 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -2280,7 +2280,8 @@ def _form_paragraphs(self, text: str) -> str: return "\n\n".join(grafs) def _add_footnotes(self, text: str) -> str: - if self.footnotes: + # Only referenced footnotes are listed, so there is nothing to add without any reference + if self.footnote_ids: footer = [ '
', ' Date: Sat, 31 Oct 2026 07:04:28 +0530 Subject: [PATCH 2/2] Add a changelog entry --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index cee783ed..b37edbf6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) +- [pull #758] Fix `footnotes` extra adding an empty footnotes block when no footnote is referenced. - [pull #746] Preserve query strings and fragments in `markdown-file-links` conversions, including reference-link targets. - [pull #739] Fix `header-ids` extra putting sanitized HTML into header ids in safe mode, which allowed attribute injection (#649) - [pull #732] Fix excessive CPU use in the inline HTML tokenizer on repeated unclosed tag fragments (#707)