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.

1

Interesting, I didn’t know you could do this in Windows.

Improving it would probably require doing the copy and paste automatically. There may be a way, but unless it simulates CTRL-C and CTRL-V it won’t work in all applications. Surely you could make a Word macro for this, but do you use need Markdown in Word?

Michel Fortin Wed Jun 1st, 3:17am.

Anyone know of a better way to do it?

  • Your email address will not be published.
  • Gravatars will be displayed.
  • Markdown is enabled (but won't show up on the preview).