seth-brown / formd

A Markdown formatting tool
MIT License
147 stars 19 forks source link

Inline converter doesn't split on whitespace. #2

Closed rouge8 closed 12 years ago

rouge8 commented 12 years ago

When converting to inline links, splitting on whitespace prevents using things like template variables in your links.

e.g.

[1]: {{ site.photos }}/hello.jpg

would become

![description]({{)

I don't know how common this is, and it doesn't seem to go against the markdown spec (it's also accepted by maruku, kramdown, and rdiscount FWIW), but it's something I use with Jekyll.

seth-brown commented 12 years ago

I also use Jekyll and think Liquid support is a good idea. However, I'm unfamiliar with the Liquid syntax you describe in your example.

When converting from referenced to inline, how does ![description]({{) denote the photo hello.jpg? There is no reference to the file path?

rouge8 commented 12 years ago

Oh sorry, I was describing the bug.

I started with this: ![description]({{ site.photos }}/hello.jpg

I converted to reference links and got this [1]: {{ site.photos }}/hello.jpg

I converted back to inline once more and got ![description]({{), which is incorrect.

With my commit, after I convert back from reference links, I get ![description]({{ site.photos }}/hello.jpg, which is expected.

Is that clearer?

seth-brown commented 12 years ago

Ok, I'm clear with what you are describing now. Thanks for the added details.

The only complication I see with your pull is with breaking certain referenced markdown syntax when it is converted from referenced to inline. For example:

This is [an example][foo] reference-style link.

[foo]: http://example.com/ (Optional Title Here)

The above example when switched to inline gives:

This is [an example](http://example.com/ (Optional Title Here)) reference-style link.

I've tried three different markdown engines all of which render this inline markdown differently:

Maruku renders: This is an example) reference-style link. Marked renders: This is [an example](http://example.com/ (Optional Title Here)) reference-style link. nvALT gives: This is an example reference-style link.

Using parentheses with the optional title is the only case where problems arise. Using quotes "Optional Title Here" renders correctly.

I believe nvALT uses a multi-markdown engine, so that may explain why it is producing the correct HTML.