nofollow links in comments if score is less than 3

This commit is contained in:
spez
2009-03-23 10:48:35 -07:00
parent 32a11ba429
commit 17282a1b84
3 changed files with 12 additions and 6 deletions

View File

@@ -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('&amp;', '&')
url = m.group(1).replace('&amp;', '&')
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('&amp;','&')

View File

@@ -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

View File

@@ -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]")}