mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 04:48:06 +00:00
Automatically escape URL bodies when using markdown
This commit is contained in:
parent
d6900cde9f
commit
f12cee5d94
@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import html
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
@ -89,10 +90,14 @@ class Markdown:
|
|||||||
for match in re.finditer(Markdown.URL_RE, text):
|
for match in re.finditer(Markdown.URL_RE, text):
|
||||||
start, stop = match.span()
|
start, stop = match.span()
|
||||||
full = match.group(0)
|
full = match.group(0)
|
||||||
|
|
||||||
body, url = match.groups()
|
body, url = match.groups()
|
||||||
|
body = html.escape(body)
|
||||||
|
|
||||||
replace = '<a href="{}">{}</a>'.format(url, body)
|
replace = '<a href="{}">{}</a>'.format(url, body)
|
||||||
|
|
||||||
text = text[:start + offset] + replace + text[stop + offset:]
|
text = text[:start + offset] + replace + text[stop + offset:]
|
||||||
|
|
||||||
offset += len(replace) - len(full)
|
offset += len(replace) - len(full)
|
||||||
|
|
||||||
return self.html.parse(text)
|
return self.html.parse(text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user