[GH-ISSUE #321] Add rule to enforce links as reference links #275

Closed
opened 2026-03-03 01:25:19 +03:00 by kerem · 10 comments
Owner

Originally created by @mondeja on GitHub (Aug 25, 2020).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/321

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
Originally created by @mondeja on GitHub (Aug 25, 2020). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/321 As default deactivated. If active, raise error here: ```markdown I'm a paragraph with [a link](http://link-to-somewhere) ``` ...but passes this: ```markdown I'm a paragraph with [a link][link-to-somewhere] [link-to-somewhere]: http://link-to-somewhere ```
kerem 2026-03-03 01:25:19 +03:00
  • closed this issue
  • added the
    new rule
    label
Author
Owner

@waldyrious commented on GitHub (Aug 25, 2020):

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.

<!-- gh-comment-id:680123781 --> @waldyrious commented on GitHub (Aug 25, 2020): 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.
Author
Owner

@DavidAnson commented on GitHub (Aug 25, 2020):

Agree, I like the rule and the parameter suggestion.

<!-- gh-comment-id:680129159 --> @DavidAnson commented on GitHub (Aug 25, 2020): Agree, I like the rule and the parameter suggestion.
Author
Owner

@leetrout commented on GitHub (Aug 31, 2020):

@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
<!-- gh-comment-id:683946893 --> @leetrout commented on GitHub (Aug 31, 2020): @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: ```diff [link-to-somewhere]:http://link-to-somewhere ``` This would pass: ```diff [link-to-somewhere]: http://link-to-somewhere ```
Author
Owner

@DavidAnson commented on GitHub (Aug 31, 2020):

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

<!-- gh-comment-id:683982718 --> @DavidAnson commented on GitHub (Aug 31, 2020): It doesn't seem required by the specification, but I agree that one space is stylistically preferred. This would be a reasonable rule.
Author
Owner

@leetrout commented on GitHub (Aug 31, 2020):

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.

<!-- gh-comment-id:684008058 --> @leetrout commented on GitHub (Aug 31, 2020): [CommonMark deviates from this](https://spec.commonmark.org/0.29/#link-reference-definition) and says it is optional but it is mentioned explicitly in the original [Daring Fireball](https://daringfireball.net/projects/markdown/syntax#link) 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.
Author
Owner

@leetrout commented on GitHub (Aug 31, 2020):

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

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

<!-- gh-comment-id:684030823 --> @leetrout commented on GitHub (Aug 31, 2020): Opened https://github.com/DavidAnson/markdownlint/issues/326 Sorry to interrupt this, but thanks for the quick answers!
Author
Owner

@wolf99 commented on GitHub (Aug 27, 2022):

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

<!-- gh-comment-id:1229257445 --> @wolf99 commented on GitHub (Aug 27, 2022): I would like this as an optional rule, either with or without the space. (Though I prefer with the space)
Author
Owner

@wolf99 commented on GitHub (Oct 8, 2022):

Possible duplicate of #40 ?

<!-- gh-comment-id:1272394993 --> @wolf99 commented on GitHub (Oct 8, 2022): Possible duplicate of #40 ?
Author
Owner

@leetrout commented on GitHub (Oct 8, 2022):

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

<!-- gh-comment-id:1272395378 --> @leetrout commented on GitHub (Oct 8, 2022): Yes, looks like #40 covers the same functionality with more options.
Author
Owner

@DavidAnson commented on GitHub (Oct 8, 2022):

Agree, thanks!

<!-- gh-comment-id:1272397959 --> @DavidAnson commented on GitHub (Oct 8, 2022): Agree, thanks!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#275
No description provided.