Tom's Miscellany

[Photo of fluffy white clouds in a sky which fades from dark blue at the top to a lighter blue at the bottom, with a lens flare in the top right quadrant of the image]

While googling for something vaguely unrelated, I’ve just come across a handy-looking technique for running John Gruber’s Markdown and SmartyPants scripts on the contents of the Windows clipboard.

You’ll need Cygwin, a Perl install (either Cygwin’s own or ActivePerl will do) and (somewhat obviously) a copy of the Markdown and SmartyPants perl scripts. After that, it’s as simple as creating a batch file to do the job:

C:\cygwin\bin\getclip.exe |
  C:\cygwin\bin\perl.exe "C:\Program Files\Markdown\Markdown.pl" |
  C:\cygwin\bin\perl.exe "C:\Program Files\SmartyPants\Smartypants.pl" |
  C:\cygwin\bin\putclip.exe

(Note: this needs to be all on one line.)

As an aside, there’s no reason you couldn’t achieve the same using PHP Markdown and PHP SmartyPants (using php -q to prevent it from outputting HTTP headers).

I’ve put a shortcut in my start menu and assigned it a ‘shortcut key’, so to format a window full of text I can now press:

  • CTRL+A (select all)
  • CTRL+C (copy)
  • CTRL+SHIFT+M (Markdown+SmartyPants)
  • CTRL+V (paste)

It seems a little long-winded when written out like that, but it’ll do for me.

Posted by Tom on Mon 21st Mar 2005.