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 Gtk.init win = Gtk::Window.new :toplevel scr = Gtk::ScrolledWindow.new nil, nil wv = WebKit::WebView.new win.add scr scr.add wv win.set_default_geometry 700, 500 win.show_all

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 } Gtk.main

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 , 2 comments no trackbacks

Comments

  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?

Comments are disabled