简体   繁体   English

为什么标题会在 GitHub readme.md 降价页面中自动创建链接?

[英]Why are headings automatically creating links in GitHub readme.md markdown pages?

Hello: I have created readme.md files for my repositories and GitHub pages.您好:我已经为我的存储库和 GitHub 页面创建了 readme.md 文件。 But when I create headings that are formatted h2/## or h3/###, etc. in-page anchor links are automatically created.但是当我创建格式为 h2/## 或 h3/### 等的标题时,会自动创建页内锚链接。 I have tried different ways to format the headings -- such as ##, , --- -- but I get the same result.我尝试了不同的方法来格式化标题——例如##、、————但我得到了相同的结果。 It occurs with each heading.它出现在每个标题中。 This occurs in readme.md files that are in the repository and those that are converted to GitHub pages.这发生在存储库中的 readme.md 文件和转换为 GitHub 页面的文件中。 I've tested it in chrome browser and edge browser and it's the same behavior.我已经在 chrome 浏览器和 Edge 浏览器中测试过它,它的行为是相同的。

# sample will create the heading and an unwanted in-page link # sample将创建标题和不需要的页内链接

## sample will create the heading and an unwanted in-page link ## sample将创建标题和不需要的页内链接

Here's a page with the behavior: https://burrittresearch.com/这是一个包含行为的页面: https : //burrittresearch.com/

My goal is to be able to format headings in markdown without having these links automatically created.我的目标是能够在不自动创建这些链接的情况下在 Markdown 中格式化标题。

Thank you!谢谢!

Those are part of the anchorjs default CSS rules from GitHub pages这些是来自 GitHub 页面的anchorjs默认 CSS 规则的一部分

<h2 id="skills">Skills
  <a class="anchorjs-link" 
     href="#skills" 
     aria-label="Anchor" 
     data-anchorjs-icon="" 
     style="font: 1em / 1 anchorjs-icons; padding-left: 0.375em;">
  </a>
</h2>

If you static page (like this one ) include its own set of CSS file/rules (like those ones ), you could add, to make sure they are not visible:如果你的静态页面(像这个)包含它自己的一组 CSS 文件/规则(像那些),你可以添加,以确保它们不可见:

.anchorjs-link {
  display: none !Important;
}

GitHub documents their markup processing in github/Markup . GitHub 在github/Markup 中记录了他们的标记处理。 Note that Markdown is converted to HTML in step one, which does not add any anchors to headers.请注意,Markdown 在第一步中转换为 HTML,它不会向标题添加任何锚点。 However, in step 4, which is separate from the Markdown parsing, all headers in the document have anchors added.但是,在与 Markdown 解析分开的第 4 步中,文档中的所有标题都添加了锚点。 This is done to all content, regardless of whether is comes from Markdown, ReStructured Text, textile, asscidoc, etc., and is not specific to Markdown.对所有内容都这样做,无论是否来自 Markdown、ReStructured Text、textile、asscidoc 等,并不特定于 Markdown。

Note that the above only applies to content supplied by users which is displayed on github.com.请注意,以上仅适用于 github.com 上显示的用户提供的内容。 It is their site, which they control, so we don't get to change/override that behavior.这是他们控制的网站,因此我们无法更改/覆盖该行为。

However, it is different with GitHub pages.但是,GitHub 页面则不同。 By default, GitHub Pages uses Jekyll to convert Markdown files into HTML.默认情况下,GitHub Pages 使用 Jekyll 将 Markdown 文件转换为 HTML。 Jekyll includes a number of options to control how Markdown is processed, including the auto_ids option. Jekyll 包含许多选项来控制 Markdown 的处理方式,包括auto_ids选项。 Turn that option off (set it to false), and Jekyll will no longer add IDs to every header.关闭该选项(将其设置为 false),Jekyll 将不再向每个标头添加 ID。 However, that is a Kramdown option, but, as I understand if, GitHub Pages uses the GitHub Flavored Markdown variant of Commonmark , which doesn't have any such options.但是,这是一个 Kramdown 选项,但是,据我所知,GitHub Pages 是否使用Commonmark的 GitHub Flavored Markdown 变体,它没有任何此类选项。 For that matter, the GFM spec doesn't indicate that headers would be assigned IDs either (so I'm not sure where those IDs are coming from).就此而言,GFM 规范也没有表明标头会被分配 ID(所以我不确定这些 ID 来自哪里)。 You might try configuring Jekyll to use Kramdown with the auto_ids option turned off.您可以尝试将 Jekyll 配置为在关闭auto_ids选项的情况下使用 Kramdown。 Configuration options "can either be specified in a _config.yml or _config.toml file placed in your site's root directory."配置选项“可以在放置在站点根目录中的_config.yml_config.toml文件中指定。”

As an alternative, you could install Jekyll (or any other static site generator ) locally and build the site before uploading to GitHub Pages.作为替代方案,您可以在本地安装 Jekyll(或任何其他静态站点生成器)并在上传到 GitHub 页面之前构建站点。 Simply include an empty file named .nojekyll in the site root and GitHub will not run your files through Jekyll.只需在站点根目录中包含一个名为.nojekyll的空文件,GitHub 将不会通过 Jekyll 运行您的文件。 In this way, you get complete control over the content and formatting of the pages.通过这种方式,您可以完全控制页面的内容和格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM