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