Refactor rewriting URL's for non-markdown files

Fixes #292

Not totally happy with this yet, but this is a first stab at the issue.