【问题标题】:Github Markdown Same Page LinkGithub Markdown 同页链接
【发布时间】:2015-03-14 21:32:48
【问题描述】:

假设我在同一个 git hub wiki 页面中有两个点,为此我们将其称为 place 1place 2

##Title

###Place 1

Hello, this is some text to fill in this, [here](place2), is a link to the second place.

###Place 2

Place one has the fun times of linking here, but I can also link back [here](place1).

另一种选择是 ToC。

##Title
[ToC]
###Place 1
###Place 2

有没有办法做到这一点?注意 - 看到 this 所以我假设它是主题。另外,处理文件之间的移动,这个处理同一个文件之间的移动。

【问题讨论】:

标签: github hyperlink markdown anchor


【解决方案1】:

这适用于 Github:

## Title

### Place 1

Hello, this is some text to fill in this, [here](#place-2), is a link to the second place.

### Place 2

Place one has the fun times of linking here, but I can also link back [here](#place-1).

### Place's 3: other example

Place one has the fun times of linking here, but I can also link back [here](#places-3-other-example).

转换规则总结:

  • 标点符号将被删除
  • 前导空格将被删除
  • 大写将转换为小写
  • 字母之间的空格将被转换为-

具有大量链接和格式的一个很好的示例文档是LivingSocial API Design Guide

【讨论】:

  • 请注意,引用链接本身必须编码为小写。使用上面的示例,如果您链​​接到[here](#Place-2),则该链接将不起作用。请注意,在示例中,标题称为“Place 2”,而指向它的链接(正确)称为[here](#place-2)
  • 如果您有 2 个或多个标题同名 Place,则链接将命名为 placeplace-1place-2 等。然后,如果您还有明确的标题 @ 987654330@ 它的链接将是place-2-1
  • 答案仍然很有帮助,因为它适用于 Gitlab Wiki。 html 方法(使用 gitlab wiki 中的锚标记)不起作用。我知道这个问题是关于 github 的。
  • BitBucket 好像不支持。我使用锚 代替。
  • 唯一的是,这似乎没有被 github 正式记录,所以它依赖于反向工程规则,可能会在没有通知的情况下更改,从而破坏您的所有链接。您最好使用@bcattle 的答案中提到的<a id="anchor-id"/><a id="anchor-id">text, html or markdown</a>
【解决方案2】:

还可以创建命名的自定义锚点,例如,如果您有一堆具有相同名称的(子)标题。要使用标头执行此操作,请插入 HTML 标记:

<h4 id="login-optional-fields">
Optional Fields
</h4>

然后通过ID属性链接到它:

[see above](#login-optional-fields)

也可以直接向文档添加锚标记:

<a id="my-anchor"></a>

【讨论】:

  • 谢谢,这个解决方案很有效,而且是有原因的。去年对 GIT 降价的更改阻止标题被添加为 #my heading,它必须是 # my heading,并且在锚点中添加一个空格,如 (# my-heading) 不起作用
  • 这也适用于 .md 文件。我将 gatsby 用于我的技术博客,并希望创建一个指向页面本身部分的超链接。谢谢!
  • 非常酷,并且不依赖于 github 如何将标题转换为锚点的实现细节(可能随时更改,恕不另行通知)。它甚至适用于图像:&lt;a id="image"&gt;![Your Image](docs/your-image.png)&lt;/a&gt; 然后[your image](#image) 链接到图像!这适用于 github 和 pycharm IDE 的 markdown 预览器。
【解决方案3】:

复制自 GitHub Gist - 原帖位于 here

要创建跳转到 README 不同部分的锚链接(如在交互式目录中),首先创建一个标题:

#Real Cool Heading

该标题的锚链接是带有破折号的小写标题名称,其中有空格。您始终可以通过访问 Github.com 上的 README 并单击将鼠标悬停在标题左侧时出现的锚点来获取锚点名称。复制从 # 开始的所有内容:

#real-cool-heading

无论您想在哪里链接到真正的酷标题部分,请将您想要的文本放在括号中,然后是括号中的锚链接:

[Go to Real Cool Heading section](#real-cool-heading)

【讨论】:

    【解决方案4】:

    示例 1:

    ##Title
    
    ###Place 1<span id="place1">HelloWorld</span>
    
    Hello, this is some text to fill in this, [here](#place2), is a link to the second place.
    
    ###Place 2<span id="place2">HelloWorld</span>
    
    Place one has the fun times of linking here, but I can also link back [here](#place1).
    

    这是一个可以从place1跳到place2,从place2跳到place1的版本

    ##Title
    
    ###[Place 1](#Place-2)<span id="place1">HelloWorld</span>
    
    Hello, this is some text to fill in this, [here](#place2), is a link to the second 
    place.
    
    ###Place 2(#Place-1)<span id="place2">HelloWorld</span>
    
    Place one has the fun times of linking here, but I can also link back [here](#place1).
    

    【讨论】:

      【解决方案5】:

      不幸的是,GitHub wiki 似乎从您添加到 wiki 页面的自定义 HTML 中删除了所有“id=..”标签,因此页面中唯一有效的锚点是标题。

      【讨论】:

        【解决方案6】:

        接受的答案对我不起作用,因为我的标题也是一个链接:

        之前(无效):

        Table of contents 
        
         1. [Header Name](#header-name)
        
        
        ### [Header Name](https://google.com)
        

        之后(为我工作):

        Table of contents 
        
         1. [Header Name](#header-name)
        
        
        ### Header Name
        
        https://google.com
        

        这是您不想拥有 html 并希望使用可接受的解决方案并在自述文件中进行一些权衡的时候。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-11-30
          • 2013-01-01
          • 1970-01-01
          • 2016-01-18
          • 1970-01-01
          • 1970-01-01
          • 2015-11-17
          • 1970-01-01
          相关资源
          最近更新 更多