Skip to content

Commit 648f37c

Browse files
committed
Add support for underline and strikethrough text via Markdown
New delimiters: - ~~strikethrough~~ - --underline--
1 parent 978ee4e commit 648f37c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pyrogram/client/style/markdown.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
MessageEntityCode as Code,
2727
MessageEntityTextUrl as Url,
2828
MessageEntityPre as Pre,
29+
MessageEntityUnderline as Underline,
30+
MessageEntityStrike as Strike,
2931
MessageEntityMentionName as MentionInvalid,
3032
InputMessageEntityMentionName as Mention
3133
)
@@ -36,6 +38,8 @@
3638
class Markdown:
3739
BOLD_DELIMITER = "**"
3840
ITALIC_DELIMITER = "__"
41+
UNDERLINE_DELIMITER = "--"
42+
STRIKE_DELIMITER = "~~"
3943
CODE_DELIMITER = "`"
4044
PRE_DELIMITER = "```"
4145

@@ -46,6 +50,8 @@ class Markdown:
4650
for i in [
4751
PRE_DELIMITER,
4852
CODE_DELIMITER,
53+
STRIKE_DELIMITER,
54+
UNDERLINE_DELIMITER,
4955
ITALIC_DELIMITER,
5056
BOLD_DELIMITER
5157
]
@@ -91,6 +97,10 @@ def parse(self, message: str):
9197
entity = Bold(offset=start, length=len(body))
9298
elif style == self.ITALIC_DELIMITER:
9399
entity = Italic(offset=start, length=len(body))
100+
elif style == self.UNDERLINE_DELIMITER:
101+
entity = Underline(offset=start, length=len(body))
102+
elif style == self.STRIKE_DELIMITER:
103+
entity = Strike(offset=start, length=len(body))
94104
elif style == self.CODE_DELIMITER:
95105
entity = Code(offset=start, length=len(body))
96106
elif style == self.PRE_DELIMITER:
@@ -124,6 +134,10 @@ def unparse(self, message: str, entities: list):
124134
style = self.BOLD_DELIMITER
125135
elif type == "italic":
126136
style = self.ITALIC_DELIMITER
137+
elif type == "underline":
138+
style = self.UNDERLINE_DELIMITER
139+
elif type == "strike":
140+
style = self.STRIKE_DELIMITER
127141
elif type == "code":
128142
style = self.CODE_DELIMITER
129143
elif type == "pre":

0 commit comments

Comments
 (0)