aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahiel.kasim@kabisa.nl>2022-04-10 12:37:00 +0200
committerRahiel Kasim <rahiel.kasim@kabisa.nl>2022-04-10 12:37:00 +0200
commit4397d33d109dd289fec50687ad54fe8f3c74a4ee (patch)
tree2d13ce37dac75ecc535c1531ef69b800118aa113
parent93d61664f1f16fb1885addd42a51b56a13169408 (diff)
use more robust html formatting for --pre option
-rw-r--r--telegram_send/telegram_send.py2
-rw-r--r--telegram_send/utils.py8
2 files changed, 4 insertions, 6 deletions
diff --git a/telegram_send/telegram_send.py b/telegram_send/telegram_send.py
index 70c3adf..3121364 100644
--- a/telegram_send/telegram_send.py
+++ b/telegram_send/telegram_send.py
@@ -109,7 +109,7 @@ def main():
return clean()
if args.pre:
- args.parse_mode = "markdown"
+ args.parse_mode = "html"
if args.parse_mode == "markdown":
# Use the improved MarkdownV2 format by default
diff --git a/telegram_send/utils.py b/telegram_send/utils.py
index a5df681..162326b 100644
--- a/telegram_send/utils.py
+++ b/telegram_send/utils.py
@@ -1,4 +1,4 @@
-import sys
+import html
from typing import List
from appdirs import AppDirs
@@ -11,10 +11,8 @@ def markup(text: str, style: str) -> str:
def pre(text: str) -> str:
- if "```" in text:
- print(markup("Sending a message containing ``` is not supported with --pre.", "red"))
- sys.exit(1)
- return "```text\n" + text + "```"
+ escaped_text = html.escape(text)
+ return f"<pre>{escaped_text}</pre>"
def split_message(message: str, max_length: int) -> List[str]: