Markdown文件中的GitHub相对链接 [英] GitHub relative link in Markdown file

查看:471
本文介绍了Markdown文件中的GitHub相对链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在一个Markdown文件中创建一个URL定位点< a> ,链接到同一个存储库和分支内的另一个文件(又名a链接相对于当前分支)?



例如,在master分支中,我有一个README.md文件,我想这样做:

 #我的项目
真的很酷。我的项目有一个名为myLib的子目录,见下文。

## myLib文档
请参阅文档[here](myLib / README.md)

这将允许我在同一分支中从一个.md链接到另一个。不必担心我在哪个分支(避免必须执行包含github.com分支的绝对URL姓名)。



以下是我的一个实际例子:


  1. GOTO http://github.com/rynop/testRel ,链接不起作用。

  2. GOTO http://github.com/rynop/testRel/blob/master/README.md,link works。

预计这是因为此时起始URL位于分支中。现在我该如何获取它在存储库根目录下的README.md中的当前分支?



更新:我打开了针对此功能请求的GitHub问题

解决方案

更新 2013年1月30日,16个月后: /github.com/blog/1395-relative-links-in-markup-filesrel =noreferrer> GitHub Blog Post 标记文件中的相对链接


从今天开始, GitHub支持标记文件中的相关链接

现在您可以直接链接不同的文档文件,无论您是在GitHub本身上查看文档,还是在本地使用其他标记呈现器。

这里有一些针对你的Markdown。

而不是一个绝对的链接:

  [一个链接](https: //github.com/user/repo/blob/branch/other_file.md)

...您可以使用相对链接:

  [相对链接](other_file.md)

我们将确保它链接到 user / repo / blob / branch / other_file.md [解决方法链接](repo / blob / master / other_file.md) c $ c>,您必须更新您的文档以使用新的语法。



这也意味着您的文档现在可以轻松地独立运行,没有总是指向GitHub







2011年12月20日更新:



GitHub标记问题84 目前由 technoweenie ,附注:


我们尝试为此添加一个< base> 标记,但它会导致网站上其他相关链接出现问题。







2011年10月12日:

如果您看 原始来源 README.md Markdown本身(!),相对路径似乎不被支持。

您会找到如下引用:

  [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


Is there a way to create a URL anchor, <a>, link from within a Markdown file, to another file within the same repository and branch (aka a link relative to the current branch)?

For example, in the master branch I have a README.md file, which I would like do something like:

# My Project
is really really cool. My Project has a subdir named myLib, see below.

## myLib documentation
see documentation [here](myLib/README.md)

This would allow me to link from one .md to another within the same branch and not have to worry about which branch I'm in (avoid having to do an absolute URL that includes the github.com branch name).

Here is a working example of what I mean:

  1. GOTO http://github.com/rynop/testRel, link does not work.
  2. GOTO http://github.com/rynop/testRel/blob/master/README.md, link works.

This is expected because at this point the starting URL is in the branch. Now how do I get it to pick up the current branch in the README.md at the root of the repository?

Update: I opened an issue against GitHub for this feature request.

解决方案

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

这篇关于Markdown文件中的GitHub相对链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆