mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Allow entities to span in multiple lines
This commit is contained in:
parent
0578cf6edc
commit
afffd5b4af
@ -36,7 +36,7 @@ class Markdown:
|
|||||||
CODE_DELIMITER = "`"
|
CODE_DELIMITER = "`"
|
||||||
PRE_DELIMITER = "```"
|
PRE_DELIMITER = "```"
|
||||||
|
|
||||||
MARKDOWN_RE = re.compile(r"```([\w\W]*)(?:\n|)```|\[([^[]+?)\]\(([^(]+?)\)|({d})(.+?)\4".format(
|
MARKDOWN_RE = re.compile(r"({d})([\w\W]*?)\1|\[([^[]+?)\]\(([^(]+?)\)".format(
|
||||||
d="|".join(
|
d="|".join(
|
||||||
["".join(i) for i in [
|
["".join(i) for i in [
|
||||||
["\{}".format(j) for j in i]
|
["\{}".format(j) for j in i]
|
||||||
@ -55,19 +55,15 @@ class Markdown:
|
|||||||
self.peers_by_id = peers_by_id
|
self.peers_by_id = peers_by_id
|
||||||
|
|
||||||
def parse(self, message: str):
|
def parse(self, message: str):
|
||||||
entities = []
|
|
||||||
message = utils.add_surrogates(message).strip()
|
message = utils.add_surrogates(message).strip()
|
||||||
|
entities = []
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
for match in self.MARKDOWN_RE.finditer(message):
|
for match in self.MARKDOWN_RE.finditer(message):
|
||||||
start = match.start() - offset
|
start = match.start() - offset
|
||||||
pre, text, url, style, body = match.groups()
|
style, body, text, url = match.groups()
|
||||||
|
|
||||||
if pre:
|
if url:
|
||||||
body = pre
|
|
||||||
entity = Pre(start, len(pre), "")
|
|
||||||
offset += len(self.PRE_DELIMITER) * 2
|
|
||||||
elif url:
|
|
||||||
mention = self.MENTION_RE.match(url)
|
mention = self.MENTION_RE.match(url)
|
||||||
|
|
||||||
if mention:
|
if mention:
|
||||||
@ -91,6 +87,8 @@ class Markdown:
|
|||||||
entity = Italic(start, len(body))
|
entity = Italic(start, len(body))
|
||||||
elif style == self.CODE_DELIMITER:
|
elif style == self.CODE_DELIMITER:
|
||||||
entity = Code(start, len(body))
|
entity = Code(start, len(body))
|
||||||
|
elif style == self.PRE_DELIMITER:
|
||||||
|
entity = Pre(start, len(body), "")
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user