-
Notifications
You must be signed in to change notification settings - Fork 957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdown footnotes enhancement #1285
Comments
If that's implemented, that should be a site-wide option in the config.toml |
Looks like this is something that others asked about here: pulldown-cmark/pulldown-cmark#142 Would you like me to leave this issue open? |
Let's leave it open for now and see if there is progress on the pulldown-cmark issue |
Related #1070 |
In the meantime, I implemented this on my side with some JavaScript: <script type="text/javascript">
window.addEventListener('load', function() {
for (const ref of document.getElementsByClassName('footnote-reference')) {
const hash = ref.children[0].hash.substring(1);
const refhash = 'ref:' + hash;
ref.id = refhash;
}
for (const footnote of document.getElementsByClassName('footnote-definition')) {
const hash = footnote.id;
const refhash = 'ref:' + hash;
const backlink = document.createElement('a');
backlink.href = '#' + refhash;
backlink.className = 'footnote-backlink';
backlink.innerText = '↩';
const paras = footnote.children;
const lastPara = paras[paras.length - 1];
lastPara.appendChild(backlink);
}
});
</script> |
* Added JavaScript written by @NieDzejkob from Zola issue getzola/zola/issues/1285 * Changed styling for footnotes * Updated index template to include site.js
copypasta from github.com/getzola/zola/issues/1285 Signed-off-by: Gunwant Jain <mail@wantguns.dev>
@meithecatte Thanks for the script, it's very helpful! For information, I've replaced the line with the link back to the reference as below to avoid confusion when there are several references to the same footnote (the arrow only sends back to the 1st reference). backlink.href = 'javascript:if (window.location.href.endsWith("#' + hash + '")) history.back()'; That way, the arrow will send back to where the reader came from, and only if it comes from that reference. The drawback is that it's not possible to tell where the footnotes are referenced by scrolling down and using the added arrows, but I don't think people often do that. Another solution would be to add several arrows but I find this confusing. The whole script becomes (with an option in comment): <script type="text/javascript">
window.addEventListener('load', function () {
for (const ref of document.getElementsByClassName('footnote-reference')) {
const hash = ref.children[0].hash.substring(1);
const refhash = 'ref:' + hash;
ref.id = refhash;
}
for (const footnote of document.getElementsByClassName('footnote-definition')) {
const hash = footnote.id;
const refhash = 'ref:' + hash;
const backlink = document.createElement('a');
backlink.href = 'javascript:if (window.location.href.endsWith("#' + hash + '")) history.back()';
// To get back by clicking any arrow, use this instead:
// backlink.href = 'javascript:if (window.location.href.search("#") >= 0) history.back()';
backlink.className = 'footnote-backlink';
backlink.innerText = '↩';
const paras = footnote.children;
const lastPara = paras[paras.length - 1];
lastPara.appendChild(backlink);
}
});
</script> |
I believe this is now unblocked after pulldown-cmark/pulldown-cmark#654 got merged, example: https://github.com/raphlinus/pulldown-cmark/blob/master/examples/footnote-rewrite.rs |
This issue would be closed by #2326. |
Can people try #2480 ? |
* Implemented bottom footnotes with backreferences Fixes #1285 * Added bottom_footnotes option to configuration.md * Renamed fix_github_style_footnotes() * Added tests for convert_footnotes_to_github_style() * Changed test to plain html instead of Vec<Event> * Added integration test for footnotes * Applied suggested changes
Works great for me, thanks! |
The PR is exactly what I was looking for, thank you! What do you think of giving backref links a class, to help style them? |
I've considered it, but it sounds like a separate big feature, that needs to be designed in the first place. If this feature is desired, let's create a separate issue and discuss it. |
Oh, I didn't have any specific wish other than a named CSS class in the new rendered html. I worked around the need with a Another less-than-ideal thing: the |
* Implemented bottom footnotes with backreferences Fixes getzola#1285 * Added bottom_footnotes option to configuration.md * Renamed fix_github_style_footnotes() * Added tests for convert_footnotes_to_github_style() * Changed test to plain html instead of Vec<Event> * Added integration test for footnotes * Applied suggested changes
* Implemented bottom footnotes with backreferences Fixes getzola#1285 * Added bottom_footnotes option to configuration.md * Renamed fix_github_style_footnotes() * Added tests for convert_footnotes_to_github_style() * Changed test to plain html instead of Vec<Event> * Added integration test for footnotes * Applied suggested changes
Enhancement
Environment
Zola version: 0.12.2 compiled from git
Have footnotes link back to where they were footnoted
It would be great if there was a way to have a link-back to the location of the footnote. So if the site visitor is reading an article, they can click the footnote and then click the little return icon to go back to where the footnote was declared.
The text was updated successfully, but these errors were encountered: