A simple script for gathering missing Markdown links

As I was writing something else1, I got distracted by a common problem and threw together a quick script to deal with it. It seems like I’m pretty much the opposite of Brett Terpstra when I write; his awesome Markdown Service Tools has a service to turn a group of tabs in Safari or Chrome to a list of Markdown reference links. But for me, it’s a lot easier to write first and find links later, as a lot of the time I’m not linking to research I’m doing now but research I’ve done in the past. So usually what I’ll do when I want to link to something is simply include a link reference as I write (so, in the first link on this page, I’ve just put [Brett Terpstra][TERPstra]), and then promptly forget about them. When I finally get around to rendering the thing, I usually find a bunch of links I’ve forgotten to fill in.

So I just threw this together:

Essentially, it looks at a given file, identifies all the Markdown link references contained therein, and appends the reference marker at the end, waiting for the URL. So, running it on this file, I’ve got an eternally convenient [TERPstra]: reminding me to enter the URL at the bottom. I’m sure I’ll futz with this, and I’ll update this post when I do. (Immediate to-do: set it up to accept input from STDIN, so that I can use it as a filter in Sublime Text, and/or integrate it into my Markdown build system.)

Update: July 8, 2012

A simpler way to do this occurred to me almost immediately: make this a Sublime Text 2 Command. Since I’m already using Terpstra’s budding MarkdownEditing package, I just forked his and added the relevant command. Now, I can just hit ⌥⌘G, and all my markers are collected for me.


  1. I swear, it’s an upcoming post about how easily distracted I am.