Skip to content

Commit

Permalink
fix: add desc nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Revathyvenugopal162 committed Oct 24, 2024
1 parent 3040dac commit f3b59bd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/ansys_sphinx_theme/search/fuse_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import re

from docutils import nodes
from docutils.nodes import Element

PARAGRAPHS = [nodes.paragraph]
TITLES = [nodes.title]
Expand Down Expand Up @@ -60,6 +61,15 @@ def __init__(self, doc_name, app, pattern=None):
def build_sections(self):
"""Build sections from the document tree."""
for node in self.doc_tree.traverse(nodes.section):
subsections = list(node.traverse(nodes.section))
if len(subsections) > 1:
# get only the first section
main_section = subsections[0]
# remove subsections from the main section
for n in main_section.traverse(nodes.section):
n.parent.remove(n)
node = main_section

section_title = node[0].astext()

section_text = "\n".join(
Expand All @@ -75,6 +85,19 @@ def build_sections(self):
}
)

for n in node.traverse(Element):
if n.tagname == "desc":
section_title = n[0].astext()
section_anchor_id = _dec_title_to_anchor(section_title)
section_text = n.astext()
self.sections.append(
{
"title": section_title,
"text": section_text,
"anchor_id": section_anchor_id,
}
)

def generate_breadcrumbs(self, section_title: str) -> str:
"""
Generate title breadcrumbs from the document structure.
Expand Down Expand Up @@ -129,6 +152,12 @@ def indices(self):
}


def _dec_title_to_anchor(title: str) -> str:
"""Convert title to anchor for the description."""
# remove () at the end
return re.sub(r"\(.*\)$", "", title)


def _title_to_anchor(title: str) -> str:
"""Convert a title to a URL-friendly anchor identifier."""
return re.sub(r"[^\w\s-]", "", title.lower().strip().replace(" ", "-"))
Expand Down

0 comments on commit f3b59bd

Please sign in to comment.