Skip to content

Improve on-page header link resolution and default anchor handling (for footnotes, etc)#667

Open
samuel-reinhardt wants to merge 4 commits intoKosmosisDire:masterfrom
samuel-reinhardt:master
Open

Improve on-page header link resolution and default anchor handling (for footnotes, etc)#667
samuel-reinhardt wants to merge 4 commits intoKosmosisDire:masterfrom
samuel-reinhardt:master

Conversation

@samuel-reinhardt
Copy link

Should resolve issue #646 and some other issues with internal link resolution I was seeing (not filed issues).

My testing ground for reference: https://vectorarrow.com/experiments/test/footer-test.html

@samuel-reinhardt
Copy link
Author

Updated to use better handling for heading hierarchy, and add support for same-page block links which should satisfy issue #57

@d9k
Copy link

d9k commented Aug 25, 2025

@samuel-reinhardt, thanks for the cool PR! Was missing this feature too!

Found a bug: blocks links with CAPITAL letters are not supported. If you click on link with capital letters browser darkens then reopens the page with scroll position on top.

Update: I tried to uncheck Webpage HTML export -> Export settings -> Use Relative Header Links but it didn't change behavior

@d9k
Copy link

d9k commented Aug 25, 2025

Also when scrolled to block link it would be better to scroll not to exact block link target position but one line above.

@samuel-reinhardt
Copy link
Author

samuel-reinhardt commented Aug 26, 2025

Found a bug: blocks links with CAPITAL letters are not supported. If you click on link with capital letters browser darkens then reopens the page with scroll position on top.

@d9k Can you copy and paste the markdown you're seeing this issue with for me to verify? I believe the issue is just that Obsidian header links are case insensitive, while browser-native anchor link handling is case sensitive. So if the scenario you're encountering is what I think, capital letters still work, it's just a mismatch between link and ID.

Also when scrolled to block link it would be better to scroll not to exact block link target position but one line above.

This can/should be handled via styling. The default obsidian behavior doesn't seem to do this, so I think it makes sense to leave the default behavior as-is. However I've added a class to block links to allow for easier targeting of this behavior.

Ex for only block links:

.blockid-target {
    scroll-margin: 2ex;
}

For everything:

:is(*) {
    scroll-margin: 2ex;
}

@KosmosisDire
Copy link
Owner

Thanks this is great! Does something still need to be done about the case sensitivity for block links?

@samuel-reinhardt
Copy link
Author

Thanks this is great! Does something still need to be done about the case sensitivity for block links?

Yes, it still needs to be handled. I should have time this weekend.

@KosmosisDire
Copy link
Owner

Okay thanks! One thing I also notice is that in your test page it shows all resolved links as unresolved (they all have the .is-unresolved class). I beleive this was working previously where resolved links would be normal and unresolved links would ha ve the .is-unresolved class. It seems in your test page it is ironically the opposite where only the unresolved links are showing as resolved

@KosmosisDire
Copy link
Owner

Finally, I also notice that the hover previews are not working for those links. This may be because they are marked as unresolved, or it may be something else. But the hover preview should, theoretically, actually show only the content being pointed to (the header section, block, footer, etc)

@d9k
Copy link

d9k commented Aug 30, 2025

@samuel-reinhardt, thanks for advice about scroll-margin styling 👍

I believe the issue is just that Obsidian header links are case insensitive, while browser-native anchor link handling is case sensitive.

I meant not header links but block links. Something like

^my-SQL-query
.....Many lines
[[#^my-SQL-query]]

@dwangoac
Copy link

@samuel-reinhardt Hi! I'm seeing this issue as well prior to any of your changes as manifested at https://lot.tas.bot - if the file is downloaded and opened, links work properly, but not when hosted with a metadata.json file present.

To reproduce what I'm seeing, do a wget https://lot.tas.bot/index.html to an empty directory and open the file itself in a web browser, you'll see that both anchor links as well as the hide/show right sidebar controls work. Then host the file locally with sudo python3 -m http.server 80 and navigate to http://localhost you'll see it report it fails to get /site-lib/metadata.json in the terminal log; in this circumstance, the anchor links will work but the hide/show right side bar controls don't work. Finally, if you create a /site-lib/metadata.json file containing {} and repeat the test you'll see the hide/show right side bar controls work but anchor links throw "This page does not exist yet."

I'm unsure if this test scenario is helpful or not but my hope is I can retest after you've made your changes and they make it into a beta release. Thanks for taking another glance at this when you get a moment, I appreciate it!

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

Successfully merging this pull request may close these issues.

4 participants