Footnotes don't allow footnote references in the text
This is a foo [^foo].
This is a bar [^bar].
[^foo]: A foo is beautiful. This is in contrast to a bar [^bar].
[^bar]: A bar is very common.
Is rendered as
- A foo is beautiful. This is in contrast to a bar [^bar].
- A bar is very common.
It looks to me as if URLs in a footnote are not rendered either:
This is body text, and a footnote.[^f]
[^f]: The footnote includes [a link][1].
[1]: https://example.com
Renders as:
This is body text, and a footnote.¹
1. The footnote includes [a link][1]. ↩
Inline URLs work fine (e.g., [a link](https://example.com) renders correctly in the footnote).
A few datapoints on the link issue (reported by @dajare above):
- only references
[link][ref]are broken, normal links[link](url)seem to work fine; this may indicate that relevant document state doesn't get passed down when the footnote text is parsed - this worked in v2 (so I guess it's a regression)
At a first glance the place to fix this would be in parse_footnote_item, will report back if I figure it out.
Update: ~~yup, in v2 the existing state is used when parsing the footnote text, whereas in v3 a fresh state is used (also, the footnote text is block.parse_text()ed only if it's longer than one line)~~ NVM, that doesn't seem to be it, I think references are resolved later, perhaps in md_footnotes_hook.
Update no. 2: passing the parent state in md_footnotes_hook here seems to fix it: state = BlockState(parent=state).
@lemon24 Please review https://github.com/lepture/mistune/pull/425
@lepture LGTM (and it seems to have fixed the original footnote ref issue too 😁). Thank you!