Skip to content

Instantly share code, notes, and snippets.

@neilmock
Created April 24, 2009 20:37
Show Gist options
  • Save neilmock/101335 to your computer and use it in GitHub Desktop.
Save neilmock/101335 to your computer and use it in GitHub Desktop.
def linebreaksul(value):
"""
Converts a series of newlines into list items enclosed in an unordered list.
"""
unordered_list = "<ul>"
# split value into individual elements separated by newline
list_items = value.split('\n')
for li in list_items:
unordered_list += "<li>%s</li>" % li
unordered_list += "</ul>"
return mark_safe(unordered_list)
register.filter(linebreaksul)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment