diff --git a/CHANGES.md b/CHANGES.md index 90f815ec..64bdc16a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) +- [pull #745] Fix `footnotes` extra listing notes in definition order, so a note's position in the list didn't match its number in the text (#178) - [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) - [pull #736] Clarify how to enable file variables in the Python API and command-line help (#269, #365). diff --git a/lib/markdown2.py b/lib/markdown2.py index 66d49a69..f052314b 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -2272,10 +2272,8 @@ def _add_footnotes(self, text: str) -> str: if not self.footnote_return_symbol: self.footnote_return_symbol = "↩" - # self.footnotes is generated in _strip_footnote_definitions, which runs re.sub on the whole - # text. This means that the dict keys are inserted in order of appearance. Use the dict to - # sort footnote ids by that same order - self.footnote_ids.sort(key=lambda a: list(self.footnotes.keys()).index(a)) + # self.footnote_ids is filled by _do_footnote_marker in the order the references are + # numbered, so listing the notes in that order keeps each note at its number for i, id in enumerate(self.footnote_ids): if i != 0: footer.append('') diff --git a/test/tm-cases/footnotes_defined_out_of_order.html b/test/tm-cases/footnotes_defined_out_of_order.html new file mode 100644 index 00000000..480ee16d --- /dev/null +++ b/test/tm-cases/footnotes_defined_out_of_order.html @@ -0,0 +1,22 @@ +
The first reference1 and the second2.
+ +++ +A quoted reference3.
+