Writing HTML in textareas made convenient: a Markdown praise

Aristotle on 2005-05-21T17:37:37

This is mostly in reply to “learning GTK+, parsing” by statico, who unfortunately does not have comments enabled.

Personally, I make things easier on myself by using Markdown and SmartyPants. If you haven’t seen Markdown, you’re really missing out. It is the plaintext-to-HTML formatter to end all formatters. The syntax is as close to intuitive as it can possibly get; if you’ve ever seen plaintext email, you’ve basically seen Markdown, and the translation to HTML looks pretty much the way such a mail would reasonably look like if it had been authored as a web page.

Hooking Markdown into the browser, and in fact into any application that has text input widgets at all, is actually simpler than might at first appear: you just need xclip (or some equivalent, I suppose, if you’re not on X11). This little tool can dump any of the X11 selections, such as the clipboard, to its stdout or slurp its stdin into one of the selections.

Thus, I have this shell oneliner bound to a keyboard shortcut in my window manager:

xclip -o -sel clip | Markdown | SmartyPants -2 | xclip -sel clip

With that in place, I simply write my entries in a natural format, then I copy, hit a key, and paste, and there they are, turned to HTML and typographically smartened. Presto.

An advantage of this solution over many tools is that it will work for everything, regardless of whether I’m using a webblogging tool, writing a comment on some foreign weblog, posting on PerlMonks, or anywhere else you can imagine. One keystroke, and there you go. No muss, no fuss.