Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Timothée Mazzucotelli <pawamoy@pm.me>
  • Loading branch information
percevalw and pawamoy committed Sep 17, 2023
1 parent 9defd30 commit d06656e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/mkdocstrings/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ class _PostProcessor(Treeprocessor):
def run(self, root: Element) -> None:
self.remove_duplicated_headings_from_parent(root)

def remove_duplicated_headings_from_parent(self, parent: Element) -> bool:
def _remove_duplicated_headings(self, parent: Element) -> bool:
carry_text = ""
found = False
for el in reversed(parent):
for el in reversed(parent): # Reversed mainly for the ability to mutate during iteration.
if el.tag == "div" and el.get("class") == "mkdocstrings":
# Delete the duplicated headings along with their container, but keep the text (i.e. the actual HTML).
carry_text = (el.text or "") + carry_text
Expand All @@ -245,7 +245,7 @@ def remove_duplicated_headings_from_parent(self, parent: Element) -> bool:
elif carry_text:
el.tail = (el.tail or "") + carry_text
carry_text = ""
elif self.remove_duplicated_headings_from_parent(el):
elif self._remove_duplicated_headings(el):
found = True
break
if carry_text:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,11 @@ def test_use_options_yaml_key(ext_markdown: Markdown) -> None:


@pytest.mark.parametrize("ext_markdown", [{"markdown_extensions": [{"pymdownx.tabbed": {"alternate_style": True}}]}], indirect=["ext_markdown"])
def test_tab_headings(ext_markdown: Markdown) -> None:
"""Assert footnotes don't get added to subsequent docstrings."""
def test_removing_duplicated_headings(ext_markdown: Markdown) -> None:
"""Assert duplicated headings are removed from the output."""
output = ext_markdown.convert(
dedent(
"""
Top.[^aaa]
=== "Tab A"
::: tests.fixtures.headings
Expand Down

0 comments on commit d06656e

Please sign in to comment.