Convert XHTML-compatible shorttag to HTML-compatible tag.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import re
from django import template
from django.utils.safestring import mark_safe
register = template.Library()


shorttag_regex = re.compile('^<([^/>]*[^\s]+)\s*/>$')

@template.defaultfilters.stringfilter
def remove_shorttag(field):
	search = shorttag_regex.search(field)
	if search:
		try:
			return mark_safe(u'<%s>' % search.groups()[0])
		except:
			return mark_safe(field)
	else:
		return mark_safe(field)
remove_shorttag.is_safe = True

register.filter('remove_shorttag', remove_shorttag)

More like this

  1. Django csrf_token Template Tag Fix by Reustle 3 years, 8 months ago
  2. Add CSS class template filter by lazerscience 3 years, 5 months ago
  3. Clear FileField/ImageField files in the Admin by marinho 4 years, 9 months ago
  4. Fieldsets for Views by Nad/ 4 years, 2 months ago
  5. YUI Loader as Django middleware by akaihola 5 years, 12 months ago

Comments

(Forgotten your password?)