From 2ef58d8b59e32854f936b795e624ddba3a74a144 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 17 May 2026 22:01:30 +0200 Subject: [PATCH] Better table cell truncation method --- RNS/Utilities/rngit/util.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/RNS/Utilities/rngit/util.py b/RNS/Utilities/rngit/util.py index 04f9330d..435bd888 100644 --- a/RNS/Utilities/rngit/util.py +++ b/RNS/Utilities/rngit/util.py @@ -689,16 +689,18 @@ class MarkdownToMicron: def _truncate_cell(self, text, width): if self._visible_width(text) <= width: return text - - stripped = text - stripped = re.sub(r'`[FB][0-9a-fA-F]{3}', '', stripped) - stripped = re.sub(r'`[!*_]', '', stripped) - stripped = re.sub(r'`f`b', '', stripped) - - if len(stripped) <= width - 1: return text - - truncated = stripped[:width - 1] + "…" - return truncated + + truncation_point = len(text) + while truncation_point > 0 and self._visible_width(text[0:truncation_point]) >= width: + truncation_point -= 1 + + truncated = text[:truncation_point] + + # TODO: Track opened tags and close any that + # were not closed yet. + + RNS.log(f"Truncated: {truncated}") + return truncated + "…" def _wrap_text(self, text, width): if not text: return [""]