zola icon indicating copy to clipboard operation
zola copied to clipboard

GitHub-Style Footnotes

Open DerDrodt opened this issue 1 year ago • 21 comments

This PR adds the option of rendering footnotes at the bottoms in GitHub-Style, based on the implementation of notriddle.

Closes #1285.

For instance, the following markdown

### Footnotes

Footnote 1 link[^first].

Footnote 2 link[^second].

Duplicated footnote reference[^second].

[^first]: Footnote **can have markup**.

[^second]: Footnote text.

Gets rendered to:

<h3 id="footnotes">Footnotes</h3>
<p>Footnote 1 link<sup class="footnote-reference" id="fr-first-1"><a href="#fn-first">[1]</a></sup>.</p>
<p>Footnote 2 link<sup class="footnote-reference" id="fr-second-1"><a href="#fn-second">[2]</a></sup>.</p>
<p>Duplicated footnote reference<sup class="footnote-reference" id="fr-second-2"><a href="#fn-second">[2]</a></sup>.</p>
<hr><ol class="footnotes-list"><li id="fn-first" class="footnote-definition">
<p>Footnote <strong>can have markup</strong>. <a href="#fr-first-1">↩</a></p>
</li>
<li id="fn-second" class="footnote-definition">
<p>Footnote text. <a href="#fr-second-1">↩</a> <a href="#fr-second-2">↩2</a></p>
</li>
</ol>

This style is disabled by default and can be turned off via the markdown.bottom_footnotes option in the config.toml.

DerDrodt avatar Oct 10 '23 06:10 DerDrodt

Can you clean up the commit history?

Keats avatar Oct 10 '23 20:10 Keats

Can you clean up the commit history?

Took some work but it's done. To make this easier for other contributors, you could merge the master branch into next.

DerDrodt avatar Oct 11 '23 07:10 DerDrodt

I don't know, if this is out of scope for this change, but currently footnotes are generated like this:

<div class="footnote-definition" id="bar"><sup class="footnote-definition-label">1</sup>
  <p>baz</p>
</div>
<div class="footnote-definition" id="baz"><sup class="footnote-definition-label">2</sup>
  <p>lul</p>
</div>

I would like to render successive footnotes in a box, which is currently not possible. Is it possible to change the generated HTML to wrap successive footnotes inside a div with a CSS class to allow styling around a list of footnotes?

<div class="footnotes-list">
  <div class="footnote-definition" id="bar"><sup class="footnote-definition-label">1</sup>
    <p>baz</p>
  </div>
  <div class="footnote-definition" id="baz"><sup class="footnote-definition-label">2</sup>
    <p>lul</p>
  </div>
</div>

That way, the footnotes-list class can be used to draw a box around any list of footnotes.

vbrandl avatar Oct 19 '23 10:10 vbrandl

That way, the footnotes-list class can be used to draw a box around any list of footnotes.

I'm not a 100% sure, I understand you correctly, but all footnotes in this new style are wrapped in an <ol>. You can set a border on this and have your box.

Drodt avatar Oct 19 '23 11:10 Drodt

I'm asking, if the old style of generating footnotes could be changed to wrap the footnotes in a div with class footnotes-list

vbrandl avatar Oct 19 '23 12:10 vbrandl

I'm asking, if the old style of generating footnotes could be changed to wrap the footnotes in a div with class footnotes-list

For that you should open a new Issue imo.

Drodt avatar Oct 19 '23 12:10 Drodt

Ok, so it's out of scope, as expexted. I'll look into this.

Another question: shouldn't the Github style footnotes use the same CSS class names as the old footnotes?

vbrandl avatar Oct 19 '23 12:10 vbrandl

Another question: shouldn't the Github style footnotes use the same CSS class names as the old footnotes?

Probably? If it makes sense

Keats avatar Oct 23 '23 20:10 Keats

Another question: shouldn't the Github style footnotes use the same CSS class names as the old footnotes?

I could do that, of course, but I don't think that's the best approach. As far as I can tell, quite a few markdown tools use the GitHub style with these classes. In my opinion, we should follow this more standard approach.

Drodt avatar Oct 24 '23 06:10 Drodt

quite a few markdown tools use the GitHub style with these classes

do you have examples?

Keats avatar Oct 26 '23 16:10 Keats

Ah, sorry. I was thinking about a different thing and mixed up the classes you were referring to. I have now added the footnote-definition class.

DerDrodt avatar Oct 27 '23 10:10 DerDrodt

I also noticed that pulldown-cmark has added support for GitHub-style footnotes (raphlinus/pulldown-cmark#654). So the code changed by this feature can be removed if and when pulldown-cmark publishes a new release.

(The feature was added in June to the repository, the last version was published in May. It may take a while.)

DerDrodt avatar Oct 27 '23 14:10 DerDrodt

Oh let's wait for that then if you don't mind, we would switch to it at the next release of pulldown-cmark anyway

Keats avatar Oct 28 '23 12:10 Keats

Just a note that it looks like the upstream PR was merged.

I would be very interested in having generated footnotes that use ol instead of div elements.

aterenin avatar Nov 27 '23 21:11 aterenin

Curious to know if this would be merged soon?

nikhilweee avatar Jan 27 '24 04:01 nikhilweee

No, we'll update the library to add support when it's released

Keats avatar Jan 27 '24 21:01 Keats

FYI, it seems that there are now new releases available: https://github.com/raphlinus/pulldown-cmark/releases/tag/v0.9.6.

dkales avatar Jan 29 '24 14:01 dkales

Unfortunately those releases don't include https://github.com/raphlinus/pulldown-cmark/pull/654 yet.

si14 avatar Jan 30 '24 11:01 si14

https://github.com/raphlinus/pulldown-cmark/releases/tag/v0.10.0 is now out and it has the relevant footnote issue included

kytta avatar Feb 06 '24 11:02 kytta

Sweet! That's a long list of changes, anyone interested in doing a PR? I think there are quite a few changes to make to the current parser

Keats avatar Feb 06 '24 11:02 Keats

@Keats I've just sent https://github.com/getzola/zola/pull/2432 to update to the new pulldown_cmark v0.10.0 version, since I had already had most of the necessary changes ready in my personal fork.

timonvo avatar Feb 06 '24 16:02 timonvo

With https://github.com/getzola/zola/pull/2432 merged, can this move forward?

WaffleLapkin avatar Mar 03 '24 00:03 WaffleLapkin

It should probably on its own PR, with an option in the config.toml that will enable the pulldown-cmark flag. Closing this PR as it's now outdated

Keats avatar Mar 03 '24 14:03 Keats

Is someone in the thread willing to make a new version of this PR?

WaffleLapkin avatar Mar 04 '24 15:03 WaffleLapkin

I've started working on it, you can assign me to #1285.

totikom avatar Apr 20 '24 20:04 totikom