wagtail-footnotes
wagtail-footnotes copied to clipboard
Allow multiple references to the same footnote
This is an attempt to fix #25
At present, this only ensures that each linked reference will have a unique HTML id so that the back links on the footnotes will work (by linking to the first reference). This does not yet include UI changes to expose links to each individual reference in the content but there is a proposed approach in https://github.com/torchbox/wagtail-footnotes/issues/25#issue-1149764004.
@jsma I know this is quite late, but would you be able to add a test or two for this?
Also, can you rebase on main. We switched to ruff for a bunch of linting and I suspect that may be introducing a conflict
I completely reworked my initial implementation which required some force pushes.
I don't know what planet I was on when I first did this but I fixed the <sup> to be inside the <a> rather than vice versa. This does introduce changes to the footnotes.html template, since that was the only way I could test that unique id attributes were generated (I opted to use plain 1-based index integers for each reference per this comment). I realize folks may be opinionated on this but at the end of the day, it's a template that can be overridden.
Sorry for any previous CI noise. I added Python 3.11 type hints out of habit, which didn't fail when I ran tox locally against all environments, I guess because it was running in a 3.11-based virtual environment (I'm not super familiar with tox, I maintain websites vs reusable packages so I'm only family with standard Django tests).
uff, this clashes a bit with #70 Could you rebase again @jsma then I can do a final test, re-review and merge in. Sorry it took so long
No worries. Per https://github.com/torchbox/wagtail-footnotes/pull/40#discussion_r1785617929 I started working on this a couple weeks back (unfortunately not a simple rebase). I'm up against several professional and personal deadlines at the moment but hope to finish it up later next week.
I've finally rebased this on main and incorporated the template-based rendering changes introduced in #70.
I reworked the implementation a bit to avoid the goofy template tag I relied on previously. It now patches the footnotes themselves before appending them to the page, so the footnote will have knowledge of how many times it has been referenced in the text above. I didn't have any bright ideas beyond just tracking 1-indexed integers so that at least footnote_reference.html and footnotes.html would agree on what the id on the reference is, and it would parallel how we're using an index to set the id for the footnote.