Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

github - Markdown文件中的GitHub相对链接(GitHub relative link in Markdown file)

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

(有没有办法创建一个URL锚点, <a> ,从Markdown文件中链接到同一存储库和分支中的另一个文件(也就是相对于当前分支的链接)?)

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

(例如,在master分支中我有一个README.md文件,我想做的事情如下:)

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

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

Here is a working example of what I mean:

(这是我的意思的一个工作示例:)

  1. GOTO http://github.com/rynop/testRel , link does not work.

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

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

    (GOTO http://github.com/rynop/testRel/blob/master/README.md ,链接有效。)

This is expected because at this point the starting URL is in the branch.

(这是预期的,因为此时起始URL位于分支中。)

Now how do I get it to pick up the current branch in the README.md at the root of the repository?

(现在我如何让它在存储库根目录下的README.md中获取当前分支?)

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

(更新 :我针对此功能请求针对GitHub打开了一个问题 。)

  ask by rynop translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Update 30th, January 2013 , 16 months later:

(2013年1月30日更新,16个月后:)

GitHub Blog Post Relative links in markup files : (GitHub Blog Post 标记文件中的相对链接 :)

Starting today, GitHub supports relative links in markup files .

(从今天开始, GitHub支持标记文件中的相对链接 。)
Now you can link directly between different documentation files, whether you view the documentation on GitHub itself, or locally, using a different markup renderer.

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

You want examples of link definitions and how they work?

(您想要链接定义的示例以及它们如何工作?)

Here's some Markdown for you.

(这是给你的Markdown。)
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 .

(我们将确保它链接到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.

(如果您使用[a workaround link](repo/blob/master/other_file.md)[a workaround link](repo/blob/master/other_file.md) ,则必须更新文档以使用新语法。)

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

(这也意味着您的文档现在可以轻松地独立存在,而无需始终指向GitHub 。)


Update December 20th, 2011:

(2011年12月20日更新:)

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

(GowHub 标记问题84目前由technoweenie关闭,评论如下:)

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

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


October 12th, 2011:

(2011年10月12日:)

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

(如果查看Markdown本身README.md原始源 (!),似乎不支持相对路径。)
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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...