mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
nofollow links in comments if score is less than 3
This commit is contained in:
@@ -106,7 +106,7 @@ fix_url = re.compile('<(http://[^\s\'\"\]\)]+)>')
|
||||
|
||||
#TODO markdown should be looked up in batch?
|
||||
#@memoize('markdown')
|
||||
def safemarkdown(text):
|
||||
def safemarkdown(text, nofollow = False):
|
||||
from contrib.markdown import markdown
|
||||
if text:
|
||||
# increase escaping of &, < and > once
|
||||
@@ -122,11 +122,13 @@ def safemarkdown(text):
|
||||
#wipe malicious javascript
|
||||
text = jscript_url.sub('', text)
|
||||
def href_handler(m):
|
||||
x = m.group(1).replace('&', '&')
|
||||
url = m.group(1).replace('&', '&')
|
||||
link = '<a href="%s"' % url
|
||||
if c.cname:
|
||||
return '<a target="_top" href="%s"' % x
|
||||
else:
|
||||
return '<a href="%s"' % x
|
||||
link += ' target="_top"'
|
||||
if nofollow:
|
||||
link += ' rel="nofollow"'
|
||||
return link
|
||||
def code_handler(m):
|
||||
l = m.group(1)
|
||||
return '<code>%s</code>' % l.replace('&','&')
|
||||
|
||||
@@ -521,6 +521,10 @@ class Comment(Thing, Printable):
|
||||
|
||||
if not hasattr(item,'editted'):
|
||||
item.editted = False
|
||||
|
||||
#score less than 3, nofollow the links
|
||||
item.nofollow = item._score < 3
|
||||
|
||||
#will get updated in builder
|
||||
item.num_children = 0
|
||||
item.score_fmt = Score.points
|
||||
|
||||
@@ -102,7 +102,7 @@ ${parent.Child(not thing.collapsed)}
|
||||
|
||||
<%def name="commentBody()">
|
||||
%if c.user_is_admin or not thing.deleted:
|
||||
${unsafe(safemarkdown(thing.body))}
|
||||
${unsafe(safemarkdown(thing.body, thing.nofollow))}
|
||||
%else:
|
||||
<div class="gray md">
|
||||
${_("[deleted]")}
|
||||
|
||||
Reference in New Issue
Block a user