seth-brown / formd

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

Handle indented reference-links #14

Closed anko closed 9 years ago

anko commented 9 years ago

Spaces before link references are valid Markdown, by John Gruber's spec: "[references should be] optionally indented from the left margin using up to three spaces". Common example from the wild: StackExchange sites use two spaces.

Formd currently disregards indented references.

This change makes it recognise such references when converting link styles from reference→inline, or when just formatting reference-style links. The inline→reference conversion is unaffected.

seth-brown commented 9 years ago

Thanks for the PR. I'll try to look and see if I can help. Can you provide a minimal working example of where you see the bug? Maybe a small sample of markdown where the match is failing?

anko commented 9 years ago

@drbunsen The first commit adds a runnable test case.


English walkthrough: formd correctly notices references with no spaces in front of them

[Markdown][1]

[1]: http://en.wikipedia.com/wiki/Markdown

but fails to recognise references that do have spaces in front of them

[Markdown][1]

  [1]: http://en.wikipedia.com/wiki/Markdown

Both examples above should inline into

[Markdown](http://en.wikipedia.org/wiki/Markdown)

but currently only the first one does. The second one inlines into

[Markdown](1)

  [1]: http://en.wikipedia.com/wiki/Markdown

because the indented reference isn't parsed.

seth-brown commented 9 years ago

Thanks for your work. I've resolved the issue in the following commit. Please let me know if you noticed any other issues. Thanks again!

https://github.com/drbunsen/formd/commit/3e08bc679dabe8ea402b373820c3c990ffee013f

anko commented 9 years ago

Thanks for the fix! That's the only issue I've encountered. :+1: