Skip to content

fix: fix links starting with / #1

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

Closed
wants to merge 3 commits into from
Closed

Conversation

scrythe
Copy link

@scrythe scrythe commented May 16, 2025

I experienced a problem with links starting with /
for example: introduction.html gets converted into #-introduction instead of #introduction, fixed by remove the first character incase the link starts with /

I tested the new version on bevy-cheatbook (https://github.com/bevy-cheatbook/bevy-cheatbook) and it seems to work for me.

HollowMan6 and others added 2 commits May 12, 2025 21:04
Let all the anchors id on the print page to have a path id prefix to
help locate.

e.g. bar/foo.md#abc -> #bar-foo-abc

Also append a dummy div to the start of the original page to make sure
that original page links without an anchor can also be located.

Fix to remove all the `./` in the normalized path id so that for
"./foo/bar.html#abc" we still get "#foo-bar-abc"

Add support for redirect link anchors in print page so that anchors can
also be redirected, also handle URL redirect links on print page

Handle all the elements id to add a path prefix, also make path id to
all be the lower case

Fix for print page footnote links by adding the path id prefix

Signed-off-by: Hollow Man <[email protected]>
I experienced a problem with links starting with /
for example: introduction.html gets converted into #-introduction instead of #introduction,
fixed by remove the first character incase the link starts with /
@scrythe
Copy link
Author

scrythe commented May 16, 2025

nevermind, some links still don't work

@scrythe
Copy link
Author

scrythe commented May 16, 2025

absolute links of subpages seem to not work
so for the page "tutorial/guide.html", I think all links are appened with tutorial, even absolute ones like href="/setup.html"
so instead of being "#setup" it becomes "#tutorial-setup"

absolute links of subpages seem to not work so for example, all links
inside a page like "tutorial/guide.html" seem to append "tutorial" so
instead of being "#setup" it becomes "#tutorial-setup" fixed by only
appending base of links that don't start with /
my solution may be bad and I didn't test it thouroughly but it works
for me
@scrythe
Copy link
Author

scrythe commented May 16, 2025

this commit should fix it, but like pointed out, I can't guarantee that it works properly and doesn't break other behaviour.

@HollowMan6 HollowMan6 force-pushed the master branch 3 times, most recently from 2d8cf8a to 4073892 Compare May 16, 2025 21:41
@HollowMan6
Copy link
Owner

Hi @scrythe! Good catch. Thanks for pointing this out and submitting this PR. I didn't really expect those links within the book to be absolute, as I can also observe some problems when I directly open the html with browser.

image

I implemented my fix for this here: https://github.com/rust-lang/mdBook/compare/cef21f1927d8cef0253836011a68f307355d59e6..bc18556e2ca2b200ae5a2305573ec35bbe707b4e

Then I tried to compile the book https://github.com/bevy-cheatbook/bevy-cheatbook, and it looks like we have another issue: those pages actually don't exist in print.html (e.g., for setup.md), which causes the links to further fail. I tried with the original mdbook and the problem persists, so I guess this is not related to the fork's change, and I would suggest opening an issue either on the book author's side or mdbook upstream's side.

Thanks again, and I'm closing this now. Feel free to discuss with me if you find more issues at rust-lang#1738

@HollowMan6 HollowMan6 closed this May 16, 2025
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.

2 participants