(s)
return mark_safe(re.sub(r"\s+", "&nbsp;", s))
collapses multiple whitespaces and replaces them with &nbsp;
collapses multiple whitespaces and replaces them with &nbsp;
collapses multiple whitespaces and replaces them with &nbsp ;
def nbsp(s):
    """collapses multiple whitespaces and replaces them with &nbsp;"""
    import re

    return mark_safe(re.sub(r"\s+", "&nbsp;", s))
def nbsp ( s ) : import re return mark_safe ( re . sub ( r"\s+" , "&nbsp;" , s ) )