-
Notifications
You must be signed in to change notification settings - Fork 317
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
Show methods and properties of autoclass in right column. #215
Comments
That sounds like an interesting idea, we just hit a similar issue and this would solve it. Are there any plans already for this? |
Hi, me too use this great theme to generate documentation for python modules. Like @SebastianJL wrote, it would be really awesome to use just The README says it uses I am a bloody beginner in this area so any help is appreciated :) |
I've been having a bit of a dabble with this I created a new template like
And then in your pydata theme you need to add a snippet like
This gives me something like Hope that helps somebody |
Hello, def _setup_navbar_side_toctree(app: Any):
def add_class_toctree_function(app: Any, pagename: Any, templatename: Any, context: Any, doctree: Any):
def get_class_toc() -> Any:
soup = BeautifulSoup(context["body"], "html.parser")
matches = soup.find_all('dl')
if matches is None or len(matches) == 0:
return ""
items = []
deeper_depth = matches[0].find('dt').get('id').count(".")
for match in matches:
match_dt = match.find('dt')
if match_dt is not None and match_dt.get('id') is not None:
current_title = match_dt.get('id')
current_depth = match_dt.get('id').count(".")
current_link = match.find(class_="headerlink")
if current_link is not None:
if deeper_depth > current_depth:
deeper_depth = current_depth
if deeper_depth == current_depth:
items.append({
"title": current_title,
"link": current_link["href"],
"attributes_and_methods": []
})
if deeper_depth < current_depth:
items[-1]["attributes_and_methods"].append(
{
"title": current_title,
"link": current_link["href"],
}
)
return items
context["get_class_toc"] = get_class_toc
app.connect("html-page-context", add_class_toctree_function)
def setup(app: Any):
for setup_function in [
_setup_navbar_side_toctree,
]:
setup_function(app) and add add the folowing entry in "page_sidebar_items": ["page-toc", "class-page-toc"], and add the following html in template: {% set class_toc = get_class_toc() %}
<nav id="bd-toc-nav", style="padding-top: 1rem;">
<ul class="visible nav section-nav flex-column">
{% for item in class_toc %}
<li class="toc-h1 nav-item toc-entry">
<a class="reference internal nav-link" href="{{ item.link }}">{{ item.title }}</a>
</li>
<ul class="visible nav section-nav flex-column">
{% for attr in item.attributes_and_methods %}
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="{{ attr.link }}">{{ attr.title }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
</ul>
</nav> |
@choldgraf, do you know if we have some snippets/recipes/wiki section to collect these examples from the community? |
@damianavila, I think github issues are well rferenced on Google so someone with the same need would ends up here eventually. I'm not sure we should duplicate them in the doc. |
It seems Furo is integrating it in its secondary sidebar, we should do it as well: |
I think that this works on our site now, no? I see this rST on the API page here.
and here's what it looks like: I'm going to close this assuming it now works, but please re-open if it doesn't work on |
ReopenI'd like to reopen this issue because:
Updated SolutionTo show class methods and attributes/inner function, we need to set html_theme_options = {
"show_toc_level": 2 # can increase, e.g., if there are nested classes
} Which gives the following look: Feature RequestThere are still 2 problems I face and I wonder if these could be addressed:
WorkaroundThe current workaround (for level 2 page-toc) is to add the following code to from pathlib import Path
from bs4 import BeautifulSoup
def process_in_page_toc(app, exception):
if app.builder.format != "html":
return
for pagename in app.env.found_docs:
if not isinstance(pagename, str):
continue
with (Path(app.outdir) / f"{pagename}.html").open("r") as f:
# Parse HTML using BeautifulSoup html parser
soup = BeautifulSoup(f.read(), "html.parser")
for li in soup.find_all("li", class_="toc-h3 nav-item toc-entry"):
if span := li.find("span"):
# Modify the toc-nav span element here
span.string = span.string.split(".")[-1]
with (Path(app.outdir) / f"{pagename}.html").open("w") as f:
# Write back HTML
f.write(str(soup))
def setup(app):
app.connect("build-finished", process_in_page_toc) |
This is related with the anchors created by autosummary and the reason why you are not seeing them is because the scrollspy function from Bootstrap is not catching anchors with ".". We're trying to find a solution and we are discussing the problem in #1435 |
I am using pydata-sphinx-theme for the documentation of zfit. (The new version with the pydata theme can be found in the version doc_redesign).
Now it would be very useful to automatically list the methods and properties of a class in the right column without having to write a manual header for each section. I.e.
Instead of
So my question now is:
Is this already possible? And if not would we have to change something about pydata theme or does this change have to be made in autodoc, i.e. generating headers for methods.
I am happy to help with implementation if you give me some guidance.
The text was updated successfully, but these errors were encountered: