Interesting post by Gustaf bemoaning the fact that he can't seem to find an easy way to implement a very useful clipboard manipulation process in Windows.
The basic user action is simple, select some text, copy, run the manipulator, paste. In this case Aristotle was using to hook markdown (and smartypants) into the process of entering text in the the browser, but you could just as easily use any text manipulation tool. It's a great trick, rather like Roberto de Almeida's Textile favelet but even more generic.
Anyway, cutting to the chase, this is possible in Windows, you just need the right tools to get and put stuff from the clipboard. Enter UnxUtils, this is a port of many GNU utilities to Windows (without the hassles of Cygwin), and tucked away in this mass of useful tools are pclip.exe and glip.exe - pclip puts the clipboard onto stdout, and gclip gets stdout into the clipboard. There's even a one line example of how to use sed with these to do some string replacement, like so:
pclip | sed "s/string1/string2/g" | gclip
The markdown example sounded interesting to me, so I've implemented it to use PyTextile. Being Windows there's always gotchas, but it's not that complicated.
First off PyTextile won't read/write from stin/stout by default, so I wrote a one-liner in Python to grab stdin, stuff it into textile and print the output to stdout, I'm calling this PipeTextile.py, and it's as below:
import textile, sys print textile.textile( ''.join( sys.stdin.readlines() ) )
Then I also needed a batch file to avoid having to type a long command line every time I want to run this process, I've put a shortcut to this on my taskbar, so the whole process is as quick as select, copy, click shortcut, paste. I've called the batch file TextileIt.cmd, and it's as below:
pclip | python PipeTextile.py | gclip
The only gotcha here is having to run the python interpreter explicitly because the windows shell is too stupid to run it implicitly. And that's it, problem solved, now I just need to brush up on my Textile syntax!