Skip to content

anchors with spaces #156

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
icanrealizeum opened this issue Jul 30, 2016 · 4 comments
Closed

anchors with spaces #156

icanrealizeum opened this issue Jul 30, 2016 · 4 comments

Comments

@icanrealizeum
Copy link
Contributor

Hello. Clicking on anchors generate urls with spaces which seem unusable when trying to link to, for example here:
https://rust-lang.github.io/book/ch04-02-ownership.html#Variable binding scope

Is there a way to make the spaces be %20 or whatever is idiomatic in these cases?
Thanks.

@azerupi
Copy link
Contributor

azerupi commented Jul 30, 2016

Yes, the code responsible for this is here. I guess the best action is to convert spaces to underscores and check if the url already contains a hashtag.

@icanrealizeum
Copy link
Contributor Author

The only issue would be, I would think, that if spaces now become underscores, any previous urls with %20 instead of space, anywhere on the net already, would stop working.
Eg. in OP, this url
https://rust-lang.github.io/book/ch04-02-ownership.html#Variable binding scope
with %20 currently works:
https://rust-lang.github.io/book/ch04-02-ownership.html#Variable%20binding%20scope
and I've used this url myself in places.

So after the fix of spaces to underscores, it won't work anymore; only this would then work:
https://rust-lang.github.io/book/ch04-02-ownership.html#Variable_binding_scope

I'm not sure how much this backward-compatibility should matter on deciding whether or not to implement the spaces to underscores. Just putting it out there.

@azerupi
Copy link
Contributor

azerupi commented Jul 31, 2016

I'm not sure how much this backward-compatibility should matter on deciding

You're right, I have always announced mdBook as "unstable" to allow for changes like these. But I can understand that this could be a pain.

I don't feel strongly about one (_) or the other (%20), both solutions are fine for me. If the latter one can minimize breakage, let's do that.

@icanrealizeum
Copy link
Contributor Author

icanrealizeum commented Jul 31, 2016

Cool. I guess I could make a PR with %20 and if you later decide to change them to _ that's okay too - it makes sense now since (I didn't know that) mdBook is to be treated as "unstable" (haven't read the readme yet, oops)

Thanks for pointing me to the code above. I'll see if I can figure out how to do this with my limited know-how :D

Cheers!

EDIT:
So it turns out, that at least in firefox, using %20 as in this:
<a href="file:///home/z/build/1nonpkgs/book/book/index.html#Contributing%20to_the_book" name="Contributing%%20to%%20thebook" class="header"><h2>Contributing2 to the book</h2></a>
when clicked they get transformed into spaces, so the above becomes:
file:///home/z/build/1nonpkgs/book/book/index.html#Contributing to_the_book in the url bar!
oh but wait a second... when copied with Ctrl+C from the url bar, looks like it is pasted correctly, as:
file:///home/z/build/1nonpkgs/book/book/index.html#Contributing%20to_the_book
So nevermind ... lol, I guess it does work with %20 even if it looks the same as before, in the url bar(in firefox 47.0.1)!
And in chromium(54.0.2815.0), clicking the anchor does show up in url bar with %20 !! Good stuff!

EDIT2: worth knowing: https://stackoverflow.com/questions/16573774/in-page-anchors-with-spaces-in-the-title/16573847#16573847
I suppose %20 isn't considered space in that context, so that's good.

EDIT3: cool! it works as I want it to! PR shortly.

azerupi added a commit that referenced this issue Jul 31, 2016
Fixes #156 - anchors are now URI encoded
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