Code

Ticket #3532: reintroduce_space.diff

File reintroduce_space.diff, 823 bytes (added by shugyoku, 6 years ago)

Reintroduce spaces for anchor tags that enclose text

Line 
1Index: django/utils/html.py
2===================================================================
3--- django/utils/html.py        (revision 7424)
4+++ django/utils/html.py        (working copy)
5@@ -59,7 +59,10 @@
6 
7 def strip_spaces_between_tags(value):
8     """Returns the given HTML with spaces between tags removed."""
9-    return re.sub(r'>\s+<', '><', force_unicode(value))
10+    value = re.sub(r'>\s+<', '><', force_unicode(value))
11+    # Re-introduce the space between '/a>' and '<a ' adjacent anchor tags that enclose text
12+    # This is necessarily complex in order to avoid anchor tags between, say, 2 images having a space added   
13+    return re.sub(r'(\w)<\/a><a(\s+[^>]*)>(?=\w)', r'\1</a> <a\2>', force_unicode(value))
14 strip_spaces_between_tags = allow_lazy(strip_spaces_between_tags, unicode)
15 
16 def strip_entities(value):