Escape code for html <pre> or <code> tag into clipboard

Here’s a speed up for posting code in a <pre> or <code> tag in an html page or blog. The script escapes all less than and greater than symbols (< with &lt; and > with &gt;) in a given file then puts the results in the clipboard to facilitate pasting into a text area or text editor. Save this in a file called escape-copy.sh:


#!/bin/bash
cat "$1" | sed s/\</\\\&lt\;/g | sed s/\>/\\\&gt\;/g | pbcopy

Posting the above code was super easy now, I just ran ./escape-copy.sh escape-copy.sh and pasted it in a <pre> tag.

Tags: , , , , , , , , ,

Leave a Reply