Using the Ruby BlueCloth Library(for Markdown)

  1. Attention folks who used this before 11:54 P.M. US Central Time on May 3rd. I fixed a typo in the instructions from gem install ruby to gem install bluecloth.
  2. Install the BlueCloth module by typing in sudo gem install bluecloth. For Windows, you can simply type in gem install bluecloth
  3. Here is the code I created to make it easy to convert Markdown-formatted documents to HTML:
  4. #!/usr/bin/env ruby


    if RUBY_PLATFORM =~ /darwin/

    require rubygems
    require_gem BlueCloth, >=0.0.4
    else
    require BlueCloth

    end

    s = “”
    ARGF.each do |line|
    s << line
    end
    doc = BlueCloth::new(s)
    File.open(markup.html,w) do |file|
    file << doc.to_html
    end

To actually use the code, you can do this:

Download the plaintext script from the Blue Box widget to your left(it is called markit.rb)

*nix, OS X, go to the directory you put this script in, and type in Terminal: ruby markit.rb <yourfile.txt>

where <yourfile.txt> is a placeholder for your actual text file containing the markdown markup (hehe, is that an oxymoron or what). Your result will be put into the file in the same directory called markup.html.

I’ll try to provide a simple GUI frontend for this script(with a file chooser or something else) on of these days, depending on my free time.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s