mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 00:07:57 -05:00
Fixed markdown so that URLs in <code> blocks no longer have
angle brackets wrapped around them
This commit is contained in:
@@ -98,9 +98,10 @@ def edit_comment_filter(text = ''):
|
||||
r_url = re.compile('(?<![\(\[])(http://[^\s\'\"\]\)]+)')
|
||||
jscript_url = re.compile('<a href="(?!http|ftp|mailto|/).*</a>', re.I | re.S)
|
||||
img = re.compile('<img.*?>', re.I | re.S)
|
||||
href_re = re.compile('<a href="([^"]+)"', re.I | re.S)
|
||||
href_re = re.compile('<a href="([^"]+)"', re.I)
|
||||
code_re = re.compile('<code>([^<]+)</code>')
|
||||
a_re = re.compile('>([^<]+)</a>')
|
||||
fix_url = re.compile('<(http://[^\s\'\"\]\)]+)>')
|
||||
|
||||
|
||||
#TODO markdown should be looked up in batch?
|
||||
@@ -109,8 +110,8 @@ def safemarkdown(text):
|
||||
from contrib.markdown import markdown
|
||||
if text:
|
||||
# increase escaping of &, < and > once
|
||||
text = text.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
#wrap urls in "<>" so that markdown will handle them as urls
|
||||
text = text.replace("&", "&").replace("<", "<").replace(">", ">")
|
||||
#wrap urls in "<>" so that markdown will handle them as urls
|
||||
text = r_url.sub(r'<\1>', text)
|
||||
try:
|
||||
text = markdown(text)
|
||||
@@ -137,6 +138,7 @@ def safemarkdown(text):
|
||||
text = href_re.sub(href_handler, text)
|
||||
text = code_re.sub(code_handler, text)
|
||||
text = a_re.sub(inner_a_handler, text)
|
||||
text = fix_url.sub(r'\1', text)
|
||||
return MD_START + text + MD_END
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user