Fix web client invisible-double space error. Resolve #2532
This commit is contained in:
parent
1b2c777fc4
commit
c1f196bc59
1 changed files with 17 additions and 1 deletions
|
|
@ -102,6 +102,7 @@ class TextToHTMLparser(object):
|
||||||
re.S | re.M | re.I,
|
re.S | re.M | re.I,
|
||||||
)
|
)
|
||||||
re_dblspace = re.compile(r" {2,}", re.M)
|
re_dblspace = re.compile(r" {2,}", re.M)
|
||||||
|
re_invisiblespace = re.compile(r"( <.*?>)( )")
|
||||||
re_url = re.compile(
|
re_url = re.compile(
|
||||||
r'(?<!=")((?:ftp|www|https?)\W+(?:(?!\.(?:\s|$)|&\w+;)[^"\',;$*^\\(){}<>\[\]\s])+)(\.(?:\s|$)|&\w+;|)'
|
r'(?<!=")((?:ftp|www|https?)\W+(?:(?!\.(?:\s|$)|&\w+;)[^"\',;$*^\\(){}<>\[\]\s])+)(\.(?:\s|$)|&\w+;|)'
|
||||||
)
|
)
|
||||||
|
|
@ -271,6 +272,13 @@ class TextToHTMLparser(object):
|
||||||
"""
|
"""
|
||||||
return self.re_dblspace.sub(self.sub_dblspace, text)
|
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):
|
def sub_mxp_links(self, match):
|
||||||
"""
|
"""
|
||||||
Helper method to be passed to re.sub,
|
Helper method to be passed to re.sub,
|
||||||
|
|
@ -336,6 +344,10 @@ class TextToHTMLparser(object):
|
||||||
"clean up double-spaces"
|
"clean up double-spaces"
|
||||||
return " " + " " * (len(match.group()) - 1)
|
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):
|
def parse(self, text, strip_ansi=False):
|
||||||
"""
|
"""
|
||||||
Main access function, converts a text containing ANSI codes
|
Main access function, converts a text containing ANSI codes
|
||||||
|
|
@ -347,7 +359,10 @@ class TextToHTMLparser(object):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
text (str): Parsed text.
|
text (str): Parsed text.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# print(f"incoming ansi:\n{text}")
|
||||||
|
|
||||||
# parse everything to ansi first
|
# parse everything to ansi first
|
||||||
text = parse_ansi(text, strip_ansi=strip_ansi, xterm256=True, mxp=True)
|
text = parse_ansi(text, strip_ansi=strip_ansi, xterm256=True, mxp=True)
|
||||||
# convert all ansi to html
|
# convert all ansi to html
|
||||||
|
|
@ -364,8 +379,9 @@ class TextToHTMLparser(object):
|
||||||
result = self.remove_backspaces(result)
|
result = self.remove_backspaces(result)
|
||||||
result = self.convert_urls(result)
|
result = self.convert_urls(result)
|
||||||
result = self.re_double_space(result)
|
result = self.re_double_space(result)
|
||||||
|
result = self.re_invisible_space(result)
|
||||||
# clean out eventual ansi that was missed
|
# clean out eventual ansi that was missed
|
||||||
# result = parse_ansi(result, strip_ansi=True)
|
## result = parse_ansi(result, strip_ansi=True)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue