Skip to content

Commit

Permalink
Update MD054/link-image-style to handle autolinked email addresses wh…
Browse files Browse the repository at this point in the history
…en disallowed (fixes #1391).
  • Loading branch information
DavidAnson committed Oct 28, 2024
1 parent 3b07268 commit a7a50ea
Show file tree
Hide file tree
Showing 16 changed files with 866 additions and 12 deletions.
4 changes: 2 additions & 2 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6721,9 +6721,9 @@ module.exports = {
let isError = false;
if (type === "autolink") {
// link kind is an autolink
destination = getDescendantsByType(link, [ "autolinkProtocol" ])[0].text;
destination = getDescendantsByType(link, [ [ "autolinkEmail", "autolinkProtocol" ] ])[0]?.text;
label = destination;
isError = !autolink;
isError = !autolink && Boolean(destination);
} else {
// link type is "image" or "link"
label = getDescendantsByType(link, [ "label", "labelText" ])[0].text;
Expand Down
4 changes: 2 additions & 2 deletions lib/md054.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ module.exports = {
let isError = false;
if (type === "autolink") {
// link kind is an autolink
destination = getDescendantsByType(link, [ "autolinkProtocol" ])[0].text;
destination = getDescendantsByType(link, [ [ "autolinkEmail", "autolinkProtocol" ] ])[0]?.text;
label = destination;
isError = !autolink;
isError = !autolink && Boolean(destination);
} else {
// link type is "image" or "link"
label = getDescendantsByType(link, [ "label", "labelText" ])[0].text;
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-autolink-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text

Text [url](https://example.com/an>g<le>) text {MD054}

Text <[email protected]> text

Text [[email protected]]([email protected]) text {MD054}

Text [[email protected]][email] text {MD054}

Text [email][] text {MD054}

Text [email] text {MD054}

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-reference-definitions": false,
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-autolink-or-inline.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text

Text [url](https://example.com/an>g<le>) text

Text <[email protected]> text

Text [[email protected]]([email protected]) text

Text [[email protected]][email] text {MD054}

Text [email][] text {MD054}

Text [email] text {MD054}

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-reference-definitions": false,
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-autolink-or-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text

Text [url](https://example.com/an>g<le>) text {MD054}

Text <[email protected]> text

Text [[email protected]]([email protected]) text {MD054}

Text [[email protected]][email] text

Text [email][] text

Text [email] text

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-style": {
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-collapsed-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text {MD054}

Text [url](https://example.com/an>g<le>) text {MD054}

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected]) text {MD054}

Text [[email protected]][email] text {MD054}

Text [email][] text

Text [email] text {MD054}

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-style": {
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-full-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text {MD054}

Text [url](https://example.com/an>g<le>) text {MD054}

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected]) text {MD054}

Text [[email protected]][email] text

Text [email][] text {MD054}

Text [email] text {MD054}

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-style": {
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-inline-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text {MD054}

Text [url](https://example.com/an>g<le>) text

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected])

Text [[email protected]][email] text {MD054}

Text [email][] text {MD054}

Text [email] text {MD054}

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-reference-definitions": false,
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-inline-or-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text {MD054}

Text [url](https://example.com/an>g<le>) text

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected]) text

Text [[email protected]][email] text

Text [email][] text

Text [email] text

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-style": {
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-no-url-inline-not-possible.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ Text ![url] text

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

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected]) text

Text [[email protected]][email] text

Text [email][] text

Text [email] text

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-image-style": {
"autolink": false,
Expand Down
13 changes: 13 additions & 0 deletions test/link-style-no-url-inline-possible.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ Text ![url] text

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

Text <[email protected]> text

Text [[email protected]]([email protected]) text
(allowed by !url_inline because email address is not an absolute URL)

Text [[email protected]][email] text

Text [email][] text

Text [email] text

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-image-style": {
"url_inline": false
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-none.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text {MD054}

Text [url](https://example.com/an>g<le>) text {MD054}

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected]) text {MD054}

Text [[email protected]][email] text {MD054}

Text [email][] text {MD054}

Text [email] text {MD054}

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-reference-definitions": false,
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-reference-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text {MD054}

Text [url](https://example.com/an>g<le>) text {MD054}

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected]) text {MD054}

Text [[email protected]][email] text

Text [email][] text

Text [email] text

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-style": {
Expand Down
12 changes: 12 additions & 0 deletions test/link-style-shortcut-only.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Text <https://example.com/pa)re(ns> text {MD054}

Text [url](https://example.com/an>g<le>) text {MD054}

Text <[email protected]> text {MD054}

Text [[email protected]]([email protected]) text {MD054}

Text [[email protected]][email] text {MD054}

Text [email][] text {MD054}

Text [email] text

[email]: [email protected]

<!-- markdownlint-configure-file {
"link-fragments": false,
"link-image-style": {
Expand Down
Loading

0 comments on commit a7a50ea

Please sign in to comment.