Skip to content

Reference Style Links are Converted (and lost) #34

@tajmone

Description

@tajmone

I wanted to carry on from issue #26 (now closed).

markdownfmt converts reference-styled links into normal inline links. Eg:

[link text][link id]  
[link id]: http://www.somelink.com      "my ref-link title

becomes:

[link text](http://www.somelink.com "my ref-link title")

I think this is quite an issue. A tidy-up tool shouldn't convert these links and remove the reference labels — tidy-markdown doesn't.

I would like to motivate this issue through real-use scenarios examples.

It is common practice when working with markdown documentation to store all links at the end of a document, in reference-link sections. This means that when a link changes, one only has to go at the bottom of all documents and change the links section and all links within the document will be «updated» (so to speak).

To give you an example: using RawGit to provide html live previews — the proper way to use RawGit for production links is to use the cdn.rawgit URL, which caches permanently the preview. So, usually links point to specific commits of the file, to prevent permanent caching of the master branch version. As files change in time, so do their RawGit preview URLs:

https://cdn.rawgit.com/username/repo/baf2857/somepath/index.html

after a new commit (hash: xyz1938) might become:

https://cdn.rawgit.com/username/repo/xyz1938/somepath/index.html

And so on with all links that use RawGit — the commit part of the URLs will have to change to accomodate the new commit hash.

And instead of going mad to search-and-replace all URLs inside the actual links, the quick way is to change it just in the links-section at the end of each document in the repo — something often automated with scripts in large documentation projects.

Basically, markdown makes life a lot easier with reference-styled links — I personally store some snippets files with all the links used in a project, carry out all changes to links in the snippet files, and then just copy-and-paste the whole links-section over the old one in all docs (yep: ALL DOCS, because unused link-ids are harmless, they just don't show up in the final preview of the document!).

In bigger projects, I use a pandoc toolchain, and invoke pandoc to always add/include the reference-links section file when processing sources — so the actual link-section is stored in a single file, used by all documents for all external links. This is a cool way to handle massive quantities of links. And it also allows to have different link-sections for different versions of a project (eg for a repo which is both on GitHub and Bitbucket) without having duplicate documents.

But Why?

What I haven't yet figure out is why blackfriday converts these links. Usually this happens in parsers which built an AST from the source (like pandoc), and in the post-processing phase they replace all references with their actual values. But I haven't yet worked my way into the source code enough to understand how it all works under the hood.

If this was the case, it might not be so easy to change this behavior. Any ideas about it?

But definitely, a clean-up tool shouldn't remove elements from the doc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions