atom/markdown-preview — pull request #144 by chibicode (2014-10-26 20:40:03+00:00)
Title: Resolve images w/ absolute src paths to use the path from project root

This is a follow-up to changes made by @BinaryMuse and accepted by @probablycorey on #12, which made relative image URLs work on preview. I modified it slightly so that the absolute image URLs to resolve to the path from the project root.

### Before

`![](/images/test.jpg)` resolved to `/images/test.jpg`, because `path.resolve(..., "/absolute-path")` returns `/absolute-path`.

This is pretty useless in my opinion.

### After

If the current project directory is `/Users/shu/blog`, then `![](/images/test.jpg)` would resolve to `/Users/shu/blog/images/test.jpg`.

I think `absolute URL == from project root` makes more sense than `absolute URL == from filesystem root`, for displaying image previews.

### Use Case

This has been useful for me when I'm writing [Jekyll](http://jekyllrb.com/), because:

- My markdown files live in `category-name/_posts/*.md`
- My images live in `images/*.jpg`
- Jekyll serves my post at `http://localhost:4000/` and images at `http://localhost:4000/images/*.jpg`, so I'd use absolute image URLs in my markdown file, which wouldn't render currently. Relative URLs won't work b/c paths don't match.