Toxic Elephant

Don't bury it in your back yard!

Building a Simple Markdown Viewer with GirFFI

Posted by matijs 17/04/2012 at 07h41

This morning, I found myself looking for a simple markdown previewer that would run on the desktop. Using GirFFI, it was ridiculously easy to create it myself.

The simple version, based on the Webkit example in the GirFFI repository, goes something like this:

require 'ffi-gtk3'
require 'github/markup'

GirFFI.setup :WebKit, '3.0'
win = :toplevel
scr = nil, nil
wv =
win.add scr
scr.add wv
win.set_default_geometry 700, 500

file = ARGV[0]
fullpath = File.expand_path(file, Dir.pwd)
html = GitHub::Markup.render fullpath
wv.load_string html, nil, nil, "file://#{fullpath}"

GObject.signal_connect(win, "destroy") { Gtk.main_quit }

I got the basic version working in about 10 minutes. The more complex version adds a keyboard handler to allow reloading the viewed file.

Tags , 3 comments no trackbacks


  1. Stage Hypnotist said 12/05/2012 at 00h48:

    Thanks for the blog. Could you please update about the app, and a working demo would be great.

  2. Stage Hypnotist said 12/05/2012 at 01h26:

    Where did my comment go?

  3. pedyherve said 24/05/2012 at 10h20:

    Hi! I just wanted to ask if you ever have any trouble with hackers? My last blog (wordpress) was hacked and I ended up losing a few months of hard work due to no data backup. Do you have any methods to protect against hackers?


Use the following link to trackback from your own site:

Comments are disabled