Skip to content

Commit 0b31c8f

Browse files
committed
Added support for spoiler message with markdown
1 parent c3656c6 commit 0b31c8f

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

pyrogram/parser/html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def handle_starttag(self, tag, attrs):
6161
elif tag == "pre":
6262
entity = raw.types.MessageEntityPre
6363
extra["language"] = ""
64-
elif tag == "spoiler":
64+
elif tag in ["span", "spoiler"]:
6565
entity = raw.types.MessageEntitySpoiler
6666
elif tag == "a":
6767
url = attrs.get("href", "")
@@ -158,7 +158,7 @@ def unparse(text: str, entities: list):
158158
if entity_type in ("bold", "italic", "underline", "strikethrough"):
159159
start_tag = f"<{entity_type[0]}>"
160160
end_tag = f"</{entity_type[0]}>"
161-
elif entity_type in ("code", "pre", "blockquote"):
161+
elif entity_type in ("code", "pre", "blockquote", "spoiler"):
162162
start_tag = f"<{entity_type}>"
163163
end_tag = f"</{entity_type}>"
164164
elif entity_type == "text_link":

pyrogram/parser/markdown.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
STRIKE_DELIM = "~~"
3131
CODE_DELIM = "`"
3232
PRE_DELIM = "```"
33+
SPOILER_DELIM = "||"
3334

3435
MARKDOWN_RE = re.compile(r"({d})|\[(.+?)\]\((.+?)\)".format(
3536
d="|".join(
@@ -41,7 +42,8 @@
4142
STRIKE_DELIM,
4243
UNDERLINE_DELIM,
4344
ITALIC_DELIM,
44-
BOLD_DELIM
45+
BOLD_DELIM,
46+
SPOILER_DELIM
4547
]
4648
]]
4749
)))
@@ -90,6 +92,8 @@ async def parse(self, text: str, strict: bool = False):
9092
tag = "code"
9193
elif delim == PRE_DELIM:
9294
tag = "pre"
95+
elif delim == SPOILER_DELIM:
96+
tag = "spoiler"
9397
else:
9498
continue
9599

@@ -127,6 +131,8 @@ def unparse(text: str, entities: list):
127131
start_tag = end_tag = CODE_DELIM
128132
elif entity_type in ("pre", "blockquote"):
129133
start_tag = end_tag = PRE_DELIM
134+
elif entity_type == "spoiler":
135+
start_tag = end_tag = SPOILER_DELIM
130136
elif entity_type == "text_link":
131137
url = entity.url
132138
start_tag = "["

pyrogram/types/messages_and_media/message_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class MessageEntity(Object):
9696
- "pre": monowidth block (see *language* below).
9797
- "text_link": for clickable text URLs.
9898
- "text_mention": for users without usernames (see *user* below).
99-
- "spoiler": for message spoiler
99+
- "spoiler": spoiler text
100100
101101
offset (``int``):
102102
Offset in UTF-16 code units to the start of the entity.

0 commit comments

Comments
 (0)