markdown: don't auto-mailto:-link a@b in @a@b mastodon UID
This chases a similar report for github posted at https://101010.pl/@mcc@mastodon.social/110742090990556162 in that "@nabijaczleweli@101010.pl" is autolinked as "@<mailto:nabijaczleweli@101010.pl>" which sucks for obvious reasons (it's not actually a correct mail address, the actual purpose is muddied by the autolinking). Instead, match against "@?<previous mail regex>", and eject addresses that start with @s as raw text.
This commit is contained in:
parent
1dd2f363ce
commit
4157c41ff0
|
@ -12,7 +12,7 @@ import mistletoe as m
|
|||
from mistletoe.span_token import SpanToken, RawText
|
||||
import re
|
||||
|
||||
SRHT_MARKDOWN_VERSION = 15
|
||||
SRHT_MARKDOWN_VERSION = 16
|
||||
|
||||
class PlainLink(SpanToken):
|
||||
"""
|
||||
|
@ -24,7 +24,7 @@ class PlainLink(SpanToken):
|
|||
"""
|
||||
pattern = re.compile(r"(?<!\\)(?:\\\\)*" # Fail if prefixed by odd number of backslashes
|
||||
r"((?P<url>[A-Za-z][A-Za-z0-9+.-]{1,31}://[^ \t\n\r\f\v<>]*)" # URLs: 'scheme'://'path'
|
||||
r"|(?P<mail>[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9]" # Emails: 'user'@'domain
|
||||
r"|(?P<mail>@?[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9]" # Emails: 'user'@'domain
|
||||
r"(?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?"
|
||||
r"(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+))")
|
||||
parse_inner = False
|
||||
|
@ -84,6 +84,8 @@ class SrhtRenderer(m.HTMLRenderer):
|
|||
def render_plain_link(self, token):
|
||||
template = '<a href="{target}">{inner}</a>'
|
||||
if token.mailto:
|
||||
if token.target.startswith('@'): # mastodon "@user@domain" as plain text
|
||||
return token.target
|
||||
target = 'mailto:{}'.format(token.target)
|
||||
else:
|
||||
target = self.escape_url(token.target)
|
||||
|
|
Loading…
Reference in New Issue