I’d like to add the title attribute to footnotes to make the content accessible on hover.
I.e. at the moment
footnote.[^bla]
[bla]: I am the text of the footnote
Will give
<p>footnote.<sup id="fnref:1"><a href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup</p>
<li id="fn:1" role="doc-endnote">
<p>I am the text of the footnote <a href="#fnref:1" class="footnote-backref" role="doc-backlink">↩︎</a></p>
</li>
And I’d like to get
<p>footnote.<sup id="fnref:1"><a title="I am the text of the footnote" href="#fn:1" class="footnote-ref" role="doc-noteref">1</a></sup</p>
<li id="fn:1" role="doc-endnote">
<p>I am the text of the footnote <a href="#fnref:1" class="footnote-backref" role="doc-backlink">↩︎</a></p>
</li>
Ideally I’d like to not have to use a JS script. Now, I don’t know how to write a Goldmark extension, and if I found one, how would I use it in a website. I’m a bit stuck and would appreciate ideas.
Just to float my ideas and why I don’t think they work:
{{ .Content | replaceRE <some hardcore regex >}}: This is the approach taken by the initial implementation of what is now done with the render-headings render hook. Since .Content is already converted to HTML at that stage (I think), that would need some hardcore regexing from what I can tell, so that’s maybe not feasible. You would probably at least need to “loop” across footnotes, right?
Instead of writing [^footnote] and later [^footnote]: Some footnote text, one might use a custom shortcode {{< fn "Some footnote text" >}} that returns the desired structure with title= inline – but that would be uncomfortable to write, as it would have to be at the exact place where the footnote label is supposed to go. For longer footnotes, that’s even worse. And at that point I haven’t even figured out how to still add the footnote to the doc-endnote list at the bottom
Besides doing this in JS after the fact, I can’t think of any feasible solution that works either within the page itself (like a shortcode) or the template level (working with .Content somehow).
The more I think about it, the more I appreciate what littlefoot.js does for me – but then again, getting away without the extra JS would be nice. This feels like such a minor tweak (“just add the title= bit!”).
Maybe it’s worth asking on goldmark about the possibility of an alternative footnote format? I mean, this could be considered an accessibility feature, right? That would at least make it more attractive to consider than “It would be neat for arbitrary reasons”, but I’m starting to ramble.
I’m also curious about this. Reading the Goldmark README, I discover that it uses as a built-in extension PHP Markdown Extra: Footnotes, and this project has a configuration to do just what you’d like to (and I do to): https://michelf.ca/projects/php-markdown/configuration/#markdown-extra (search for fn_link_title = "").