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

Same-document hyperlinks support #233

Open
gridlocdev opened this issue Feb 15, 2022 · 2 comments
Open

Same-document hyperlinks support #233

gridlocdev opened this issue Feb 15, 2022 · 2 comments

Comments

@gridlocdev
Copy link

When using a link to another place in the same markdown document, the published Listed site reloads the page at the root level (with the link tag appended to the url) instead of navigating the page scroll to the appropriate tag on the page:

[Link to Header](#example-header)

# Example Header
@gridlocdev
Copy link
Author

I've done some testing myself while playing around with SSG, and it's likely to do with how same-document hyperlinks navigate.

Here's a related Issue that explains it better: github/cmark-gfm#186

In short, same-document hyperlinks with the # prefix target elements by ID, and the Listed generated header tags like h1, h2 etc; do not get generated with any ID attributes.

In the example I put in the comment above, the HTML that would get generated to enable same-document hyperlinks would look like:

<a href="...#example-header">Link to Header</a>

<h1 id="example-header">Example Header</h1>

@dewcked
Copy link

dewcked commented Oct 24, 2022

I felt uncomfortable, so I made a tampermonkey userscript for this function.

https://gist.github.com/dewcked/4f53f75a1563011dabfbcb2546029df0#file-listed-to-enhanced-markdown-links-js

This function adds distinct id (with naming convention example-header) and chain to each heading. Chain works same as github's.

still, it is not 100% compatible with markdown heading-to-elementId rule. I'm searching for heading-to-elementId sanitization rule.

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

No branches or pull requests

2 participants