Skip to content

Commit

Permalink
Merge pull request #6 from aurickq/master
Browse files Browse the repository at this point in the history
allow markdown in profile
  • Loading branch information
aurickq committed Dec 28, 2014
2 parents 39100a9 + ea27eed commit cd3ee7c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ pyflakes==0.8.1
rgkit==0.5.0
uWSGI==2.0.5.1
web.py==0.37
Markdown==2.5.2
bleach==1.4.1
7 changes: 5 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,14 @@ def logout_user(sess):

def template_closure(directory):
global settings
templates = web.template.render(directory,
templates = web.template.render(
directory,
globals={
'sess': sess,
'settings': settings,
'tplib': tplib})
'tplib': tplib,
},
)
def render(name, *params, **kwargs):
return getattr(templates, name)(*params, **kwargs)
return render
Expand Down
2 changes: 1 addition & 1 deletion t/viewrobot.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h1 class="no-margin">
<h2><a href='/user/$robot.user_id'>About this programmer</a></h2>
<div class="about">
$if robot.about:
<div class="text">$robot.about</div>
$:tplib.safe_markdown(robot.about)
$else:
<div class="text"></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion t/viewuser.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>About the programmer</h1>
$if tplib.is_mod(sess):
Registered $tplib.time_ago(user.registered_on).
</div>
<div class="text">$user.about</div>
$:tplib.safe_markdown(user.about)
</div>

<hr />
Expand Down
12 changes: 10 additions & 2 deletions tplib.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import math
import bleach
import hashlib
from datetime import datetime
import markdown
import math
import tools

from datetime import datetime

ADMINS = (
1, # bh (hehe, just use one account to be safe
)
Expand Down Expand Up @@ -182,3 +185,8 @@ def rating_change(match, rid, other=False):
match.r2_score, match.r1_score,
match.k_factor)
return round(diff, 1)

def safe_markdown(string):
string = bleach.clean(string)
string = markdown.markdown(string)
return bleach.clean(string, tags=bleach.ALLOWED_TAGS+['p'])

0 comments on commit cd3ee7c

Please sign in to comment.