def encode(string):
    """Encode some critical characters to html entities."""
    return string.replace('&', '&amp;')           \
                 .replace('<', '&lt;')            \
                 .replace('>', '&gt;')            \
                 .replace('    ', '&nbsp;&nbsp;') \
                 .replace('\n', '<br>') if string else ''