-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Make it easier for extensions to extend the TocTree directive #7913
Conversation
Could you describe this to me, please? I don't understand what will be changed by this PR. |
OK, I have finally seen this approach through and it's resulted in some things being simpler than I expected, so I think there are now fewer changes to the
|
Thank you for your explanation. Now I understand your idea. I can accept the refactoring of TocTree directive (But I can't promise that will be kept as a public interface in the future). On the other hand, I'm hesitating to change the internal structure of the toctree. Note: I found you could hack the toctree via filling |
I'm afraid it's my turn to ask for clarification or a worked example. |
I just made a hack code to do that.
I believe this might work as your example. But, as commented in above code, I noticed both codes would not work because toctree resolver does not support resolving "pending_xref" node in the toctree. |
I'm not sure what you mean by "the toctree resolver" here, because AIUI sphinx/sphinx/transforms/post_transforms/__init__.py Lines 63 to 71 in e4c3e24
children of the toctree node, so that the .traverse() in the ReferencesResolver would visit it.
|
Rather than the approach taken by sphinx-doc#2354, which would require answering some tricky questions about the entire set of Builders in the known universe, just expose just enough through hooks or overridable routines so that individual instances of Sphinx can splice in their own implementation of this functionality if it is desired.
(Updated commit to try to appease flake8 and mypy. I cannot, sadly, make mypy work locally, so am reduced to guessing and trying CI. Apologies for the noise.) |
Sorry for wrong wording. I meant "TocTree.resolve()".
I still don't try your code yet. But I think |
That matches my understanding: I'm not terribly enthusiastic about munging with sphinx/sphinx/environment/adapters/toctree.py Line 159 in 8cc0b89
looks like it might do the right thing, surely there's going to be a problem that env.metadata won't have a similar key, sosphinx/sphinx/environment/adapters/toctree.py Line 160 in 8cc0b89
will throw a KeyError ? Moreover,sphinx/sphinx/environment/adapters/toctree.py Line 158 in 8cc0b89
means that this fake entry is going to propagate through recursion of _entries_from_toctree . That might be OK, but it's an extrusion of new state.
|
oh, I've missed the code that inserts a node to under the toctree node. Okay, I understand.
Yes, my idea is just a hack. Not a good way. But, as I commented above, I'd not like to change the internal structure of the toctree. So your |
Closing, since I think this approach requires cooperation from the TocTree. |
Rather than the approach taken by #2354,
which would require answering some tricky questions about the entire set
of Builders in the known universe, just expose just enough through hooks or
overridable routines so that individual instances of Sphinx can splice
in their own implementation of this functionality if it is desired.