How to add footnotes to GitHub-flavoured Markdown?
Asked Answered
B

14

376

I am just trying to add footnotes in my GitHub Gist, but it doesn't work:

Some long sentence. [^footnote]

[^footnote]: Test, [Link](https://google.com).

I am following this guide and I don't think I'm doing anything wrong. Can someone point out my mistake?

Blain answered 30/8, 2014 at 7:1 Comment(15)
fletcher.github.io/peg-multimarkdown Note: Currently, the Github wiki software supports Markdown, but not MultiMarkdown Where is it documented that this is going to work?Ilka
@Ilka Ah, damn, so it wouldn't work? Is there any other way to do footnote in regular Markdown?Blain
@EnricoSusatyo Not in plain markdown, but for example Pandoc supports itCabby
Interestingly, GitLab's markdown does support the [^footnote] syntax, even before it got officially added to the documentationRafferty
@Rafferty you are referring to GitLab's footnote, not Github as the OP was asking.Shulock
@Devy, yes, that's why I said "GitLab's markdown". Could still be useful, given that GitLab's flavour implementation seems to be based on the GitHub flavour, and that in general Markdown, its flavours and its implementations are an unholy mess. Summary: "just in case try this too".Rafferty
@Rafferty the question is specially titled "Github-flavored" markdown.Shulock
@Shulock I found hmijail comment very useful. I actually need to use footnote for MD file in GitLab repository. This Q was returned from duckduckgo and the correct answer for me I got from his comment.Hako
As of 2020, the exact syntax of footnotes works. You won't need to browse the answers for workarounds.Breunig
@Breunig I don't think this is fully supported yet. Just tried while commenting on an issue. It does not show up in the preview.Appalachian
Can this question be considered a duplicate of meta.https://mcmap.net/q/88300/-best-xml-serialization-library-for-a-mfc-c-app?Manpower
I can not believe that Github is making using Markdown so hard.Lewellen
Footnotes are now supported (Sept. 2021): See my answer belowBiedermeier
Values of "Supported" may vary, @Biedermeier - for instance, I see the footnotes format working in .md file previews, but not in the github repository wiki feature.Chapen
@TomHillman Yes, as commented in my answer below: wiki are indeed not supported yet.Biedermeier
F
280

GitHub Flavored Markdown doesn't support footnotes, but you can manually fake it¹ with Unicode characters or superscript tags, e.g. <sup>1</sup>.

¹Of course this isn't ideal, as you are now responsible for maintaining the numbering of your footnotes. It works reasonably well if you only have one or two, though.

Fula answered 30/8, 2014 at 16:33 Comment(3)
Thanks, I also like how other sites have clickable footnote links, but I guess this might be the only way to do it in GitHub.Blain
You can also use regular numbers enclosed in square brackets[1], which is a pretty established convention for plaintext footnotes in my experience. (Gosh darnit why can’t I make line breaks in comments.) [1] I.e. like Pandoc Mandoc footnotes minus the caret.Cruck
Some flavors may restrict using HTML. In such a case, use characters from the Unicode superscript block: ⁰¹²³⁴⁵⁶⁷⁸⁹ (Chris already mentioned them, I just think they deserve more attention.)Garfield
W
428

Expanding a little bit on the previous answer, you can make the footnote links clickable here as well. First define the footnote at the bottom like this

<a name="myfootnote1">1</a>: Footnote content goes here

Then reference it at some other place in the document like this

<sup>[1](#myfootnote1)</sup>
Wintertime answered 1/4, 2015 at 6:29 Comment(5)
This is a nice middle-ground answer. It maintains clarify of intent without, IMO, too much bloat for formatting.Interlock
Using non-numeric references obviates the above-mentioned issue of maintaining sequential numeric references - Example [[TPL]](#TPL) ... #### Notes ... <a name="TPL">[TPL]</a> footnote templateIsocracy
Don't miss Part 2 in @Matteo's answer below. I was so chuffed with this answer (thanks) that i almost didn't bother to scroll down . . .Latialatices
This works well in GitLab Flavored Markdown (GFM) as well. Although there is a built-in option available, I wanted the footnote's text to be rendered at a custom location (end of Section) instead of at the end of the whole file (built-in option).Purgatory
GitHub supports this as per Sept. 2021: https://mcmap.net/q/87100/-how-to-add-footnotes-to-github-flavoured-markdownGadson
F
280

GitHub Flavored Markdown doesn't support footnotes, but you can manually fake it¹ with Unicode characters or superscript tags, e.g. <sup>1</sup>.

¹Of course this isn't ideal, as you are now responsible for maintaining the numbering of your footnotes. It works reasonably well if you only have one or two, though.

Fula answered 30/8, 2014 at 16:33 Comment(3)
Thanks, I also like how other sites have clickable footnote links, but I guess this might be the only way to do it in GitHub.Blain
You can also use regular numbers enclosed in square brackets[1], which is a pretty established convention for plaintext footnotes in my experience. (Gosh darnit why can’t I make line breaks in comments.) [1] I.e. like Pandoc Mandoc footnotes minus the caret.Cruck
Some flavors may restrict using HTML. In such a case, use characters from the Unicode superscript block: ⁰¹²³⁴⁵⁶⁷⁸⁹ (Chris already mentioned them, I just think they deserve more attention.)Garfield
R
244

Expanding on the previous answers even further, you can add an id attribute to your footnote's link:

Bla bla <sup id="a1">[1](#f1)</sup>

Then from within the footnote, link back to it.

<b id="f1">1</b> Footnote content here. [↩](#a1)

This will add a little at the end of your footnote's content, which takes your readers back to the line containing the footnote's link.

Rysler answered 20/8, 2015 at 13:37 Comment(6)
Adding a minor correction to @Matteo's response above, I had to use name instead of id in the call to the footnote. I.e. <p> Bla bla <sup name="a1">[1](#f1)</sup>Cagliostro
Thanks @oldfartdeveloper. It seems that both name and id work for README files on github.com.. haven't tested gists though.Rysler
For those who find this Q&A in circa 2020: This answer works on GitHub, PLUS it has the additional feature: return-to-the-footnote-link-you-clicked. I have found one minor caveat (explained here), but this is THE answer afaic.Dunstan
This also works on Azure DevOps Server (Version Dev18.M170.6). I ended up using a <span> instead of a <b>, but that is merely a style preference.Bonus
Supported as per Sept. 2021: https://mcmap.net/q/87100/-how-to-add-footnotes-to-github-flavoured-markdownGadson
But in any case, if you click to the refrence number, it is not leading to the in page citation.Kimberli
B
40

Sept. 2021: Footnotes are here!

(Dec. 2021, as commented below, wiki README.md does not yet support footnotes)

"Footnotes now supported in Markdown fields"

Footnotes let you reference relevant information without disrupting the flow of what you're trying to say:

Here is a simple footnote[^1]. With some additional text after it.

[^1]: My reference.

You can now use footnote syntax in any Markdown field!

Footnotes are displayed as superscript links. Click them to jump to their referenced information, displayed in a new section at the bottom of the document:

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpLS21bC2jaRA/user-images.githubusercontent.com/2503052/135463148-0231966e-8631-41a1-b1a7-66746100d20a.gif?ssl=1

Cf. Documentation.

Biedermeier answered 30/9, 2021 at 17:6 Comment(9)
This doesn't seem to work on GitHub wikis.Toile
@Toile Indeed. Hopefully, GitHub will extend the support of that syntax to wikis. For now, the syntax isn't even added to the GFM spec: github.github.com/gfmBiedermeier
it would be nice if the docs said which version of Github (enterprise/onprem) this was enabled. GitHub Enterprise Server 3.2.1 does not have it for instance, but the PR comment box links to a page that says "footnotes are supported"Slavey
@Slavey Indeed. Let me know when you see those supported in GHE.Biedermeier
It is not working actuallyKimberli
re: "For now, the syntax isn't even added to the GFM spec" – two years later, the spec is still at Version 0.29-gfm (2019-04-06). There's also an issue about it: "Published HTML version of specification is out of date with spec.txt".Hermia
@Hermia Thank you for this feedback. I will follow those issues 271 and 288.Biedermeier
footnotes work well! but not in markdown file headings i.e. # heading [^1] (followed by the footnote content) renders the [1] part in the markdown file heading as "full" text, not elevated with a <sup>. I opened an issue here.Stepchild
Unfortunately latex is not rendered in the footnotes.Connection
S
19

I wasn't able to get Surya's and Matteo's solutions to work. For example, "(#f1)" was just displayed as text, and didn't become a link. However, their solutions led me to slightly different solution. (I also formatted the footnote and the link back to the original superscript a bit differently.)

In the body of the text:

Yadda yadda<a href="#note1" id="note1ref"><sup>1</sup></a>

At the end of the document:

<a id="note1" href="#note1ref"><sup>1</sup></a>Here is the footnote text.

Clicking on the superscript in the footnote returns to the superscript in the original text.

Schematize answered 4/3, 2017 at 18:5 Comment(3)
Interesting. You've used HTML where @Rysler used GFM. I was able to get his solution to work, but it required a bit of fiddling. Do you think this is a quirk in GitHub's rendering engine?Dunstan
I have no idea, @Seamus. As I recall, there was a bit of trial and error when I was trying to figure it out.Schematize
It's a clever solution. And yeah - that's still where we are today - trial and error :)Dunstan
S
15

Although I am not aware if it's officially documented anywhere, you can do footer notes in Github.

  1. Mark the place where you want to insert footer link with a number enclosed in square brackets, I.E. [1]

  2. On the bottom of the post, make a reference of the numbered marker and followed by a colon and the link, I.E. [1]: http://www.example.com/link1

And once you preview it, it will be rendered as numbered links in the body of the post.

Shulock answered 23/8, 2016 at 21:13 Comment(5)
This doesn't generate a list of links at the end of your document though. Like on Wikipedia pages.Laurielaurier
should there be a colon after the square brackets?Nasopharynx
This is not a footnote, this is a link.Creature
step #1 didn't work as a link on github markdown (Dec 2018).Surrender
@DavidMoles I stumbled upon this SO post because I was looking for a way to include reference links as footnotes. So for those who google like me, this is the right answer even though it is the wrong question. 😜Niemeyer
G
14

This works for me:

blablabla [<sup>1</sup>](#1) blablabla

footnotes: reference to blablabla <a class="anchor" id="1"></a>

Gymno answered 9/10, 2018 at 23:34 Comment(0)
T
13

For short notes, providing an anchor element with a title attribute creates a "tooltip".

<a title="Note text goes here."><sup>n</sup></a>

Otherwise, for more involved notes, it looks like your best bet is maintaining named links manually.

Terbia answered 10/11, 2016 at 17:25 Comment(1)
This did not work in a GitHub Enterprise 2.8 markdown pageDeoxidize
S
10

Here's a variation of Eli Holmes' answer that worked for me without using latex:

Text<span id="a1">[¹](#1)</span>

<span id="1">¹</span> Footnote.[⏎](#a1)<br>

Example

Spencerianism answered 17/4, 2020 at 12:43 Comment(0)
B
8

I used a variant of Mateo's solution. I'm using this in Rmd files written in github flavored markdown (gfm) for a Jekyll powered website but the same Rmd files are being used to produce pdfs in various contexts. The Rmd files are math heavy and the math is displayed with MathJax on the website. So I needed a solution that works with gfm that is processed via Jekyll, works with pandoc->pdflatex, and is compatible with MathJax.

snippet from Rmd file (which is gfm)

Here is a paragraph with an footnote <span id="a1">[[1]](#f1)</span>.

Footnotes
=========

1. <span id="f1"></span> This is a footnote. [$\hookleftarrow$](#a1)

$\hookleftarrow$ is latex, which works for me since I always have MathJax enabled. I use that to make sure it shows up correctly in my pdfs. I put my footnotes in square brackets because superscript is confusing if I am putting a footnote on some inline math.

Here it is in action: https://eeholmes.github.io/posts/2016-5-18-FI-recursion-1/

These notes can be put anywhere in the Rmd. I am putting in a list at the end so they are technically endnotes.

Belgae answered 15/12, 2017 at 19:51 Comment(1)
Mildly tangential to the OP's question but ultimately I really like your "solution that works with gfm that is processed via Jekyll, works with pandoc->pdflatex, and is compatible with MathJax". Neat example.Monoplegia
E
8

Although the question is about GitHub flavored Markdown, I think it's worth mentioning that as of 2013, GitHub supports AsciiDoc which has this feature builtin. You only need to rename your file with a .adoc extension and use:

A statement.footnote:[Clarification about this statement.]

A bold statement!footnote:disclaimer[Opinions are my own.]

Another bold statement.footnote:disclaimer[]

Documentation along with the final result is here.

Enugu answered 27/4, 2020 at 9:33 Comment(0)
C
1

Unfortunately the footnotes as supported by github (see this answer) don't support rendering of latex, see https://github.com/orgs/community/discussions/55227 .

My way of adding footnotes to a document therefor is

This is the first sentence. <sup id="a1">[1](#f1)</sup>

This is a second sentence. <sup id="a2">[2](#f2)</sup>

---

#### Footnotes
> <sup id="f1">1</sup> Pythagoras theorem $a^2+b^2=c^2$ [⏎](#a1)

> <sup id="f2">2</sup> See [De_Gua's_theorem](https://en.wikipedia.org/wiki/De_Gua's_theorem) [⏎](#a2)

The advantage of formatting footnotes as quotes using > is that this will render them in a grey instead of black to better distinguish them from the main text.

Connection answered 14/11, 2023 at 13:42 Comment(1)
Good workaround. Upvoted.Biedermeier
W
0

This one works on Kaggle notebook markdown:

Tell the story here.[<sup>[1]</sup>](#f1)

<span id="f1">[1]</span> Detail reference here.
Wilfredowilfrid answered 25/10, 2021 at 13:16 Comment(0)
A
0

I was looking for the same and I came up with the following, which is a footnote and opens the link in an external tab.

myfootnote^[Please see at: <a href="copylink" 
target="_blank">copylink</a> ]
Aegaeon answered 23/1, 2022 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.