(backported from https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.html.format_html)