链接到GitHub上的一行Markdown文件

Ian*_*han 28 github

我经常通过#LURI中的param 链接到GitHub源代码.

例如:https://github.com/github/learn.github.com/blob/gh-pages/episodes.yaml#L1

但是有没有办法链接到Markdown文件中的行?

例如https://github.com/github/learn.github.com/blob/gh-pages/README.md#L1 (不起作用!)

我知道我可以链接到'部分',但线条要好得多!

例如https://github.com/github/learn.github.com/blob/gh-pages/README.md#learngithubcom

lul*_*ala 18

由于目前无法实现,我采用下一个最佳选择:使用blame然后突出显示这些行,例如https://github.com/rails/rails/blame/master/guides/source/configuring.md#L166

  • 几乎就在那里,[参见我的答案](/sf/answers/4004144441/):不要使用 `master` 而使用 SHA,并且 - 如果需要 - 将 `/blame/` 替换为 `/blob/ ` 内联到问题中 (3认同)

Dan*_*ein 18

现在支持?plain=1

2021 年 6 月 30 日宣布,现在有一个禁用 Markdown 渲染的参数

现在,附加?plain=1到任何 Markdown 文件的 url 将显示该文件而不进行渲染。与其他代码文件一样,它也会显示行号,并可用于将其他用户链接到特定的一行或多行。例如,追加?plain=1#L52将突出显示纯文本 Markdown 文件的第 52 行。

听起来您可能想使用行号链接到渲染文档中的某个点。这仍然是不可能的,也不是 Markdown 渲染的标准功能来添加这样的行号锚点。


Tin*_*ino 7

为了读者的利益:长答案是肯定的,这很困难,但可能。

GitHub 允许将永久链接内联到 Markdown 文件的文本部分

但是目前似乎无法直接创建此类永久链接,您必须手动创建它们。如下:

  • 显示降价文档
  • 在上右击文档上方缩短SHA的文件
    (可以用“历史”和有关承诺,以及)
  • 显示提交的差异。
  • 在右侧的提交上方单击 3 个点...并选择“查看文件”
  • 现在 Mardown 再次出现,但它是永久变体。
  • 在文档上方右键单击“责备”
  • 向下滚动到包含要引用的文本的 Markdown 表示的行
  • 选择有问题的一行或多行
  • 从浏览器地址栏复制网址
  • 将 URL 粘贴到问题中等。
  • 此步骤仅在问题中需要:在 URL 中替换/blame//blob/

在问题的预览中,您将看到预期的 Markdown 文本部分的直接引用。

缺点了的/blob/-variant

如果单击 URL,您会在浏览器中看到完整的 Markdown,文本部分未按预期标记。

这是 GitHub 如何处理这些 URL 的限制。

缺点了的/blame/-variant

由于所有这些注释和 Markdown 的非渲染,它完全不可读。

例子

请注意,我必须克隆此示例才能创建问题:

https://github.com/hilbix/learn.github.com/blob/gh-pages/README.md

  • 单击 SHA

https://github.com/hilbix/learn.github.com/commit/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba

  • “查看文件”

https://github.com/hilbix/learn.github.com/blob/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md

  • “责备”

https://github.com/hilbix/learn.github.com/blame/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md

  • 标记一些行

https://github.com/hilbix/learn.github.com/blame/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md#L20-L23

  • 更改网址

https://github.com/github/learn.github.com/blob/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md#L20-L23

  • 将此 URL 粘贴到某个问题中

结果:https : //github.com/hilbix/learn.github.com/issues/1

这是进入问题:

https://github.com/hilbix/learn.github.com/blob/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md#L20-L23

see /sf/answers/4004144441/
Run Code Online (Sandbox Code Playgroud)

这呈现为类似

learn.github.com/README.md

Lines 20 to 23 in 38034b3
    $ git clone https://github.com/github/learn.github.com
    $ cd learn.github.com
    $ script/bootstrap
    $ jekyll --server

see /sf/answers/4004144441/
Run Code Online (Sandbox Code Playgroud)

这是所创建问题的完整 HTML(抱歉,我也没有设法复制 CSS):

https://github.com/hilbix/learn.github.com/blob/38034b3aee7f4fb7f46e94b3f9c2b3d3554291ba/README.md#L20-L23

see https://stackoverflow.com/a/57202063/490291
Run Code Online (Sandbox Code Playgroud)