Google Groups Home
Help | Sign in
Message from discussion linebreaksli template filter
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
rokclimb15@gmail.com  
View profile
 More options Jun 20 2007, 1:03 am
From: "rokclim...@gmail.com" <rokclim...@gmail.com>
Date: Wed, 20 Jun 2007 05:03:51 -0000
Local: Wed, Jun 20 2007 1:03 am
Subject: linebreaksli template filter
I don't want to attempt to pollute Django's beautiful template library
namespace with garbage, but I do see a legitimate value for a
linebreaksli template filter.  It does just what it says - converts a
string with linebreaks into a set of list items.  Sometimes, a <p> tag
just doesn't do the same thing, especially if you want to number the
items with an <ol>.  My code is below.  It wouldn't take too much to
convert it to a Django template filter.  What does everyone think?

def linebreaksli(value):
        "Converts strings with newlines into <li></li>s"
        value = re.sub(r'\r\n|\r|\n', '\n', value) # normalize newlines
        lines = re.split('\n', value)
        lines = ['<li>%s</li>' % line for line in lines]
        return '\n'.join(lines)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google