mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Minor refactor MessageEntity#parse
This commit is contained in:
parent
be622ca559
commit
dfc334ef20
1 changed files with 12 additions and 18 deletions
|
|
@ -49,29 +49,23 @@ class MessageEntity(base.TelegramObject):
|
||||||
entity_text = self.get_text(text)
|
entity_text = self.get_text(text)
|
||||||
|
|
||||||
if self.type == MessageEntityType.BOLD:
|
if self.type == MessageEntityType.BOLD:
|
||||||
if as_html:
|
method = markdown.hbold if as_html else markdown.bold
|
||||||
return markdown.hbold(entity_text)
|
return method(entity_text)
|
||||||
return markdown.bold(entity_text)
|
|
||||||
if self.type == MessageEntityType.ITALIC:
|
if self.type == MessageEntityType.ITALIC:
|
||||||
if as_html:
|
method = markdown.hitalic if as_html else markdown.italic
|
||||||
return markdown.hitalic(entity_text)
|
return method(entity_text)
|
||||||
return markdown.italic(entity_text)
|
|
||||||
if self.type == MessageEntityType.PRE:
|
if self.type == MessageEntityType.PRE:
|
||||||
if as_html:
|
method = markdown.hpre if as_html else markdown.pre
|
||||||
return markdown.hpre(entity_text)
|
return method(entity_text)
|
||||||
return markdown.pre(entity_text)
|
|
||||||
if self.type == MessageEntityType.CODE:
|
if self.type == MessageEntityType.CODE:
|
||||||
if as_html:
|
method = markdown.hcode if as_html else markdown.code
|
||||||
return markdown.hcode(entity_text)
|
return method(entity_text)
|
||||||
return markdown.code(entity_text)
|
|
||||||
if self.type == MessageEntityType.URL:
|
if self.type == MessageEntityType.URL:
|
||||||
if as_html:
|
method = markdown.hlink if as_html else markdown.link
|
||||||
return markdown.hlink(entity_text, entity_text)
|
return method(entity_text, entity_text)
|
||||||
return markdown.link(entity_text, entity_text)
|
|
||||||
if self.type == MessageEntityType.TEXT_LINK:
|
if self.type == MessageEntityType.TEXT_LINK:
|
||||||
if as_html:
|
method = markdown.hlink if as_html else markdown.link
|
||||||
return markdown.hlink(entity_text, self.url)
|
return method(entity_text, self.url)
|
||||||
return markdown.link(entity_text, self.url)
|
|
||||||
if self.type == MessageEntityType.TEXT_MENTION and self.user:
|
if self.type == MessageEntityType.TEXT_MENTION and self.user:
|
||||||
return self.user.get_mention(entity_text)
|
return self.user.get_mention(entity_text)
|
||||||
return entity_text
|
return entity_text
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue