How to remove anchor links from headers in Markdown?

懵懂的女人 提交于 2021-02-11 16:19:11

问题


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. When you click this anchor, it links you to the page with that header at the top of the page (www.myurl#myheader).

Is it possible to remove this anchor?


回答1:


You can disable Kramdown's auto-ids option. Depending on how you are using Kramdown, there are a number of ways in which to do so:

Command Line

If you are using Kramdown from the command line, simply include the --no-auto-ids option:

kramdown --no-auto-ids

Ruby Code

If you are calling Kramdown from your own Ruby code, set 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

The question mentions 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:

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.



来源:https://stackoverflow.com/questions/58785061/how-to-remove-anchor-links-from-headers-in-markdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!