Escaping HTML from the command line
17/12/07 16:43 Filed in: Web Development
If you want to escape HTML from the command line you can use the following one-liner:
To use this command, pipe it some HTML:
If you find yourself using this command frequently your fingers will start screaming for relief. When this happens you might want to store the command as an alias. For CSH:
You can then escape your HTML more concisely:
$ ruby -e "require 'cgi'; puts CGI.escapeHTML(STDIN.gets)"
To use this command, pipe it some HTML:
$ echo "<p>Brilliant!</p>" | ruby -e "require 'cgi'; puts CGI.escapeHTML(STDIN.gets)"
If you find yourself using this command frequently your fingers will start screaming for relief. When this happens you might want to store the command as an alias. For CSH:
$ alias htmlify 'ruby -e "require '\'cgi\' '; puts CGI.escapeHTML(STDIN.gets)"'
You can then escape your HTML more concisely:
$ echo "<p>Brilliant!</p>" | htmlify
|