From a3fa00b8873aa24194b3b6f7b499a6afc4ba5883 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Sun, 27 Jan 2019 17:24:36 -0500 Subject: [PATCH] auto-format text to html when expected; refs #33 --- apprise/Apprise.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/apprise/Apprise.py b/apprise/Apprise.py index cb2a5bcb..70d3c92a 100644 --- a/apprise/Apprise.py +++ b/apprise/Apprise.py @@ -254,6 +254,39 @@ class Apprise(object): # Apply Markdown conversion_map[server.notify_format] = markdown(body) + elif body_format == NotifyFormat.TEXT and \ + server.notify_format == NotifyFormat.HTML: + + # Basic TEXT to HTML format map; supports keys only + re_map = { + # Support Ampersand + r'&': '&', + + # Spaces to   for formatting purposes since + # multiple spaces are treated as one an this may not + # be the callers intention + r' ': ' ', + + # Tab support + r'\t': '   ', + + # Greater than and Less than Characters + r'>': '>', + r'<': '<', + } + + # Compile our map + re_table = re.compile( + r'(' + '|'.join(map(re.escape, re_map.keys())) + r')', + re.IGNORECASE, + ) + + # Execute our map against our body in addition to swapping + # out new lines and replacing them with
+ conversion_map[server.notify_format] = \ + re.sub(r'\r*\n', '
\r\n', + re_table.sub(lambda x: re_map[x.group()], body)) + else: # Store entry directly conversion_map[server.notify_format] = body