Skip to content
This repository has been archived by the owner on Mar 10, 2022. It is now read-only.

github anchor #5

Open
aderidder opened this issue Nov 5, 2015 · 2 comments
Open

github anchor #5

aderidder opened this issue Nov 5, 2015 · 2 comments

Comments

@aderidder
Copy link

Hi,

We have several pages in a github wiki which use anchors to navigate within a page. In github markdown it looks like this:

[Some text](#header-1)
# Header 1

This works fine. If I look at the HTML this leads to on github:
<a href="#header-1">Some text</a>
<h1><a id="user-content-header-1" class="anchor" href="#header-1" aria-hidden="true"><span class="octicon octicon-link"></span></a></h1>

If I run the same markdown content through showdown, the html it generates is
<a href="#header-1">Some text</a>
<h1 id="header1">Header 1</h1>

So it seems to have removed the space from the header text to generate its id. As they are no longer matching, the navigation is no longer working. Is there some setting I'm missing?

Thanks!

@tivie
Copy link
Member

tivie commented Nov 5, 2015

The behavior of showdowns generated Ids follows the original markdown.pl, the parser made by markdown's aithor, John Gruber.
This behavior, however, is a bit different from github, which uses a different set of rules, mostly for internal linking and compatibility issues.

Currently you cannot match git hubs behavior.
However it should not be very difficult to implement an option to emulate this.

Do you mind post the list of rules github uses to generate IDS?

I can use that list as a base for said option!

@aderidder
Copy link
Author

Thanks for the quick response.

So far I haven't been able to find the list of rules.
The page that contains the gfm information, https://help.github.com/articles/github-flavored-markdown/, doesn't say anything about the identifiers unfortunately.

Perhaps an easy fix would be to allow a user to provide a parameter with which to replace the non-word characters in the Headers? I think replacing the non-word characters with "-" would already lead to a working solution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants