mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 04:48:06 +00:00
Lazily compute html and markdown styled texts
This commit is contained in:
parent
2398de716c
commit
33207c2138
@ -33,26 +33,26 @@ log = logging.getLogger(__name__)
|
|||||||
# TODO: Organize the code better?
|
# TODO: Organize the code better?
|
||||||
|
|
||||||
class Str(str):
|
class Str(str):
|
||||||
def __init__(self, value):
|
def __init__(self, text):
|
||||||
str.__init__(value)
|
str.__init__(text)
|
||||||
self._markdown = None
|
self._client = None
|
||||||
self._html = None
|
self._entities = None
|
||||||
|
|
||||||
|
def init(self, client, entities):
|
||||||
|
self._client = client
|
||||||
|
self._entities = entities
|
||||||
|
|
||||||
|
@property
|
||||||
|
def text(self):
|
||||||
|
return self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def markdown(self):
|
def markdown(self):
|
||||||
return self._markdown
|
return self._client.markdown.unparse(self, self._entities)
|
||||||
|
|
||||||
@markdown.setter
|
|
||||||
def markdown(self, value):
|
|
||||||
self._markdown = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def html(self):
|
def html(self):
|
||||||
return self._html
|
return self._client.html.unparse(self, self._entities)
|
||||||
|
|
||||||
@html.setter
|
|
||||||
def html(self, value):
|
|
||||||
self._html = value
|
|
||||||
|
|
||||||
|
|
||||||
ENTITIES = {
|
ENTITIES = {
|
||||||
@ -580,17 +580,25 @@ def parse_messages(
|
|||||||
reply_markup=reply_markup
|
reply_markup=reply_markup
|
||||||
)
|
)
|
||||||
|
|
||||||
if m.text:
|
# TODO: lazily evaluate html and markdown?
|
||||||
args = (m.text, m.entities or [])
|
|
||||||
|
|
||||||
m.text.markdown = client.markdown.unparse(*args)
|
if m.text:
|
||||||
m.text.html = client.html.unparse(*args)
|
m.text.init(m.client, m.entities or [])
|
||||||
|
|
||||||
if m.caption:
|
if m.caption:
|
||||||
args = (m.caption, m.caption_entities or [])
|
m.caption.init(m.client, m.caption_entities or [])
|
||||||
|
|
||||||
m.caption.markdown = client.markdown.unparse(*args)
|
# if m.text:
|
||||||
m.caption.html = client.html.unparse(*args)
|
# args = (m.text, m.entities or [])
|
||||||
|
#
|
||||||
|
# m.text.markdown = client.markdown.unparse(*args)
|
||||||
|
# m.text.html = client.html.unparse(*args)
|
||||||
|
#
|
||||||
|
# if m.caption:
|
||||||
|
# args = (m.caption, m.caption_entities or [])
|
||||||
|
#
|
||||||
|
# m.caption.markdown = client.markdown.unparse(*args)
|
||||||
|
# m.caption.html = client.html.unparse(*args)
|
||||||
|
|
||||||
if message.reply_to_msg_id and replies:
|
if message.reply_to_msg_id and replies:
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user