How to link to part of the same document in Markdown?

前端 未结 14 1682
眼角桃花
眼角桃花 2020-11-29 14:50

I am writing a large Markdown document and would like to place a table of contents of sorts at the beginning that will provide links to various locations in the document. Ho

14条回答
  •  春和景丽
    2020-11-29 15:08

    Universal solutions

    This question seems to have a different answer according to the markdown implementation.
    In fact, the official Markdown documentation is silent on this topic.
    In such cases, and if you want a portable solution, you could use HTML.

    Before any header, or in the same header line, define an ID using some HTML tag.
    For example:
    You will see this in your code but not in the rendered document.

    Full example:

    See a full example (online and editable) here.

    ## Content
    
    * [Chapter 1](#Chapter1)
    * [Chapter 2](#Chapter2)
    
    
    ## Chapter 1 Some text here. Some text here. Some text here. ## Chapter 2 Some text here. Some text here. Some text here.

    To test this example, you must add some extra space between the content list and the first chapter or reduce the window height.
    Also, do not use spaces in the name of the ids.

提交回复
热议问题