Footnotes in lists are numbered before other footnotes
goofpunk opened this issue · 3 comments
Describe the bug
If you include footnotes in a list (whether ordered or unordered), the footnotes that are in the list get numbered first, and are at the top of the list at the bottom of the HTML output.
To Reproduce
---
title: testing the footnotes bug
---
Lorem ipsum dolor sit amet. Aliqua cillum, eu velit.[^note1] Velit deserunt adipiscing adipiscing ullamco exercitation.
- this is a list item
- this is a list item[^note2]
- this is a list item[^note3]
Lorem ipsum dolor sit amet. Adipiscing[^note4] adipiscing ullamco, exercitation sint. Exercitation sint, fugiat exercitation voluptate amet.
[^note1]: this should be the first note
[^note2]: this should be the second note
[^note3]: this should be the third note
[^note4]: this should be the fourth note
Expected behavior
Notes should be in the order they were numbered. Instead, the results (in both the numbering and the list at the bottom) are:
- note2
- note4
- note1
- note3
Debug info
Version of library being used: 2.4.10
Any extras being used: reproducible with no extras other than footnotes
I noticed another, much more minor issue recently, that I think is related: if I mix regular HTML headings in with the Markdown, they don't get picked up in the table of contents. Are all of the extras being run before the main markdown conversion process? That could lead to both of these bugs.
Are all of the extras being run before the main markdown conversion process?
The table of contents extra is run when converting MD headers to HTML. I think most extras are run that way as well.
For this specific issue, I guess we could do basic parsing of the h[1-6]
tags, add them to the TOC and then sort by the line number, since h[1-6]
tags are block level.
Notes should be in the order they were numbered.
Could probably apply the same "sort in order of appearance" logic to this. Not sure if footnotes are considered "block level" so might have to secondary sort by column as well.
I'll look into both of these at some point
I've created a PR that fixes the main point of this issue, which is footnote ordering. Footnotes will now appear in the same order that they are defined. This behaviour is in line with what python-markdown does (couldn't find explicit docs but I tested it locally).
For the headers issue, I've spun it off into a separate issue (#537) and I'll try to look at it soon