Skip to content

Commit

Permalink
Fix html_tags validate function
Browse files Browse the repository at this point in the history
  • Loading branch information
neoformit committed Jan 4, 2025
1 parent ab16330 commit 4f79290
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/labs/lab_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ def html_tags(value: str) -> str:
if "<" not in value:
return value
# Remove self closing tags
value = (
value_stripped = (
re.sub(r'(<.*?/>)|(<img.*?>)', '', value, flags=re.MULTILINE)
.replace('<br>', '')
.replace('<hr>', '')
)
# Enumerate open/close tags
open_tags = re.findall(r'<[^/][\s\S]*?>', value, flags=re.MULTILINE)
close_tags = re.findall(r'</[\s\S]*?>', value, flags=re.MULTILINE)
open_tags = re.findall(
r'<[^/][\s\S]*?>', value_stripped, flags=re.MULTILINE)
close_tags = re.findall(
r'</[\s\S]*?>', value_stripped, flags=re.MULTILINE)
assert len(open_tags) == len(close_tags), (
f'Unclosed HTML tag in section content:\n{value}')
return value

0 comments on commit 4f79290

Please sign in to comment.