Skip to content

Commit

Permalink
Handle empty tags
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvanrun committed Dec 20, 2024
1 parent 2378384 commit 5210a63
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/grandchallenge/core/utils/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def decode(self, **kwargs):
class ExtendHTMLTagClasses:
def __init__(self, tag_classes):
# Make extensions safe
self.tag_class_dict = {
self.clean_tag_classes = {
t: [escape(c).strip() for c in classes]
for t, classes in tag_classes.items()
}
Expand All @@ -39,12 +39,14 @@ def __call__(self, html):

soup = BeautifulSoupWithCharEntities(markup=html)

for element in soup.find_all(self.tag_class_dict.keys()):
classes = element.get("class", [])
for new_class in self.tag_class_dict[element.name]:
if new_class not in classes:
classes.append(new_class)
element["class"] = classes
tags = [*self.clean_tag_classes.keys()]
if tags:
for element in soup.find_all(tags):
classes = element.get("class", [])
for new_class in self.clean_tag_classes[element.name]:
if new_class not in classes:
classes.append(new_class)
element["class"] = classes

new_markup = soup.decode()

Expand Down

0 comments on commit 5210a63

Please sign in to comment.