Open 0giso opened 6 years ago
@agjohnson you are the javascript guy
var anchor = window.location.hash;
Sorry, that worked only with Edge and IE.
This may be just a workaround, but the code below works with Edge, IE, Chrome.
var anchor = decodeURI(window.location.hash);
Yes, I think that decodeURI
is more correct than encodeURI
. For the test string ёђѓєѕіїјљњћќўџабвг
, the value of window.location.hash
is:
Firefox: %D1%91%D1%92%D1%93%D1%94%D1%95%D1%96%D1%97%D1%98%D1%99%D1%9A%D1%9B%D1%9C%D1%9E%D1%9F%D0%B0%D0%B1%D0%B2%D0%B3
Chromium: ёђѓєѕіїјљњћќўџабвг
With encodeURI(window.location.hash)
:
Firefox: %25D1%2591%25D1%2592%25D1%2593%25D1%2594%25D1%2595%25D1%2596%25D1%2597%25D1%2598%25D1%2599%25D1%259A%25D1%259B%25D1%259C%25D1%259E%25D1%259F%25D0%25B0%25D0%25B1%25D0%25B2%25D0%25B3
Chromium: %D1%91%D1%92%D1%93%D1%94%D1%95%D1%96%D1%97%D1%98%D1%99%D1%9A%D1%9B%D1%9C%D1%9E%D1%9F%D0%B0%D0%B1%D0%B2%D0%B3
In other words, in Firefox it gets encoded twice. The alternative is to find a more cross-platform alternative to window.location.hash
but decodeURI
seems to work in the meantime.
@jessetan
@0giso do you still encounter this problem? Do you have a testcase we can see? I originally fixed this in PR #615, without checking if the original Firefox bug was still there. But just like @davidfischer in https://github.com/rtfd/sphinx_rtd_theme/pull/615#issuecomment-383160744, I no longer see any difference between Chrome and Firefox behavior on macOS. If the original Firefox bug was solved, we can close this and discard the PR.
@jessetan I am not sure #615 can fix or not this problem, but I created test case to reproduce the issue. https://github.com/0giso/testcase_for_sphinx_rtd_theme_issue495
It use sphinx_rtd_theme installed by pip.
Thanks for the testcase. Can you explain the need for the unicode_ids extension? If I remove it, the TOC works correctly.
I need unicode_ids extension for non-English markdown document because if I don't use it, sphinx with recommonmark ignore non-English character in section title, then section hyper link url ends with '#' (no url fragment appended).
I updated the test case as below to show unicode_ids necessity.
Thank you.
Sphinx with recommonmark does not use unicode text header as page link's anchor, just ignore them. If the header is written by unicode text only, anchor is empty like "http://example.com/foo.html#". So I use unicode_ids extension to generate unicode anchor text from header.
In that case, navigation to 3rd or below level get fall back to top level content and toc tree collapsed, because sphinx_rtd_theme try to find URI escaped anchor and fail.
Change theme.js from
var anchor = encodeURI(window.location.hash);
tovar anchor = window.location.hash;
worked for me. Is this acceptable change?