简体   繁体   English

如何从 Markdown 的标题中删除锚链接?

[英]How to remove anchor links from headers in Markdown?

In Github, when you create an h2 or smaller header (##, ###, ...) there is an anchor link thing that is automatically generated to the right of the header.在 Github 中,当您创建 h2 或更小的 header (##, ###, ...) 时,会在 Z099FB995346F31C749F6E40DB0F395 的右侧自动生成一个锚链接事物。 When you click this anchor, it links you to the page with that header at the top of the page (www.myurl#myheader).当您单击此锚点时,它会将您链接到页面顶部带有 header 的页面 (www.myurl#myheader)。

Is it possible to remove this anchor?是否可以删除此锚?

You can disable Kramdown's auto-ids option.您可以禁用 Kramdown 的自动 ID选项。 Depending on how you are using Kramdown, there are a number of ways in which to do so:根据您使用 Kramdown 的方式,有多种方法可以这样做:

Command Line命令行

If you are using Kramdown from the command line, simply include the --no-auto-ids option:如果您从命令行使用 Kramdown,只需包含--no-auto-ids选项:

kramdown --no-auto-ids

Ruby Code Ruby代码

If you are calling Kramdown from your own Ruby code, set auto_ids: false :如果您从自己的 Ruby 代码调用 Kramdown,请设置auto_ids: false

Kramdown::Document.new(source_text, {auto_ids: false})

From within a document从文档中

You can also override the default settings from within a document for the document only.您还可以仅从文档中覆盖文档中的默认设置。 Include the following in the document on a line by itself:在文档中单独包含以下内容:

{::options auto_ids="false" /}

GitHub Pages GitHub 页数

The question mentions GitHub.问题提到了 GitHub。 Assuming this is referring to GitHub Pages with Jekyll (as that is the only place GitHub makes use of Kramdown ), you can set Kramdown options in your _config.yml file:假设这是指使用 Jekyll 的 GitHub 页面(因为这是GitHub 使用 Kramdown 的唯一地方),您可以在_config.yml文件中设置 Kramdown 选项

markdown: kramdown
auto_ids: false

Note that if you are using GFM on GitHub Pages, or if you are using any other GitHub service except GitHub Pages, this option is not available as GFM does not offer such an option.请注意,如果您在 GitHub 页面上使用 GFM,或者如果您使用除 GitHub 页面以外的任何其他 GitHub 服务,则此选项不可用,因为 GFM 不提供此类选项。

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

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