Escaping HTML so you can quote it in HTML

2004-02-26 10:13:00 +0000

Quick tip: How to escape HTML text so that it can be quoted in another piece of HTML, e.g. in a <pre> tag.

cat index.html | \
    sed 's/&/\&/' | \
    sed 's/"/\"/' | \
    sed 's/</\</' | \
    sed 's/>/\>/'

There’s probably a simpler way to do this, but it works for me, so I’m putting it here before I forget.