TkinterWeb
TkinterWeb copied to clipboard
Internal hrefs not working in Linux
I'm using tkinterweb to display a help file in my app. The help has a table of contents, containing internal hrefs:
<a href="#penguins">Penguins are great!</a>
and farther on
<h2 id="penguins">Penguins</h2>
In Windows this works as expected: clicking the link jumps to the relevant section. In Linux, I get "Oops! The document could not be found." I tried using name="penguins" instead of "id" but no joy there. Any idea what's going wrong?
UPDATE: the following technique kind of achieves the intended effect:
<a href="./this_document.html#penguins">Penguins are great!</a>
I assume it just reloads the current document at the specified ID, but ideally it should be possible to do a jump without reloading.
Thanks!
Hi!
Thanks for letting me know about this. There are a couple of issues that might be causing this.
I have noticed that due to some weird urllib
behaviour, on Linux urls with four slashes will load, but get converted into an illegal url when combining them with a url fragment (i.e. #penguins
).
You can try this yourself. Run from urllib.parse import urljoin
. If you run urljoin("file:////path/to/file.html", "#penguins")
you will get file://path/to/file.html#penguins
, which is an considered an illegal url by urllib
. Meanwhile, if you run urljoin("file:////path/to/file.html", "./file.html/#penguins")
, you will get file:///path/to/file.html#penguins
, which is a proper url.
You won't notice this on Windows because on Windows, a url that starts with file:////
is not recognized as a proper url in the first place.
This would be my best guess at what is happening. Make sure your url starts with three slashes (i.e. file:///
) and see if you still find this issue
I agree that this behaviour is not ideal. I will look into a workaround.
EDIT: I made a quick workaround that seems to do the trick. Try updating TkinterWeb and let me know if the issue persists.
I have also noticed that url fragments do not work when using load_html
. I just resolved this issue. If the above doesn't fix the issue for you, you could could also try upgrading TkinterWeb and see if this issue still persists.
Hope this helps!