The original post has been merged into the formal proposal.
Markdown provides multiple ways to create links. It would be useful to have refactorings that convert between inline and reference links. Doing it manually all the time makes me quite sad.
There are totally 12 kinds of conversions.
The following seem always feasible:
Inline <=> Full <- Collapsed <- Shortcut
| From | To |
| --------- | --------- |
| Inline | Full |
| Full | Inline |
| Collapsed | Inline |
| Collapsed | Full |
| Shortcut | Inline |
| Shortcut | Full |
| Shortcut | Collapsed |
Out of reliability and compatibility concern, the other 5 conversions are possible only under certain circumstances.
In practice, the 5 kinds below should be enough:
| From | To |
| --------- | --------- |
| Inline | Full |
| Inline | Collapsed |
| Full | Inline |
| Collapsed | Inline |
| Shortcut | Inline |
The Inline -> Collapsed conversion is available only if no brackets ([ or ]) are next to the link, and the link text matches JavaScript regular expression /^[\w-]+$/ (only contains ASCII letters, digits, underscore, and hyphen).
One inline link to full or collapsed reference link.
< and >.") first, then '.<!-- From: -->
[My [simple] link](<uri uri> 'title \'n )(title')
<!-- To: -->
[My [simple] link][2_ref-def]
All inline links with the same destination and title to full reference links.
<!-- From: -->
A [fox](<uri uri> 'title') jumped over a lazy dog. The [fox][] was brown. [It](uri%20uri (title)) moved very quickly.
<!-- To: -->
A [fox][fox] jumped over a lazy dog. The [fox][] was brown. [It][fox] moved very quickly.
One reference link to inline link.
All reference links with the same link reference definition to inline links.
<!-- From: -->
A [fox] jumped over a lazy dog. The [fox][] was brown. [It][fox] moved very quickly.
<!-- To: -->
A [fox](<uri%20uri> "title") jumped over a lazy dog. The [fox](<uri%20uri> "title") was brown. [It](<uri%20uri> "title") moved very quickly.
Code spans and code blocks should remain untouched.
`````markdown
<!-- Do not touch: -->
dog`
[foo] [bar](/uri)
``````
Consecutive links should remain untouched. Too dangerous to process them.
<!-- Do not touch: -->
[link1](/uri1 "title")[link2](uri2)[link3](</uri 3>)
<!-- Below is OK: -->
[link1](/uri1 "title") [link2](uri2) [link3](</uri 3>)
Here is a node.js program I found if it can help:
https://github.com/bjfletcher/convert-markdown-inlined-links-to-references/blob/master/main.js
I agree that it might be useful. But I probably have little time for this in the near future. Let's see whether there is somebody can help.
I don't have that much time the two next weeks neither but I could definitely help creating it after. 😃
Most helpful comment
I don't have that much time the two next weeks neither but I could definitely help creating it after. 😃