Geoff Huang
Geoff Huang

Reputation: 117

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. 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?

Upvotes: 4

Views: 2872

Answers (1)

Waylan
Waylan

Reputation: 42517

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.

Upvotes: 3

Related Questions