Skip to content

Instantly share code, notes, and snippets.

@victorono
Created May 8, 2014 18:00
Show Gist options
  • Select an option

  • Save victorono/4fbddef0ae6b12f09ec0 to your computer and use it in GitHub Desktop.

Select an option

Save victorono/4fbddef0ae6b12f09ec0 to your computer and use it in GitHub Desktop.
replace all newlines in a string with <br />.
from django import template
register = template.Library()
from django.utils.safestring import mark_safe
@register.filter()
def breakline(text):
return mark_safe("<br />".join(text.split("\n")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment