From 4db6e27abc2f69ca07017e97ad6c5d8701de630a Mon Sep 17 00:00:00 2001 From: mags0ft <113589312+mags0ft@users.noreply.github.com> Date: Thu, 6 Feb 2025 23:52:21 +0100 Subject: [PATCH 1/2] Fix bug causing code blocks to be rendered inconsistently This commit should fix issue #526 (https://github.com/Jeffser/Alpaca/issues/526). --- src/custom_widgets/message_widget.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/custom_widgets/message_widget.py b/src/custom_widgets/message_widget.py index 8ae0837..f953f86 100644 --- a/src/custom_widgets/message_widget.py +++ b/src/custom_widgets/message_widget.py @@ -806,15 +806,25 @@ def set_text(self, text:str=None): pos = 0 for pattern_name, pattern in patterns: for match in pattern.finditer(self.text[pos:]): - start, end = match.span() - if pos < start + pos: - normal_text = self.text[pos:start+pos] + match_start, match_end = match.span() + + if pos < (match_start): + normal_text = self.text[pos:(match_start)] parts.append({"type": "normal", "text": normal_text.strip()}) - if pattern_name == 'code': - parts.append({"type": pattern_name, "text": match.group(2), "language": match.group(1)}) + + if pattern_name == "code": + parts.append( + { + "type": pattern_name, + "text": match.group(2), + "language": match.group(1), + } + ) else: parts.append({"type": pattern_name, "text": match.group(1)}) - pos += end + + pos = match_end + # Text blocks if pos < len(self.text): normal_text = self.text[pos:] From a4eb84d66986f3724d1ecfa1e1d43dfa6a9060a6 Mon Sep 17 00:00:00 2001 From: mags0ft <113589312+mags0ft@users.noreply.github.com> Date: Fri, 7 Feb 2025 00:12:23 +0100 Subject: [PATCH 2/2] patch out broken table rendering --- src/custom_widgets/message_widget.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/custom_widgets/message_widget.py b/src/custom_widgets/message_widget.py index f953f86..ff7eecf 100644 --- a/src/custom_widgets/message_widget.py +++ b/src/custom_widgets/message_widget.py @@ -820,6 +820,8 @@ def set_text(self, text:str=None): "language": match.group(1), } ) + elif pattern_name == "table": + parts.append({"type": pattern_name, "text": text[match_start:match_end]}) else: parts.append({"type": pattern_name, "text": match.group(1)})