From c1f196bc59a46378ab366f1a8a9513d7a499b1e3 Mon Sep 17 00:00:00 2001 From: Griatch Date: Tue, 15 Feb 2022 23:23:26 +0100 Subject: [PATCH] Fix web client invisible-double space error. Resolve #2532 --- evennia/utils/text2html.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/evennia/utils/text2html.py b/evennia/utils/text2html.py index 7adfdfdd8e..0b5f691599 100644 --- a/evennia/utils/text2html.py +++ b/evennia/utils/text2html.py @@ -102,6 +102,7 @@ class TextToHTMLparser(object): re.S | re.M | re.I, ) re_dblspace = re.compile(r" {2,}", re.M) + re_invisiblespace = re.compile(r"( <.*?>)( )") re_url = re.compile( r'(?\[\]\s])+)(\.(?:\s|$)|&\w+;|)' ) @@ -271,6 +272,13 @@ class TextToHTMLparser(object): """ return self.re_dblspace.sub(self.sub_dblspace, text) + def re_invisible_space(self, text): + """ + If two spaces are separated by an invisble html element, they act as a + hidden double-space and the last of them should be replaced by   + """ + return self.re_invisiblespace.sub(self.sub_invisiblespace, text) + def sub_mxp_links(self, match): """ Helper method to be passed to re.sub, @@ -336,6 +344,10 @@ class TextToHTMLparser(object): "clean up double-spaces" return " " + " " * (len(match.group()) - 1) + def sub_invisiblespace(self, match): + "clean up invisible spaces" + return match.group(1) + " " + def parse(self, text, strip_ansi=False): """ Main access function, converts a text containing ANSI codes @@ -347,7 +359,10 @@ class TextToHTMLparser(object): Returns: text (str): Parsed text. + """ + # print(f"incoming ansi:\n{text}") + # parse everything to ansi first text = parse_ansi(text, strip_ansi=strip_ansi, xterm256=True, mxp=True) # convert all ansi to html @@ -364,8 +379,9 @@ class TextToHTMLparser(object): result = self.remove_backspaces(result) result = self.convert_urls(result) result = self.re_double_space(result) + result = self.re_invisible_space(result) # clean out eventual ansi that was missed - # result = parse_ansi(result, strip_ansi=True) + ## result = parse_ansi(result, strip_ansi=True) return result