summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-12-16 20:46:45 +0100
committermathieui <mathieui@mathieui.net>2014-12-16 20:46:45 +0100
commitef3beab02b0ac10e5b535bb4cea949d44a413fd9 (patch)
tree705bb5f01e9e47fdf6e3f4e582534f4b50195109
parent778581c48087450ec0efbb7ade16f2eefe501f3f (diff)
downloadpoezio-ef3beab02b0ac10e5b535bb4cea949d44a413fd9.tar.gz
poezio-ef3beab02b0ac10e5b535bb4cea949d44a413fd9.tar.bz2
poezio-ef3beab02b0ac10e5b535bb4cea949d44a413fd9.tar.xz
poezio-ef3beab02b0ac10e5b535bb4cea949d44a413fd9.zip
Add a decode_newlines option to the OTR plugin
I wish I didn’t have to do such ugly things to get a close-to-decent interop with legacy OTR plugins that insert awful HTML4 stuff inside messages that do not need it.
-rw-r--r--plugins/otr.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/plugins/otr.py b/plugins/otr.py
index a632a165..7488ed46 100644
--- a/plugins/otr.py
+++ b/plugins/otr.py
@@ -129,12 +129,20 @@ Configuration
Decode embedded XHTML.
decode_entities
- **Default:** ``false``
+ **Default:** ``true``
Decode XML and HTML entities (like ``&amp;``) even when the
document isn't valid (if it is valid, it will be decoded even
without this option).
+ decode_newlines
+ **Default:** ``true``
+
+ Decode ``<br/>`` and ``<br>`` tags even when the document
+ isn't valid (if it is valid, it will be decoded even
+ without this option for ``<br/>``, and ``<br>`` will make
+ the document invalid anyway).
+
keys_dir
**Default:** ``$XDG_DATA_HOME/poezio/otr``
@@ -554,15 +562,23 @@ class Plugin(BasePlugin):
body = txt.decode()
decode_entities = self.config.get_by_tabname('decode_entities',
msg['from'].bare,
- default=False)
+ default=True)
+ decode_newlines = self.config.get_by_tabname('decode_newlines',
+ msg['from'].bare,
+ default=True)
if self.config.get_by_tabname('decode_xhtml', msg['from'].bare, default=True):
try:
body = xhtml.xhtml_to_poezio_colors(body, force=True)
- except:
+ except Exception:
if decode_entities:
body = html.unescape(body)
- elif decode_entities:
- body = html.unescape(body)
+ if decode_newlines:
+ body = body.replace('<br/>', '\n').replace('<br>', '\n')
+ else:
+ if decode_entities:
+ body = html.unescape(body)
+ if decode_newlines:
+ body = body.replace('<br/>', '\n').replace('<br>', '\n')
tab.add_message(body, nickname=tab.nick, jid=msg['from'],
forced_user=user, typ=ctx.log,
nick_color=nick_color)