Skip to content

Commit

Permalink
[DOCS] Add titles to properties and methods sections in API Reference (
Browse files Browse the repository at this point in the history
…#10821)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
JessSaavedra and pre-commit-ci[bot] authored Jan 17, 2025
1 parent 7d53a90 commit e1a3a29
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/docusaurus/src/css/api_docs/api_docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@
color: var(--ifm-font-color-base);
}
}

h2 {
color: var(--ifm-font-color-base);
font-weight: var(--ifm-font-weight-bold);
}
}
8 changes: 6 additions & 2 deletions docs/sphinx_api_docs_source/build_sphinx_api_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def my_task(
Definition,
get_shortest_dotted_path,
)
from docs.sphinx_api_docs_source.utils import apply_markdown_adjustments
from docs.sphinx_api_docs_source.utils import (
apply_markdown_adjustments,
apply_structure_changes,
)

logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler())
Expand Down Expand Up @@ -220,6 +223,7 @@ def _parse_and_process_html_to_mdx( # noqa: C901
title_str = title_str.replace("#", "")

apply_markdown_adjustments(soup, html_file_path, html_file_contents)
apply_structure_changes(soup, html_file_path, html_file_contents)

sidebar_entry = self._get_sidebar_entry(html_file_path=html_file_path)

Expand Down Expand Up @@ -517,7 +521,7 @@ def _create_class_md_stub(self, definition: Definition) -> str:
.. autoclass:: {dotted_import}
:members:
:inherited-members:
:member-order: groupwise
```
"""

Expand Down
27 changes: 27 additions & 0 deletions docs/sphinx_api_docs_source/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,30 @@ def apply_markdown_adjustments(soup, html_file_path, html_file_contents): # noq
if lengthChildren > 0:
item.insert(0, "\r\n")
item.append("\r\n")


def apply_structure_changes(soup, html_file_path, html_file_contents):
# Add h2 title to Methods section
methods = soup.select(".py.method")
if methods:
add_section_title(soup, methods, "Methods")

# Add h2 title to Properties section
properties = soup.select(".py.property")
if properties:
add_section_title(soup, properties, "Properties")


def add_section_title(soup, items, title):
wrapper_div = soup.new_tag("div")
title_h2 = soup.new_tag("h2")
title_h2.string = title
parent = items[0].parent

for item in items:
wrapper_div.append(item.extract())

wrapper_div.insert(0, "\r\n")
wrapper_div.insert(1, title_h2)
wrapper_div.insert(2, "\r\n")
parent.insert_after(wrapper_div)
Original file line number Diff line number Diff line change
Expand Up @@ -2244,13 +2244,13 @@ def build_data_docs(
URLs of the sites that *would* be built, but it does not build
these sites.
build_index: a flag if False, skips building the index page
Returns:
A dictionary with the names of the updated data documentation sites as keys and the location info
of their index.html files as values
Raises:
ClassInstantiationError: Site config in your Data Context config is not valid.
""" # noqa: E501 # FIXME CoP
return self._build_data_docs(
site_names=site_names,
Expand Down

0 comments on commit e1a3a29

Please sign in to comment.