-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[singlehtml] add docname to section anchor to make them unique #13739
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
base: master
Are you sure you want to change the base?
Conversation
e6b65fb
to
5117057
Compare
Hi @gastmaier - I'm a former semi-regular volunteer contributor here, although I have been less active recently. Thanks for the pull request; and sorry that I did not notice the toctree constructor problem, as you mention in #13717. I am reading both #13717 and this PR #13739 to try to understand the different approaches and reasons for them. Also: do you have a test case that we could add under |
Hi @jayaddison maybe extending tests/test_builders/test_build_html_tocdepth.py |
@gastmaier that sounds perfect, yep! (I'd forgotten about those tests) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align with purpose
To assert unique ids in singlehtml builder. Signed-off-by: Jorge Marques <[email protected]>
c50ba56
to
910de47
Compare
Hi, @jayaddison and @akhilsmokie7-cloud I rebased and added the test to check for duplicated ids. I added the test to the bottom, checking out fe728f4 will fail at
as expected, since at f5457f1 On, "the html build also changes the images src path during the write step", this is what I am talking about CI note:
is due to 2e51b787680cefdfe56b3438d809e6476600a47e Thanks, |
Since the singlehtml aggregates all doc files into a single html page during the write step, and the ids must be unique for proper link anchoring, add test that collects all ids in the page and checks if all ids are unique, by asserting the length of the list against it as a set.
And use modified id directly, modified in the previous commit to ensure unique id in singlehtml.
Purpose
Follow up to #13717, inverting the logic, instead of patching the toctree to yield "#id1" instead of "#document-path/to#id1", have the section id to be docname preffixed, solving non-unique ids in singlehtml.
Allows to remove post Sphinx transforms like in here
Top level overview of current behavior
Approach taken
Based on the LaTeX builder solution.
sphinx/writers/latex.py#hypertarget[withdoc=True]
method suffixes docutils id with the docname.In my implementation I edit ids['0'] directly to not have to overwrite the whole
visit_section
method, but I understand if requested to not modify the tree and instead overwrite.On the format #document-test/extra#id1
It is compatible with HTML anchoring, CSS and JavaScript selectors, but require escaping:
Tests
The following tests are relevant:
References