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 Consists of functions to typically be used within templates, but also
available to Controllers. This module is available to both as 'h'. available to Controllers. This module is available to both as 'h'.
""" """
import logging
from webhelpers.html import escape, HTML, literal, url_escape from webhelpers.html import escape, HTML, literal, url_escape
from webhelpers.date import distance_of_time_in_words from webhelpers.date import distance_of_time_in_words
from pylons import session, url as url_for from pylons import session, url as url_for
from pylons.controllers.util import redirect_to from pylons.controllers.util import redirect_to
log = logging.getLogger(__name__)
class Flash(object): class Flash(object):
def set_message(self, message_text, message_type, message_head=None): def set_message(self, message_text, message_type, message_head=None):
session[u'flash.text'] = message_text session[u'flash.text'] = message_text
@ -77,6 +80,13 @@ def teaser(text):
text = text[:position] text = text[:position]
return text 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): def url_for_post(post):
#TODO: this is hard coded. #TODO: this is hard coded.
return url_for( return url_for(

View File

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

View File

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