mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Support callable parse_mode's
This allows to more easily plug in custom parse methods.
This commit is contained in:
parent
eabaa3854a
commit
07a8a73e3e
|
@ -679,13 +679,18 @@ class TelegramClient(TelegramBareClient):
|
||||||
if not parse_mode:
|
if not parse_mode:
|
||||||
return message, []
|
return message, []
|
||||||
|
|
||||||
parse_mode = parse_mode.lower()
|
if isinstance(parse_mode, str):
|
||||||
if parse_mode in {'md', 'markdown'}:
|
parse_mode = parse_mode.lower()
|
||||||
message, msg_entities = markdown.parse(message)
|
if parse_mode in {'md', 'markdown'}:
|
||||||
elif parse_mode.startswith('htm'):
|
message, msg_entities = markdown.parse(message)
|
||||||
message, msg_entities = html.parse(message)
|
elif parse_mode.startswith('htm'):
|
||||||
|
message, msg_entities = html.parse(message)
|
||||||
|
else:
|
||||||
|
raise ValueError('Unknown parsing mode: {}'.format(parse_mode))
|
||||||
|
elif callable(parse_mode):
|
||||||
|
message, msg_entities = parse_mode(message)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown parsing mode: {}'.format(parse_mode))
|
raise TypeError('Invalid parsing mode type: {}'.format(parse_mode))
|
||||||
|
|
||||||
for i, e in enumerate(msg_entities):
|
for i, e in enumerate(msg_entities):
|
||||||
if isinstance(e, MessageEntityTextUrl):
|
if isinstance(e, MessageEntityTextUrl):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user