aboutsummaryrefslogtreecommitdiffstats
path: root/slack/util.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-10-14 19:52:44 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:54 +0100
commit291ce07645f63614b3b00fbe20063d6ef0161bef (patch)
treef6b2d0f7412f1f3ac2c02d8c2ab2957d1dc338fa /slack/util.py
parent184bf08360003538179e3c19b2711016c823eadd (diff)
downloadwee-slack-291ce07645f63614b3b00fbe20063d6ef0161bef.tar.gz
Support sending messages
Diffstat (limited to 'slack/util.py')
-rw-r--r--slack/util.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/slack/util.py b/slack/util.py
index 41993c5..c988f1f 100644
--- a/slack/util.py
+++ b/slack/util.py
@@ -34,6 +34,17 @@ def with_color(color: Optional[str], string: str, reset_color: str = "reset"):
return string
+# Escape chars that have special meaning to Slack. Note that we do not
+# (and should not) perform full HTML entity-encoding here.
+# See https://api.slack.com/reference/surfaces/formatting#escaping for details.
+def htmlescape(text: str) -> str:
+ return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
+
+
+def unhtmlescape(text: str) -> str:
+ return text.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&")
+
+
# From https://github.com/more-itertools/more-itertools/blob/v10.1.0/more_itertools/recipes.py#L93-L106
def take(n: int, iterable: Iterable[T]) -> List[T]:
"""Return first *n* items of the iterable as a list.