June 2, 2008

Typing code in html

When I need to write a code in this blog in html, it's often a pain because the characters "&", ">" and "<" in the code are recognized as html commands. Command sed can help, substituting those characters with their html standards:

sed -e 's/\&/\&#38;/g' -e 's/</\&#60;/g' -e 's/>/\&gt;/g' < OriginalScript.sh > New.sh.html

Than just add around the script the fields <code> </code> and <pre> </pre>

No comments: