-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Trim anchors #8
Comments
They are not, though.. just that every user happens to use it this way |
Relevant ongoing work: |
Yep, with the changes in the mentioned PR, it could be possible to change the anchor of objects while retaining the complete identifier for cross-refs. |
Gotcha, I guess I shall keep an eye on future releases then! Thanks! |
Hm so this is nice and all, but that makes it impossible to distinguish class methods and instance methods. This would be some solution to distinguish them, although still looking rather weird:
Because I think you're suggesting basically
|
Easiest fix would be just do what the stdlib doc generator docs and do something like: id=def.abs_id | replace("%s#" % obj.abs_id, 'instance-') | replace("%s." % obj.abs_id, 'class-') Then you'd end up with EDIT: Or add it at the end 🤷. Either or. |
@pawamoy If I have a heading with this id: Then I want this to remain the global identifier, but the actual local id to become: So I need to suppress |
I'm not sure to understand. IIUC, this is what we currently have:
Docstring summary.
## Usage notes
[Link to usage notes](#usage-notes).
<p>Docstring summary.</p>
<h4 id="Foo::Bar--usage-notes">Usage notes</h4>
<p><a href="#Foo::Bar--usage-notes">Link to usage notes</a></p>
|
Right but the request is to have it become <h4 id="usage-notes">Usage notes</h4> but the need to have a globally linkable identifier still remains |
I'm not sure a subheading (a heading in a docstring) can ever retain just its slug as id ( Unless we're documenting |
The parent's id is not so important, sure it needs to be at least The point that this issue is trying to make is that this is redundant:
|
Yes the point is about the usage where the item is documented on its own on the page. As much as we say that it's not necessarily the case, I'm guessing 95%+ of usages are like that |
Yeah, right. Then we must add aliases with FQN above headings, so that autorefs registers those and redirects to the headings with short ids. So I think the two mkdocstrings filters |
There's also the really nasty case
|
Alternatively we could say that people who are so certain about the page paths should just forfeit the autorefs syntax and use normal links (absolute links will work properly in the next mkdocs release) |
Hmmm, I think it's feasible. If we pass both the FQN and the current path (left part of the FQN down to where we are in terms of page tree): <p>Docstring summary.</p>
<!-- Foo::Bar - Foo::Bar = "" -->
<a id="Foo::Bar--usages-notes"></a>
<h4 id="usage-notes">Usage notes</h4>
<p><a href="#usage-notes">Link to usage notes</a></p>
<!-- Foo::Bar.some_method - Foo::Bar = some_method -->
<a id="Foo::Bar.some_method"></a>
<h4 id="some_method">some method</h4>
<p>Some method summary.</p>
<a id="Foo::Bar.some_method--usages-notes"></a>
<h4 id="some_method--usage-notes">Usage notes</h4>
<p><a href="#some_methhod--usage-notes">Link to usage notes</a></p> |
Aha. It's definitely doable somehow and I was almost able to finish coding all this, but it just becomes super complicated |
That's what I meant by "a bit more work" in the autorefs PR hahah |
I don't think it's that complicated. Computing names relative to other names seems however to depend on the language (different separators), so this would need some kind of hook between mkdocstrings and the handlers... and yeah that part complicates things.
|
I will say I'd be okay with this. For my specific use case I think I'd have to do this anyway to link something from one component to another, unless something is done to integrate https://squidfunk.github.io/mkdocs-material/plugins/projects/. |
Actually if handlers can expose a path components on objects (string tuple), no need for a hook:
If we can infer we're down to This would be language-agnostic. |
I think the main difficulty is still here We are still relying on "autorefs" to scan the headings, and it is hardcoded to look at |
Argh, my brain is exploding. IIUC, headings in docstrings are solved (see previous comments, and thanks to the fact that the autorefs extension also runs when converting docstrings from markdown to html). The remaining issue is for headings generated by mkdocstrings itself with its So, one solution would be to somehow call autorefs' register methods directly from our |
After taking a good, serious look at everything again, it turns out that the These latter headings (API object headings and their subheadings in docstrings) are registered directly from within our mkdocstrings outer extension, in Note that autorefs in full-mode (listed in mkdocs.yml Three examples. Example 1, with root object heading:
This will cause issues if there are other non-API-object Example 2, with root object sub-heading:
This will cause issues too if there are other non-API-object Example 3, with sub-object sub-heading:
This one is less problematic because users are not supposed to try and cross-reference something using the short Conclusion: we have to find a way to prevent autorefs from registering short anchors again. For the implementation itself of trimmed anchors:
|
Currently when you permalink to a specific method within a type, the anchor includes the FQN of the type itself. Such that you end up with really long redundant URLs. E.g. https://athenaframework.org/Framework/Controller/ValueResolvers/RequestAttribute/#Athena::Framework::Controller::ValueResolvers::RequestAttribute#initialize.
Given the anchors are already isolated to the page itself, would it not be enough to just sub out the type name from the
id
of the method (and related types)? E.g. something like:Where I updated the method to be referenced as
def
such that the type can still be accessed viaobj
.The text was updated successfully, but these errors were encountered: