-
-
Notifications
You must be signed in to change notification settings - Fork 119
Add module name to doc source (to allow intersphinx usage) #346
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
Conversation
Is there any way to add redirects for those, that you know of? |
Not that I'm aware of. I tried manually inserting a target (which Sphinx/rST terminology for an anchor): .. _NamedTuple:
.. class:: NamedTuple
See :py:class:`typing.NamedTuple`. Even putting aside how much clutter this would add, it doesn't work: Sphinx lower cases the label, so you can link to |
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.
It's a shame about the anchors, but I think this is worth it for intersphinx. LGTM, but I'll wait to see if any other maintainers object.
@CAM-Gerlach, if you have the time -- do you know any way of preserving the anchors here or easily adding redirects, by any chance? |
Actually I spoke too soon – I found a way to fix up the HTML by delving into Sphinx's more advanced customisation points. Adding this to the end of from sphinx.writers.html import HTMLTranslator
from docutils.nodes import Element, Node, Text
class MyTranslator(HTMLTranslator):
def visit_desc_signature(self, node: Element) -> None:
desc_name = node.get("fullname")
if desc_name:
self.body.append(f'<span id="{desc_name}"></span>')
super().visit_desc_signature(node)
def setup(app):
app.set_translator('html', MyTranslator) It links a few pixels too high compared to the real anchors but I don't think that's a big deal. And it doesn't do anything for Any thoughts? |
Thanks for looking into it! That seems worth it to me; it's not too much added complexity to our |
OK I added that code in a new commit. (I also removed the line of config that referenced the non-existent |
Could you fix the lint issue in CI? (Probably just run Black on conf.py.) |
@JelleZijlstra I think this fixes it. Also I realised that I used a slightly wrong class from Sphinx ( |
Thank you! 🎉 |
Fixes #341. With this change,
typing_extensions
can be used from other libraries' documentation via intersphinx.I included
add_module_names = False
, which means that thetyping_extensions.
prefix will not show up in the docs before identifiers, because that was the consensus on the issue report.However, while testing I did notice another: even with that setting turned on, the anchors are still changed to include the prefix. For example:
That will break any existing external pages that link directly to an anchor within the docs.