It may be true that smart quotes are a detail appreciated only by design geeks and typography nerds. But it’s equally true that I am both a design geek and a typography nerd. Call me nuts, but I like my quotes curly.
Last December’s version of the code that powers this website included my second attempt at a “quote educator.” It, too, suffered a fatal flaw: about 30% of the time, quotes curled the wrong way.
It’s a lot more complicated than you might think. “Realize,” for example, “that you’ll want ‘nested quotes.’” You’ll want to answer in straight quotes when someone asks your height (6'1") but in curly quotes when someone asks what year your old Camaro was (“69”). And although you can’t see the problem from your side of the browser, the presence of HTML markup makes the task even more difficult.
Enter John Gruber, who like me had worked through at least one less-than-ideal solution. Unlike me, he had attacked the problem again and came up with an excellent solution, which he released as open-source software: SmartyPants — which by the time I found it had been public for a year, and improved through user feedback during that time.
Using SmartyPants in my Monaural Jerk code seemed infinitely more sane than spending time on a 3rd attempt of my own. There was only one problem: SmartyPants was written in PERL, which although wonderful in many ways, would not coexist very effectively with Monaural Jerk, which is written in PHP.
So I ported it. It took all weekend. I thought I knew about regular expressions, but I can honestly say, now I know about regular expressions.
Anyway, the result is here: SmartyPants-PHP
SmartyPants-PHP is, in one sentence, an HTML-savvy quote-conversion library. In another sentence, it is a derivative product of John Gruber’s original code, and he deserves all the credit for the invention. I only translated it, and tried not to break it too badly in the process.