""", re.X | re.I)
+EMAIL_LINK_REPLACE_RE = re.compile("(?<= href=\")[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})(?=\")")
+
def is_ip(addr):
try:
socket.inet_aton(addr)
ws = m.group('ws')
- if ws and ws[0] in ("'", '"'):
+ if ws and ws[0] in ("'", '"', "@"):
return m.group(0)
elif not ws:
if not protocol:
domain_chunks = domain.split('.')
- if not ((len(domain_chunks) == 1 and domain_chunks[0].lower() == 'localhost') or (domain_chunks[-1].lower() in TLDS)):
+ if not (len(domain_chunks) == 1 and domain_chunks[0].lower() == 'localhost') or (domain_chunks[-1].lower() in TLDS):
return m.group(0)
if (not protocol) and is_ip(domain):
class AutoLinker(markdown.postprocessors.Postprocessor):
def run(self, text):
- return AUTO_LINK_RE.sub(replacer, text)
+ text = AUTO_LINK_RE.sub(replacer, text)
+ text = EMAIL_LINK_REPLACE_RE.sub(lambda m: "mailto:%s" % m.group(0), text)
+
+ return text
class AutoLinkerExtension(markdown.Extension):