diff --git a/CHANGES.md b/CHANGES.md index afb0be54..a82fa459 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) diff --git a/lib/markdown2.py b/lib/markdown2.py index e35bf5d2..d08b2e5f 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 = [ '
', 'This paragraph has no footnote marker.

diff --git a/test/tm-cases/footnotes_unreferenced.opts b/test/tm-cases/footnotes_unreferenced.opts new file mode 100644 index 00000000..9dfee9e2 --- /dev/null +++ b/test/tm-cases/footnotes_unreferenced.opts @@ -0,0 +1 @@ +{"extras": ["footnotes"]} diff --git a/test/tm-cases/footnotes_unreferenced.text b/test/tm-cases/footnotes_unreferenced.text new file mode 100644 index 00000000..ae7962e9 --- /dev/null +++ b/test/tm-cases/footnotes_unreferenced.text @@ -0,0 +1,3 @@ +This paragraph has no footnote marker. + +[^1]: A footnote that is never referenced.