# Github 预览中的锚点应预览锚点位置，而不是文件顶部

**URL:** <https://meta.discourse.org/t/github-preview-with-anchors-should-preview-the-anchor-rather-than-the-top-of-the-file/331474>\
**Category:** Bug\
**Tags:** onebox, pr-welcome\
**Created:** [2024年十月18日 05:37 UTC](https://meta.discourse.org/t/github-preview-with-anchors-should-preview-the-anchor-rather-than-the-top-of-the-file/331474 "2024-10-18T05:37:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atemu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/atemu/32/456886_2.png) [@Atemu](https://meta.discourse.org/u/Atemu)\
**Post date:** [2024年十月18日 05:37 UTC](https://meta.discourse.org/t/github-preview-with-anchors-should-preview-the-anchor-rather-than-the-top-of-the-file/331474/1 "2024-10-18T05:37:33Z")

</div>

当您链接带有锚点的 Github 文件时，Discourse 渲染的预览是从文件顶部开始，而不是从锚点开始。

例如，请参阅：

> <https://github.com/discourse/discourse/blob/main/README.md#development>

此预览应显示开发部分，而不是自述文件的顶部。

（不确定这是否真的是一个错误。）

---

<div class="post-metadata">

**Author:** ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)\
**Post date:** [2024年十月25日 09:41 UTC](https://meta.discourse.org/t/github-preview-with-anchors-should-preview-the-anchor-rather-than-the-top-of-the-file/331474/2 "2024-10-25T09:41:07Z")

</div>

如果您想改进这一点，我已经添加了一个 #pr-welcome。 🙂

---

<div class="post-metadata">

**Author:** ![jahan\_gagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jahan_gagan/32/501948_2.png) [@jahan\_gagan](https://meta.discourse.org/u/jahan_gagan)\
**Post date:** [2024年十一月13日 13:01 UTC](https://meta.discourse.org/t/github-preview-with-anchors-should-preview-the-anchor-rather-than-the-top-of-the-file/331474/4 "2024-11-13T13:01:42Z")

</div>

我审查了此 PR，并注意到 Discourse 尝试直接从存储库提供内容，使用 `https://raw.githubusercontent.com`，它提供了一个未加样式化的纯文本文件（例如 `https://raw.githubusercontent.com/discourse/discourse/main/README.md#development`）。对于特定行引用（例如 `#L-{line-number}`），它会直接跳转到文件中指定的行来显示内容。要预览特定部分（例如 `#development`、`#requirements`），您可以指定行号，如下所示：

> <https://github.com/discourse/discourse/blob/main/README.md#L23>
