Tightened up how we clean up and present blank space in content.

master
Pacman Ghost 4 years ago
parent 7f4ae2676c
commit 13d6c8c12c
  1. 11
      asl_articles/utils.py
  2. 2
      web/src/SearchResults.css

@ -64,7 +64,7 @@ def make_ok_response( extras=None, updated=None, warnings=None ):
# ---------------------------------------------------------------------
def clean_html( val, allow_tags=None, safe_attrs=None ):
def clean_html( val, allow_tags=None, safe_attrs=None ): #pylint: disable=too-many-branches
"""Sanitize HTML using a whitelist."""
# check if we need to do anything
@ -108,15 +108,20 @@ def clean_html( val, allow_tags=None, safe_attrs=None ):
# clean up the results
while True:
buf = buf.strip()
prev_buf = buf
buf = re.sub( r"\s+", " ", buf )
buf = re.sub( " +", " ", buf ) # nb: we don't use "\s+" to preserve newlines
buf = re.sub( r"^\s+", "", buf, re.MULTILINE )
buf = re.sub( r"\s+$", "", buf, re.MULTILINE )
for tag in ["body","p","div","span"]:
for tag in ["body","div","span"]:
if buf.startswith( "<{}>".format(tag) ) and buf.endswith( "</{}>".format(tag) ):
buf = buf[ len(tag)+2 : -len(tag)-3 ]
if buf == prev_buf:
break
if buf.startswith( "<p>" ) and buf.endswith( "</p>" ):
buf2 = buf[ 3: -4 ]
if "<p>" not in buf2 and "</p>" not in buf2:
buf = buf2
return buf.strip()
def load_html_whitelists( app ):

@ -24,6 +24,8 @@
}
.search-result .content { padding: 2px 5px ; font-size: 90% ; }
.search-result .content p { margin-top: 0.25em ; }
.search-result .content p:first-child { margin-top: 0 ; }
.search-result .content .image { float: left ; margin: 0.25em 0.5em 0.5em 0 ; max-height: 5em ; }
.search-result .footer { padding: 0 5px ; font-size: 80% ; font-style: italic ; color: #666 ; }

Loading…
Cancel
Save