undo that shit

pull/36245/head
Shane Smiskol 5 days ago
parent c3311e5241
commit ef3564145b
  1. 31
      system/ui/widgets/html_render.py

@ -73,36 +73,25 @@ class HtmlRenderer(Widget):
html_content = re.sub(r'<!DOCTYPE[^>]*>', '', html_content) html_content = re.sub(r'<!DOCTYPE[^>]*>', '', html_content)
html_content = re.sub(r'</?(?:html|head|body)[^>]*>', '', html_content) html_content = re.sub(r'</?(?:html|head|body)[^>]*>', '', html_content)
# Find all HTML elements and also render text nodes outside tags as paragraphs # Find all HTML elements
pattern = r'<(h[1-6]|p)(?:[^>]*)>(.*?)</\1>|<br\s*/?>' pattern = r'<(h[1-6]|p)(?:[^>]*)>(.*?)</\1>|<br\s*/?>'
matches = list(re.finditer(pattern, html_content, re.DOTALL | re.IGNORECASE)) matches = re.finditer(pattern, html_content, re.DOTALL | re.IGNORECASE)
def _add_text_node_as_paragraph(text: str) -> None:
txt = re.sub(r'\s+', ' ', text).strip()
if txt:
self._add_element(ElementType.P, txt)
last_end = 0
for match in matches: for match in matches:
# Add any plain text between previous end and this match as a paragraph
if match.start() > last_end:
_add_text_node_as_paragraph(html_content[last_end:match.start()])
if match.group(0).lower().startswith('<br'): if match.group(0).lower().startswith('<br'):
# Handle <br> tags
self._add_element(ElementType.BR, "") self._add_element(ElementType.BR, "")
else: else:
tag = match.group(1).lower() tag = match.group(1).lower()
content = match.group(2) content = match.group(2).strip()
content = re.sub(r'\s+', ' ', content).strip()
if content:
element_type = ElementType(tag)
self._add_element(element_type, content)
last_end = match.end() # Clean up content - remove extra whitespace
content = re.sub(r'\s+', ' ', content)
content = content.strip()
# Trailing text after the last tag if content: # Only add non-empty elements
if last_end < len(html_content): element_type = ElementType(tag)
_add_text_node_as_paragraph(html_content[last_end:]) self._add_element(element_type, content)
def _add_element(self, element_type: ElementType, content: str) -> None: def _add_element(self, element_type: ElementType, content: str) -> None:
style = self.styles[element_type] style = self.styles[element_type]

Loading…
Cancel
Save