Skip to content

Commit

Permalink
Merge pull request #195 from canonical/nested-heading-fix
Browse files Browse the repository at this point in the history
bug: Fix bug where if a code block is nested in the heading it gets duplicated
  • Loading branch information
petesfrench authored Jul 4, 2024
2 parents 64be0f4 + e8699b2 commit a4eb1b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions canonicalwebteam/discourse/parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,12 +848,14 @@ def _add_anchor_links(self, soup):
for heading in soup.find_all(["h2", "h3"]):
anchor = heading.find("a", class_="anchor")
if anchor:
heading_text = heading.get_text()
heading_children = [
child for child in heading.children if child != anchor
]
anchor.clear()
anchor.append(BeautifulSoup(heading_text, "html.parser"))
for child in heading_children:
anchor.append(child)
anchor["class"] = "p-link--anchor-heading"
for content in heading.contents:
if isinstance(content, NavigableString):
content.replace_with("")
heading.clear()
heading.append(anchor)

return soup
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name="canonicalwebteam.discourse",
version="5.6.0",
version="5.6.1",
author="Canonical webteam",
author_email="[email protected]",
url="https://github.com/canonical/canonicalwebteam.discourse",
Expand Down

0 comments on commit a4eb1b1

Please sign in to comment.