Using marked as an nvalt wiki viewer

screenYes! This is not a literary post, but for some people it might be interesting… If you don’t know what markdown is then probably this is not for you, or it might be a chance to investigate. Since I discovered markdown I try to write almost everything using it. Nvalt for my notes and Ulysses for longer texts

Now with the new marked update it is possible to use it as a viewer of a nvalt wiki (both applications are written by the awesome Brett Terpstra). I use nvalt to keep all the notes of the books and articles I read, my reading lists, ideas, etc… Its super fast search is great for quickly getting to the note I’m looking for. The only problem is that the nvalt previewer is not that nice yet… marked is a much better tool for that task.

Now that marked can handle opening files much better, the only problem to tackle is to transform the nvalt [[links]] to correct markdown [links](/Users/yseult/Documents/file.txt). This can be done with a super simple custom preprocessor. See the code below in ruby. The only smart thing going on here happens in line 19 which, as all regular expressions, is a bit difficult to read.

require 'uri'

NVALT_DIR = "/path/to/your/nvalt/dir"

def replace_chars(s)

if RUBY_VERSION.to_f > 1.9
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8
  content ='utf-8')
  content =

if File.dirname(ENV['MARKED_PATH']) == NVALT_DIR then
	content.gsub!(/\[\[(.*?)\]\]/) {"[#{$1}](#{URI.encode(NVALT_DIR+'/'+replace_chars($1)+"."+ENV['MARKED_EXT'])})"}

STDOUT.puts content

In line 4 replace the path to the directory where you keep your nvalt notes. Other issue to notice: I replace ‘:’ for ‘-‘ because nvalt files also does that. Probably Brett replaces other problematic characters as well, but this is the only one that I have found so far in my notes

The preprocessor checks if the file is in the nvalt dir, if not it will skip it.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s