Toxic Elephant

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 , 3 comments Trackbacks

Comments

  1. %>

    pedyherve said 24/05/2012 at 10h20 later:

    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?

  2. %>

    Stage Hypnotist said 12/05/2012 at 01h26 later:

    Where did my comment go?

  3. %>

    Stage Hypnotist said 12/05/2012 at 00h48 later:

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

No trackbacks

Comments are disabled

Toxic Elephant is Matijs van Zuijlen's weblog.

Powered