Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

links to anchors to other headings not working #22

Closed
fabbra opened this issue Feb 26, 2021 · 4 comments
Closed

links to anchors to other headings not working #22

fabbra opened this issue Feb 26, 2021 · 4 comments
Labels
bug - output The output isn't what it is supposed to be

Comments

@fabbra
Copy link

fabbra commented Feb 26, 2021

I have a markdown file with various headings and links inside the same file linking to those headings (i.e., linking to anchors in the same file) and converted this to HTML using the following code:

  gh-md-to-html ./test.md -w .

After conversion the "internal" links to other headings do not work anymore. My dirty workaround was to replace id="user-content- with id=" and class="anchor" with an empty string.

  sed -i 's/id=\"user-content-/id=\"/g' test.html
  sed -i 's/class=\"anchor\" //g' test.html

I suppose there might be a more elegant solution to this?

@phseiff
Copy link
Owner

phseiff commented Apr 3, 2021

@fabbra Hello, and sorry for responding so late (several months, actually). I accidentally unwatched my own repository, and missed several issues in the process. I didn't realize this until right now, though.

My apologies for the delayed response; I will look into the issue (and hopefully fix it) this evening.

Did you find a workaround for yourself? I'm sorry if you had to stop using my tool due to me not fixing this in time.

I suppose there might be a more elegant solution to this?

I think the behavior is probably either caused by GitHub's web API, or by some internal code of the module. In the later case, I just need to change some code, and in the former one, I will parse the HTML and do some changes to the parsed HTML (using sed would probably cause issues in case the string "user-content- is used within a code box, for example.

@phseiff phseiff added the bug - output The output isn't what it is supposed to be label Apr 3, 2021
@phseiff
Copy link
Owner

phseiff commented Apr 3, 2021

Turns out the behavior to start header ids with user-content- is GitHub-specific behavior (and the offline-option that gh-md-to-html provides actually imitates that behavior on purpose). This behavior is also intended, because it ensures that the resulting HTML file can be embedded into any website, for example using a self-written static site generator, without clashing with anchors used by the rest of the website provided none of them starts with user-content-.

@phseiff phseiff closed this as completed in 0ca716c Apr 3, 2021
@phseiff
Copy link
Owner

phseiff commented Apr 3, 2021

I fixed this now by making the tool change all internal links from <a href="#foobar"> to <a href="#user-content-foobar">.
Thanks again for filing this issue! :D

@fabbra
Copy link
Author

fabbra commented Apr 6, 2021

perfect. thanks a lot for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug - output The output isn't what it is supposed to be
Projects
None yet
Development

No branches or pull requests

2 participants