Textile & Markdown in Ruby

  • Digg this article
  • Sphinn this article
  • Stumble this article
  • Facebook
  • del.icio.us
  • LinkedIn
  • Twit this article

Thursday, 13 November 2008

Textile

Simple to implement with the redcloth gem

sudo gem install RedCloth

Usage,

require 'redcloth'
s = RedCloth.new "p. format this with textile"
puts s
Markdown

With markdown you've got three implementations to try,

  • bluecloth gem (last maintained 2005, slow)
  • rdiscount gem (better c implementation, fast!)
  • maruku gem (pure ruby implementation)

To implement with BlueCloth

sudo gem install bluecloth

Then,

require 'bluecloth'
s = BlueCloth::new("# format this with markdown")
puts s

Or RDiscount

sudo gem install rdiscount

Then,

require 'rdiscount'
s = RDiscount.new("# format this with markdown")
puts s
Comments
  1. Thomas GlasgowTuesday, 30 December 2008
    Hi John,

    We use rdiscount on our VoD website. It is extremely fast, and I guess some orders of magnitude faster than Bluecloth (untested). Do you know any easy way of adding custom tags for rdiscount to understand or do we have to roll our own additional parser for that purpose?

    I just noticed that you are now running your own blog engine, I'll have a look at it. I like it very much, but the captcha is too hard to guess.

    Best regards,
  2. johnWednesday, 31 December 2008
    Nice work and thanks, I finally switched Matilda over to RDiscount, remember to add this to your .bash_profile to make sure you can require gems ok.

    export RUBYOPT=rubygems

    I'll look at adding custom tags to the base, shouldn't be too hard; either that or add a filter as you suggested.

    All the best, have a great New Year.