Skip to content

Instantly share code, notes, and snippets.

@phalt
Created July 13, 2014 08:18
Show Gist options
  • Save phalt/3f5f6425483675fb73f8 to your computer and use it in GitHub Desktop.
Save phalt/3f5f6425483675fb73f8 to your computer and use it in GitHub Desktop.
Escape html and other common characters
def escape_html(text):
html_escape_table = {
"&": "&",
'"': """,
"'": "'",
">": ">",
"<": "&lt;",
}
return "".join(html_escape_table.get(c,c) for c in text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment