Added simple formatting to comments. \n\n becomes </p><p> and \n becomes <br />

This commit is contained in:
Raoul Snyman 2010-02-23 22:21:52 +02:00
parent 37885d7578
commit bbd366c0cb
3 changed files with 17 additions and 2 deletions

View File

@ -26,12 +26,15 @@ Helper functions
Consists of functions to typically be used within templates, but also
available to Controllers. This module is available to both as 'h'.
"""
import logging
from webhelpers.html import escape, HTML, literal, url_escape
from webhelpers.date import distance_of_time_in_words
from pylons import session, url as url_for
from pylons.controllers.util import redirect_to
log = logging.getLogger(__name__)
class Flash(object):
def set_message(self, message_text, message_type, message_head=None):
session[u'flash.text'] = message_text
@ -77,6 +80,13 @@ def teaser(text):
text = text[:position]
return text
def comment(text):
text = text.replace(u'\r\n', u'\n')
paralist = escape(text).split(u'\n\n')
paragraphs = u'</p><p>'.join([para.strip(u'\n') for para in paralist])
text = paragraphs.replace(u'\n', u'<br />')
return literal(text)
def url_for_post(post):
#TODO: this is hard coded.
return url_for(

View File

@ -221,6 +221,11 @@ hr {
font-size: 0.9em;
}
.comment-body p {
margin-top: 0;
margin-bottom: 0.5em;
}
.user-details {
margin-top: 0;
}

View File

@ -39,8 +39,8 @@
by <cite>${comment.user.nick}</cite>
on ${comment.created.strftime('%B %d, %Y')} at ${comment.created.strftime('%H:%M')}
</div>
<div>
${comment.body}
<div class="comment-body">
<p>${h.comment(comment.body)}</p>
</div>
</li>
% endfor