Replace Paragraph Tags for Flash

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from re import sub
from django import template
from django.template.defaultfilters import stringfilter

register = template.Library()

@stringfilter
@register.filter
def force_br(value):
    """
    For Flash, replace all <p> tags with <br />
    and strip newlines
    """
    
    if not value:
        return value
    
    value = sub('<p[^>]*>', '', value)
    value = sub('<\/p>', '<br />', value)
    value = sub("\n", "", value)
    
    return value

More like this

  1. Cleanup dirty HTML from a WYSIWYG editor by denis 3 years, 11 months ago
  2. TinyMCE Widget by semente 3 years, 8 months ago
  3. Extended rails flash implementation by miracle2k 5 years, 10 months ago
  4. linebreaksli template filter by rokclimb15 5 years, 11 months ago
  5. Convert newlines into <p> and </p> tags by jheasly 6 years, 1 month ago

Comments

(Forgotten your password?)