GitHub relative link in Markdown file

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

    As of January 31, 2013 Github markdown supports relative links to files.

    [a relative link](markdown_file.md)
    

    However, there are a few deficiencies that have been discussed in this comment thread.

    As an alternative, you can use Gitdown to construct full URLs to the repository and even make them branch aware, e.g.

    {"gitdown": "gitinfo", "name": "url"} // https://github.com/gajus/gitdown
    {"gitdown": "gitinfo", "name": "branch"} // master
    

    Gitdown is a GitHub markdown preprocessor. It streamlines common tasks associated with maintaining a documentation page for a GitHub repository, e.g. generating table of contents, including variables, generating URLs and getting information about the repository itself at the time of processing the input. Gitdown seamlessly integrates with your building scripts.

    I am the author of the Gitdown library.

    0 讨论(0)
  • 2020-11-29 15:01

    This question is pretty old, but it still seems important, as it isn't easy to put relative references from readme.md to wiki pages on Github.

    I played around a little bit and this relative link seems to work pretty well:

    [Your wiki page](../../wiki/your-wiki-page)

    The two ../ will remove /blob/master/ and use your base as a starting point. I haven't tried this on other repositories than Github, though (there may be compatibility issues).

    0 讨论(0)
  • 2020-11-29 15:01

    You can use relative URLs from the root of your repo with <a href="">. Assuming your repo is named testRel, put the following in testRel/README.md:

    # My Project
    is really really cool. My Project has a subdir named myLib, see below.
    
    ## myLib docs
    see documentation:
        * <a href="testRel/myLib">myLib/</a>
        * <a href="testRel/myLib/README.md">myLib/README.md</a>
    
    0 讨论(0)
  • 2020-11-29 15:07

    Just wanted to add this because none of the above solutions worked if target link is directory with spaces in it's name. If target link is a directory and it has space then even escaping space with \ doesn't render the link on Github. Only solution worked for me is using %20 for each space.

    e.g.: if directory structure is this

    Top_dir
    |-----README.md
    |-----Cur_dir1
          |----Dir A
               |----README.md
          |----Dir B
               |----README.md
    

    To make link to Dir A in README.md present in Top_dir you can do this:

    [Dir 1](Cur_dir1/Dir%20A)
    
    0 讨论(0)
  • 2020-11-29 15:10

    GitHub could make this a lot better with minimal work. Here is a work-around.

    I think you want something more like

    [Your Title](your-project-name/tree/master/your-subfolder)
    

    or to point to the README itself

    [README](your-project-name/blob/master/your-subfolder/README.md)
    
    0 讨论(0)
提交回复
热议问题