Smart quotes!

Vardibidian asked if there was a Movable Type plugin that would change curved quotation marks and apostrophes into the appropriate HTML code, so it would look good in all browsers.

I wasn't sure, but it sounded like a great idea. I've always wanted to have "smart" quotes in my journal entries, but typing the appropriate HTML code by hand is a big pain--bad enough that I type the HTML code for em dashes by hand.

So I went looking, and I fairly quickly found SmartyPants, "a free web publishing plug-in for Movable Type, Blosxom, and BBEdit that easily translates plain ASCII punctuation characters into 'smart' typographic punctuation HTML entities." It works on quotation marks, apostrophes, em (and even en!) dashes, and apparently on ellipses (though I might turn that off). And it doesn't affect anything inside certain HTML tags whose contents should generally use plain ASCII quotation marks (like the <code> tag).

(Note that this doesn't do exactly what I think V. was asking about: it doesn't take Mac and Windows curly quotes and convert them to HTML entities. However, it may not be too hard to add that capability; I'll drop a note to the creator and ask for the feature, but I may also try to add it myself. At any rate, for now you have to feed it plain text.)

Nifty. I installed it--and nothing happened.

Some further poking around revealed to me that the original plugin (written in Perl) is inconsistent with MT's dynamic publishing system, for which plugins have to be written in PHP. This whole thing isn't documented as well as it might be; I get the impression that the MT system is still not entirely comfortable with dynamic publishing. (Those of you who have no idea what I'm talking about: "dynamic publishing" means that each page of my journal is generated on the fly when you request it. The system extracts the entry text from the database and adds the appropriate HTML code and sends it to your browser. In the other approach, "static publishing," the system generates all the web pages in advance and stores them on your server as individual files. Both approaches have advantages and disadvantages, and both have their proponents and detractors.)

Anyway, so eventually I found a PHP plugin version of SmartyPants. Installed that, then moved it to the right directory after realizing I'd put it in the wrong place, then changed "smarty_pants" to "smartypants" in my templates (on advice from the comments section of that PHP plugin page). And--voila!--it works!

I had been assuming that SmartyPants would modify the entry when I saved the entry, but that turns out not to be the case. Instead, SP modifies the entry at display time. So the text in the database still has plain straight up-and-down quotation marks, but when you look at an individual entry, the system smartens the quotes before passing the entry to your browser to be displayed. Nifty. This also means that it automatically applies to all my old entries without my having to do anything!

A couple of further notes:

  • If you copy and paste from my journal into a plain ASCII application, the quotes may go wonky. Sorry about that.
  • At the moment, quotes only get smartened in my entry body--not on the list-of-entries page, not in search results or monthly-archive or category pages, not in entry titles, not in comments. I'll probably switch everything over to use smart quotes soon, but I wanted to try it out in entry bodies first.
  • I may have broken the feeds in various ways. If this doesn't show up properly in LJ, lemme know.

...I should mention that this plugin isn't perfect. It does the wrong thing with an apostrophe at the beginning of a word (as in 'tis). And in foot/inch measurements (as in 5'10"), it converts the prime and double prime marks--which I was always told was bad typography (I was told those marks should be straight up and down), but Wikipedia says they should be slanted, so I must've just been confused. (But if you do want to keep those marks straight, you can escape them using backslashes: 5\'10\".)

One Response to “Smart quotes!”

  1. Nao

    Psst… the LJ feed served this up with straight quotes and double dashes.

    That does sound like a nifty plugin.

    reply

Join the Conversation