GitHub relative link in Markdown file

前端 未结 11 1410
孤独总比滥情好
孤独总比滥情好 2020-11-29 14:40
相关标签:
11条回答
  • 2020-11-29 14:47

    You can link to file, but not to folders, and keep in mind that, Github will add /blob/master/ before your relative link(and folders lacks that part so they cannot be linked, neither with HTML <a> tags or Markdown link).

    So, if we have a file in myrepo/src/Test.java, it will have a url like:

    https://github.com/WesternGun/myrepo/blob/master/src/Test.java
    

    And to link it in the readme file, we can use:

    [This is a link](src/Test.java)
    

    or: <a href="src/Test.java">This is a link</a>.

    (I guess, master represents the master branch and it differs when the file is in another branch.)

    0 讨论(0)
  • 2020-11-29 14:47

    I am not sure if I see this option here. You can just create a /folder in your repository and use it directly:

    [a relative link](/folder/myrelativefile.md)
    

    No blob or tree or repository name is needed, and it works like a charm.

    0 讨论(0)
  • 2020-11-29 14:47

    Just follow the format below.

    [TEXT TO SHOW](actual URL to navigate)
    
    0 讨论(0)
  • 2020-11-29 14:51

    Update 30th, January 2013, 16 months later:

    GitHub Blog Post Relative links in markup files:

    Starting today, GitHub supports relative links in markup files.
    Now you can link directly between different documentation files, whether you view the documentation on GitHub itself, or locally, using a different markup renderer.

    You want examples of link definitions and how they work? Here's some Markdown for you.
    Instead of an absolute link:

    [a link](https://github.com/user/repo/blob/branch/other_file.md)
    

    …you can use a relative link:

    [a relative link](other_file.md)
    

    and we'll make sure it gets linked to user/repo/blob/branch/other_file.md.

    If you were using a workaround like [a workaround link](repo/blob/master/other_file.md), you'll have to update your documentation to use the new syntax.

    This also means your documentation can now easily stand on its own, without always pointing to GitHub.


    Update December 20th, 2011:

    The GitHub markup issue 84 is currently closed by technoweenie, with the comment:

    We tried adding a <base> tag for this, but it causes problems with other relative links on the site.


    October 12th, 2011:

    If you look at the raw source of the README.md of Markdown itself(!), relative paths don't seem to be supported.
    You will find references like:

    [r2h]: http://github.com/github/markup/tree/master/lib/github/commands/rest2html
    [r2hc]: http://github.com/github/markup/tree/master/lib/github/markups.rb#L13
    
    0 讨论(0)
  • 2020-11-29 14:56

    If you want a relative link to your wiki page on GitHub, use this:

    Read here: [Some other wiki page](path/to/some-other-wiki-page)
    

    If you want a link to a file in the repository, let us say, to reference some header file, and the wiki page is at the root of the wiki, use this:

    Read here: [myheader.h](../tree/master/path/to/myheader.h)
    

    The rationale for the last is to skip the "/wiki" path with "../", and go to the master branch in the repository tree without specifying the repository name, that may change in the future.

    0 讨论(0)
  • 2020-11-29 14:59

    For example, you have a repo like the following:

    project/
        text.md
        subpro/
           subtext.md
           subsubpro/
               subsubtext.md
           subsubpro2/
               subsubtext2.md
    

    The relative link to subtext.md in text.md might look like this:

    [this subtext](subpro/subtext.md)
    

    The relative link to subsubtext.md in text.md might look like this:

    [this subsubtext](subpro/subsubpro/subsubtext.md)
    

    The relative link to subtext.md in subsubtext.md might look like this:

    [this subtext](../subtext.md)
    

    The relative link to subsubtext2.md in subsubtext.md might look like this:

    [this subsubtext2](../subsubpro2/subsubtext2.md)
    

    The relative link to text.md in subsubtext.md might look like this:

    [this text](../../text.md)
    
    0 讨论(0)
提交回复
热议问题