Browse files

gotr: fix line break handling (issue #25)

  • Loading branch information...
1 parent d9b6e00 commit 25e129fa383145f8d6c4d6ab9b4244aa54d3d70a @afflux afflux committed Oct 15, 2012
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/gajim-plugin/gotr/otrmodule.py
View
13 src/gajim-plugin/gotr/otrmodule.py
@@ -628,6 +628,11 @@ def reset(self):
def handle_data(self, data):
self.stripped_data += data
+
+ def handle_starttag(self, tag, attrs):
+ if tag == 'br':
+ self.stripped_data += '\n'
+
def handle_entityref(self, name):
c = unichr(name2codepoint[name])
self.stripped_data += c
@@ -637,9 +642,14 @@ def handle_charref(self, name):
else:
c = unichr(int(name))
self.stripped_data += c
+
def unknown_decl(self, data):
if data.startswith('CDATA['):
- self.data += data[6:]
+ self.stripped_data += data[6:]
+
+ def feed(self, data):
+ data = data.replace('\n', '')
+ HTMLParser.feed(self, data)
def escape(s):
'''Replace special characters "&", "<" and ">" to HTML-safe sequences.
@@ -648,6 +658,7 @@ def escape(s):
s = s.replace("&", "&amp;") # Must be done first!
s = s.replace("<", "&lt;")
s = s.replace(">", "&gt;")
+ s = s.replace("\n", "<br/>")
return s
## TODO:

0 comments on commit 25e129f

Please sign in to comment.