Using SmartyPants with Haml
If only a tiny fraction of you is a typography nut, you probably adore correct punctuation and correct use of quotation marks. Despite that, maybe you simply do not remember the awkward keystrokes required to actually type those marks in your prose, though. (On the Mac, Option-[ and Cmd-Option-[ for example.)
Luckily, John Gruber created a Perl tool called SmartyPants several years back, which will take care of converting straight quotes into curly quotes, regular dashes into em-dashes and so forth. It has since been adopted as an optional filter-mode for most (if not all) of the modern Markdown implementations.
:markdown Using filters, embedding [Markdown](http://daringfireball.net/projects/markdown/) is *easy*.
With proper indentation (and the availability of a supported Markdown interpreter such as RDiscount), Haml will automatically render the indented parts using Markdown.
Speaking of RDiscount, it also supports the
:smart option, which will apply the punctuation transformations of SmartyPants to the given text. This is, however, not supported in the standard
:markdown filter syntax of Haml.
It's very simple to build your own filter, though:
# config/initializers/markdown_smart.rb module Haml::Filters::MarkdownSmart include Haml::Filters::Base def render(text) RDiscount.new(text, :smart).to_html end end
With this file in place in, for example,
config/initializers/markdown_smart.rb, you can now use the
:markdownsmart filter in your templates to render Markdown text and to automatically convert your punctuation to "smart" punctuation based on SmartyPants.