Skip to content

Commit

Permalink
Update MD054/link-image-style handling of url_inline to ensure link a…
Browse files Browse the repository at this point in the history
…nd destination match and that the destination is autolink-able (fixes #1040).
  • Loading branch information
DavidAnson committed Nov 15, 2023
1 parent ff46526 commit 41bc846
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
"strict": true,
"code_blocks": false
},
"link-image-style": {
"collapsed": false,
"shortcut": false,
"url_inline": false
},
"no-duplicate-heading": {
"siblings_only": true
},
Expand Down
2 changes: 1 addition & 1 deletion demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6673,7 +6673,7 @@ module.exports = {
if (destination) {
// link kind is an inline link
var title = getTokenTextByType(descendents, "resourceTitleString");
isError = !inline || !urlInline && autolink && !title && !image;
isError = !inline || !urlInline && autolink && !image && !title && label === destination && autolinkAble(destination);
} else {
// link kind is a full/collapsed/shortcut reference link
var isShortcut = !children.some(function (t) {
Expand Down
9 changes: 8 additions & 1 deletion lib/md054.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ module.exports = {
if (destination) {
// link kind is an inline link
const title = getTokenTextByType(descendents, "resourceTitleString");
isError = !inline || (!urlInline && autolink && !title && !image);
isError = !inline || (
!urlInline &&
autolink &&
!image &&
!title &&
(label === destination) &&
autolinkAble(destination)
);
} else {
// link kind is a full/collapsed/shortcut reference link
const isShortcut = !children.some((t) => t.type === "reference");
Expand Down
18 changes: 18 additions & 0 deletions test/link-style-no-url-inline-not-possible.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ Text <https://example.com> text {MD054}
[url]: https://example.com
[url-title]: https://example.com "title"

Text [link](https://example.com) text

Text ![link](https://example.com) text

Text [link][url] text

Text ![link][url] text

Text [url][] text

Text ![url][] text

Text [url] text

Text ![url] text

Text [file.md](file.md) text

<!-- markdownlint-configure-file {
"link-image-style": {
"autolink": false,
Expand Down
18 changes: 18 additions & 0 deletions test/link-style-no-url-inline-possible.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ Text <https://example.com> text
[url]: https://example.com
[url-title]: https://example.com "title"

Text [link](https://example.com) text

Text ![link](https://example.com) text

Text [link][url] text

Text ![link][url] text

Text [url][] text

Text ![url][] text

Text [url] text

Text ![url] text

Text [file.md](file.md) text

<!-- markdownlint-configure-file {
"link-image-style": {
"url_inline": false
Expand Down
36 changes: 36 additions & 0 deletions test/snapshots/markdownlint-test-scenarios.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -27049,6 +27049,24 @@ Generated by [AVA](https://avajs.dev).
[url]: https://example.com␊
[url-title]: https://example.com "title"␊
Text [link](https://example.com) text␊
Text ![link](https://example.com) text␊
Text [link][url] text␊
Text ![link][url] text␊
Text [url][] text␊
Text ![url][] text␊
Text [url] text␊
Text ![url] text␊
Text [file.md](file.md) text␊
<!-- markdownlint-configure-file {␊
"link-image-style": {␊
"autolink": false,␊
Expand Down Expand Up @@ -27136,6 +27154,24 @@ Generated by [AVA](https://avajs.dev).
[url]: https://example.com␊
[url-title]: https://example.com "title"␊
Text [link](https://example.com) text␊
Text ![link](https://example.com) text␊
Text [link][url] text␊
Text ![link][url] text␊
Text [url][] text␊
Text ![url][] text␊
Text [url] text␊
Text ![url] text␊
Text [file.md](file.md) text␊
<!-- markdownlint-configure-file {␊
"link-image-style": {␊
"url_inline": false␊
Expand Down
Binary file modified test/snapshots/markdownlint-test-scenarios.js.snap
Binary file not shown.

0 comments on commit 41bc846

Please sign in to comment.