wordbreak filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
from datetime import datetime
import re 

from django import template
register = template.Library()

@register.filter
def wordbreak (string, arg):
    search = '([^ ]{' + arg + '})'
    t = datetime.now()
    wbr = t.strftime("%A%d%B%Y%f") + 'wbr_here' + t.strftime("%A%d%B%Y%f")
    saferesult = conditional_escape(re.sub( search, '\\1' + wbr, string ))
    result = saferesult.replace(wbr,'­')
    return mark_safe(result)

More like this

  1. Filter to add zero-width space to break up long words by jayliew 8 months ago
  2. Soft-wrap long lines by Ubercore 5 years, 1 month ago
  3. Soft hyphenation (­) template filter using PyHyphen by dokterbob 4 years, 1 month ago
  4. Truncate text to length up until the nearest space by phektus 2 years, 2 months ago
  5. nbsp filter by vitamon 6 months, 2 weeks ago

Comments

(Forgotten your password?)