How to add footnotes to GitHub-flavoured Markdown?

前端 未结 10 1022
夕颜
夕颜 2021-01-29 17:21

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).


        
相关标签:
10条回答
  • 2021-01-29 17:51

    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.

    0 讨论(0)
  • 2021-01-29 17:53

    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.

    0 讨论(0)
  • 2021-01-29 17:56

    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.

    0 讨论(0)
  • 2021-01-29 17:56

    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.

    0 讨论(0)
  • 2021-01-29 17:59

    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.

    0 讨论(0)
  • 2021-01-29 17:59

    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.

    0 讨论(0)
提交回复
热议问题