1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import re
from django.template.defaultfilters import stringfilter
from django.template import Library
register = Library()
@register.filter
@stringfilter
def killtags(value, tags):
tags = [re.escape(tag) for tag in tags.split()]
tags_re = u'(%s)' % u'|'.join(tags)
kill_re = re.compile("<\s*%s[^>]*>(.*?)<\s*/\s*\\1>" % tags_re, re.U)
value = kill_re.sub('', value)
return value
killtags.is_safe = True
|
More like this
- Enhanced "avoid widows" template filters by SmileyChris 5 years, 10 months ago
- Tags & filters for rendering search results by exogen 5 years, 2 months ago
- Soft-wrap long lines by Ubercore 5 years, 1 month ago
- filter for extracting a number of paragraphs from any HTML code by rafadev 1 year, 11 months ago
- alientag by itchyfingrs 1 year, 7 months ago
Comments