markdownlint icon indicating copy to clipboard operation
markdownlint copied to clipboard

Add rule to enforce links as reference links

Open mondeja opened this issue 3 years ago • 7 comments

As default deactivated. If active, raise error here:

I'm a paragraph with [a link](http://link-to-somewhere)

...but passes this:

I'm a paragraph with [a link][link-to-somewhere]

[link-to-somewhere]: http://link-to-somewhere

mondeja avatar Aug 25 '20 11:08 mondeja

It would also be nice if this was configurable by the length of the URL — i.e. non-reference links shorter than N characters would not trigger this rule, with the default max length being 0.

waldyrious avatar Aug 25 '20 16:08 waldyrious

Agree, I like the rule and the parameter suggestion.

DavidAnson avatar Aug 25 '20 16:08 DavidAnson

@DavidAnson @mondeja Any interest in an additional rule to enforce correct style on reference links for at least one unit of whitespace after the colon?

This would fail:

[link-to-somewhere]:http://link-to-somewhere

This would pass:

[link-to-somewhere]: http://link-to-somewhere

leetrout avatar Aug 31 '20 18:08 leetrout

It doesn't seem required by the specification, but I agree that one space is stylistically preferred. This would be a reasonable rule.

DavidAnson avatar Aug 31 '20 19:08 DavidAnson

CommonMark deviates from this and says it is optional but it is mentioned explicitly in the original Daring Fireball docs:

Then, anywhere in the document, you define your link label like this, on a line by itself:

[id]: http://example.com/ "Optional Title Here"

That is:

Square brackets containing the link identifier (optionally indented from the left margin using up to three spaces); followed by a colon; followed by one or more spaces (or tabs); followed by the URL for the link; optionally followed by a title attribute for the link, enclosed in double or single quotes, or enclosed in parentheses.

leetrout avatar Aug 31 '20 20:08 leetrout

Opened https://github.com/DavidAnson/markdownlint/issues/326

Sorry to interrupt this, but thanks for the quick answers!

leetrout avatar Aug 31 '20 20:08 leetrout

I would like this as an optional rule, either with or without the space. (Though I prefer with the space)

wolf99 avatar Aug 27 '22 20:08 wolf99

Possible duplicate of #40 ?

wolf99 avatar Oct 08 '22 20:10 wolf99

Yes, looks like #40 covers the same functionality with more options.

leetrout avatar Oct 08 '22 20:10 leetrout

Agree, thanks!

DavidAnson avatar Oct 08 '22 21:10 DavidAnson