From ef3564145bcbb62833eef05ed542e8342ab314a5 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 3 Oct 2025 00:20:55 -0700 Subject: [PATCH] undo that shit --- system/ui/widgets/html_render.py | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/system/ui/widgets/html_render.py b/system/ui/widgets/html_render.py index 166818220c..11163bd0aa 100644 --- a/system/ui/widgets/html_render.py +++ b/system/ui/widgets/html_render.py @@ -73,36 +73,25 @@ class HtmlRenderer(Widget): html_content = re.sub(r']*>', '', html_content) html_content = re.sub(r']*>', '', 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)(?:[^>]*)>(.*?)|' - 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: - # 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(' tags self._add_element(ElementType.BR, "") else: tag = match.group(1).lower() - content = match.group(2) - content = re.sub(r'\s+', ' ', content).strip() - if content: - element_type = ElementType(tag) - self._add_element(element_type, content) + content = match.group(2).strip() - 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 last_end < len(html_content): - _add_text_node_as_paragraph(html_content[last_end:]) + if content: # Only add non-empty elements + element_type = ElementType(tag) + self._add_element(element_type, content) def _add_element(self, element_type: ElementType, content: str) -> None: style = self.styles[element_type]