mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Removed fix_ampersands template filter per deprecation timeline.
Also removed related utility functions: * django.utils.html.fix_ampersands * django.utils.html.clean_html
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import warnings
|
||||
|
||||
from django.utils.deprecation import RemovedInDjango18Warning
|
||||
from django.utils.encoding import force_text, force_str
|
||||
from django.utils.functional import allow_lazy
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
@@ -174,15 +172,6 @@ def strip_entities(value):
|
||||
strip_entities = allow_lazy(strip_entities, six.text_type)
|
||||
|
||||
|
||||
def fix_ampersands(value):
|
||||
"""Returns the given HTML with all unencoded ampersands encoded correctly."""
|
||||
# As fix_ampersands is wrapped in allow_lazy, stacklevel 3 is more useful than 2.
|
||||
warnings.warn("The fix_ampersands function is deprecated and will be removed in Django 1.8.",
|
||||
RemovedInDjango18Warning, stacklevel=3)
|
||||
return unencoded_ampersands_re.sub('&', force_text(value))
|
||||
fix_ampersands = allow_lazy(fix_ampersands, six.text_type)
|
||||
|
||||
|
||||
def smart_urlquote(url):
|
||||
"Quotes a URL if it isn't already quoted."
|
||||
# Handle IDN before quoting.
|
||||
@@ -283,44 +272,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
|
||||
urlize = allow_lazy(urlize, six.text_type)
|
||||
|
||||
|
||||
def clean_html(text):
|
||||
"""
|
||||
Clean the given HTML. Specifically, do the following:
|
||||
* Convert <b> and <i> to <strong> and <em>.
|
||||
* Encode all ampersands correctly.
|
||||
* Remove all "target" attributes from <a> tags.
|
||||
* Remove extraneous HTML, such as presentational tags that open and
|
||||
immediately close and <br clear="all">.
|
||||
* Convert hard-coded bullets into HTML unordered lists.
|
||||
* Remove stuff like "<p> </p>", but only if it's at the
|
||||
bottom of the text.
|
||||
"""
|
||||
# As clean_html is wrapped in allow_lazy, stacklevel 3 is more useful than 2.
|
||||
warnings.warn("The clean_html function is deprecated and will be removed in Django 1.8.",
|
||||
RemovedInDjango18Warning, stacklevel=3)
|
||||
text = normalize_newlines(text)
|
||||
text = re.sub(r'<(/?)\s*b\s*>', '<\\1strong>', text)
|
||||
text = re.sub(r'<(/?)\s*i\s*>', '<\\1em>', text)
|
||||
text = fix_ampersands(text)
|
||||
# Remove all target="" attributes from <a> tags.
|
||||
text = link_target_attribute_re.sub('\\1', text)
|
||||
# Trim stupid HTML such as <br clear="all">.
|
||||
text = html_gunk_re.sub('', text)
|
||||
# Convert hard-coded bullets into HTML unordered lists.
|
||||
|
||||
def replace_p_tags(match):
|
||||
s = match.group().replace('</p>', '</li>')
|
||||
for d in DOTS:
|
||||
s = s.replace('<p>%s' % d, '<li>')
|
||||
return '<ul>\n%s\n</ul>' % s
|
||||
text = hard_coded_bullets_re.sub(replace_p_tags, text)
|
||||
# Remove stuff like "<p> </p>", but only if it's at the bottom
|
||||
# of the text.
|
||||
text = trailing_empty_content_re.sub('', text)
|
||||
return text
|
||||
clean_html = allow_lazy(clean_html, six.text_type)
|
||||
|
||||
|
||||
def avoid_wrapping(value):
|
||||
"""
|
||||
Avoid text wrapping in the middle of a phrase by adding non-breaking
|
||||
|
||||
Reference in New Issue
Block a user