Fixed a webclient issue that caused urls to loose their following whitespace.

This commit is contained in:
Griatch 2012-02-20 23:25:22 +01:00
parent c56ede0fa2
commit 6d73b05d91
2 changed files with 19 additions and 17 deletions

View file

@ -74,7 +74,7 @@ def create_objects():
limbo_obj.id = 2 limbo_obj.id = 2
string = " ".join([ string = " ".join([
"Welcome to your new {wEvennia{n-based game. From here you are ready to begin development.", "Welcome to your new {wEvennia{n-based game. From here you are ready to begin development.",
"If you should need help or would like to participate in community discussions, visit http://evennia.com.", "Visit http://evennia.com if you should need help or would like to participate in community discussions.",
"If you are logged in as User #1 you can create a demo/tutorial area with '@batchcommand contrib.tutorial_world.build'.", "If you are logged in as User #1 you can create a demo/tutorial area with '@batchcommand contrib.tutorial_world.build'.",
"Log out and create a new non-admin account at the login screen to play the tutorial properly."]) "Log out and create a new non-admin account at the login screen to play the tutorial properly."])
string = _(string) string = _(string)

View file

@ -37,7 +37,7 @@ class TextToHTMLparser(object):
normalcode = '\033[0m' normalcode = '\033[0m'
tabstop = 4 tabstop = 4
re_string = re.compile(r'(?P<htmlchars>[<&>])|(?P<space>^[ \t]+)|(?P<lineend>\r\n|\r|\n)|(?P<protocol>(^|\s)((http|ftp)://.*?))(\s|$)', re_string = re.compile(r'(?P<htmlchars>[<&>])|(?P<space>^[ \t]+)|(?P<lineend>\r\n|\r|\n)',#|(?P<protocol>(^|\s)((http|ftp)://.*?))(\s|$)',
re.S|re.M|re.I) re.S|re.M|re.I)
def re_color(self, text): def re_color(self, text):
@ -79,7 +79,7 @@ class TextToHTMLparser(object):
def convert_urls(self, text): def convert_urls(self, text):
"Replace urls (http://...) by valid HTML" "Replace urls (http://...) by valid HTML"
regexp = r"((ftp|www|http)(\W+\S+[^).,:;?\]\}(\<span\>) \r\n$]+))" regexp = r"((ftp|www|http)(\W+\S+[^).,:;?\]\}(\<span\>) \r\n$]+))"
return re.sub(regexp, r'<a href="\1">\1</a>', text) return re.sub(regexp, r'<a href="\1">\1</a> ', text)
def do_sub(self, m): def do_sub(self, m):
"Helper method to be passed to re.sub." "Helper method to be passed to re.sub."
@ -88,23 +88,26 @@ class TextToHTMLparser(object):
return cgi.escape(c['htmlchars']) return cgi.escape(c['htmlchars'])
if c['lineend']: if c['lineend']:
return '<br>' return '<br>'
elif c['space'] == '\t':
return ' '*self.tabstop
elif c['space']: elif c['space']:
t = m.group().replace('\t', '&nbsp;'*self.tabstop) t = m.group().replace('\t', '&nbsp;'*self.tabstop)
t = t.replace(' ', '&nbsp;') t = t.replace(' ', '&nbsp;')
return t return t
elif c['space'] == '\t': # else:
return ' '*self.tabstop # return m.group('protocol') + ' '
else: # url = m.group('protocol')
url = m.group('protocol') # prefix, postfix = '',''
if url.startswith(' '): # if url.startswith(' '):
prefix = ' ' # prefix = ' '
url = url[1:] # url = url[1:]
else: # if url.endswith(' '):
prefix = '' # postfix = ' '
last = m.groups()[-1] # url = url[:-1]
if last in ['\n', '\r', '\r\n']: # last = m.groups()[-1]
last = '<br>' # if last in ['\n', '\r', '\r\n']:
return '%s%s' % (prefix, url) # last = '<br>'
# return '%s%s%s' % (prefix, url, postfix)
def parse(self, text): def parse(self, text):
""" """
@ -124,7 +127,6 @@ class TextToHTMLparser(object):
result = self.convert_linebreaks(result) result = self.convert_linebreaks(result)
result = self.remove_backspaces(result) result = self.remove_backspaces(result)
result = self.convert_urls(result) result = self.convert_urls(result)
# clean out eventual ansi that was missed # clean out eventual ansi that was missed
result = ansi.parse_ansi(result, strip_ansi=True) result = ansi.parse_ansi(result, strip_ansi=True)