diff --git a/doc-build/md034.md b/doc-build/md034.md index e07e32e1..970758c2 100644 --- a/doc-build/md034.md +++ b/doc-build/md034.md @@ -19,11 +19,24 @@ Not a clickable link: `https://www.example.com` ``` Note: The following scenario does not trigger this rule because it could be a -valid shortcut link: +shortcut link: ```markdown [https://www.example.com] ``` +Note: The following syntax triggers this rule because the nested link could be +a shortcut link (which takes precedence): + +```markdown +[text [shortcut] text](https://example.com) +``` + +To avoid this, escape both inner brackets: + +```markdown +[link \[text\] link](https://example.com) +``` + Rationale: Without angle brackets, a bare URL or email isn't converted into a link by some Markdown parsers. diff --git a/doc/Rules.md b/doc/Rules.md index 7db9f408..1fb58e9b 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -1431,12 +1431,25 @@ Not a clickable link: `https://www.example.com` ``` Note: The following scenario does not trigger this rule because it could be a -valid shortcut link: +shortcut link: ```markdown [https://www.example.com] ``` +Note: The following syntax triggers this rule because the nested link could be +a shortcut link (which takes precedence): + +```markdown +[text [shortcut] text](https://example.com) +``` + +To avoid this, escape both inner brackets: + +```markdown +[link \[text\] link](https://example.com) +``` + Rationale: Without angle brackets, a bare URL or email isn't converted into a link by some Markdown parsers. diff --git a/doc/md034.md b/doc/md034.md index 084b1fbb..eca0db1b 100644 --- a/doc/md034.md +++ b/doc/md034.md @@ -27,11 +27,24 @@ Not a clickable link: `https://www.example.com` ``` Note: The following scenario does not trigger this rule because it could be a -valid shortcut link: +shortcut link: ```markdown [https://www.example.com] ``` +Note: The following syntax triggers this rule because the nested link could be +a shortcut link (which takes precedence): + +```markdown +[text [shortcut] text](https://example.com) +``` + +To avoid this, escape both inner brackets: + +```markdown +[link \[text\] link](https://example.com) +``` + Rationale: Without angle brackets, a bare URL or email isn't converted into a link by some Markdown parsers. diff --git a/test/bare-urls.md b/test/bare-urls.md index 00c1813c..2455fe39 100644 --- a/test/bare-urls.md +++ b/test/bare-urls.md @@ -76,3 +76,15 @@ Links with spaces inside angle brackets are okay: [blue jay]( + +--- + +[is-a-valid]: https://example.com + +Links bind to the innermost [link that [is-a-valid] link](https://example.com) {MD034} + +But not if the [link [is-not-a-valid] link](https://example.com) {MD034} +HOWEVER this scenario could have an invalid shortcut and IS reported + +Escaping both inner square brackets avoids the unwanted report: +[link \[is-not-a-valid\] link](https://example.com) diff --git a/test/snapshots/markdownlint-test-scenarios.js.md b/test/snapshots/markdownlint-test-scenarios.js.md index 463b88c7..a397170c 100644 --- a/test/snapshots/markdownlint-test-scenarios.js.md +++ b/test/snapshots/markdownlint-test-scenarios.js.md @@ -3164,6 +3164,46 @@ Generated by [AVA](https://avajs.dev). 'no-bare-urls', ], }, + { + errorContext: 'https://example.com', + errorDetail: null, + errorRange: [ + 59, + 19, + ], + fixInfo: { + deleteCount: 19, + editColumn: 59, + insertText: '', + }, + lineNumber: 84, + ruleDescription: 'Bare URL used', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md', + ruleNames: [ + 'MD034', + 'no-bare-urls', + ], + }, + { + errorContext: 'https://example.com', + errorDetail: null, + errorRange: [ + 45, + 19, + ], + fixInfo: { + deleteCount: 19, + editColumn: 45, + insertText: '', + }, + lineNumber: 86, + ruleDescription: 'Bare URL used', + ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md', + ruleNames: [ + 'MD034', + 'no-bare-urls', + ], + }, ], fixed: `# Detailed Results Bare URLs␊ ␊ @@ -3243,6 +3283,18 @@ Generated by [AVA](https://avajs.dev). Email addresses are treated similarly: {MD034}␊ ␊ Angle brackets work the same for email: ␊ + ␊ + ---␊ + ␊ + [is-a-valid]: https://example.com␊ + ␊ + Links bind to the innermost [link that [is-a-valid] link]() {MD034}␊ + ␊ + But not if the [link [is-not-a-valid] link]() {MD034}␊ + HOWEVER this scenario could have an invalid shortcut and IS reported␊ + ␊ + Escaping both inner square brackets avoids the unwanted report:␊ + [link \\[is-not-a-valid\\] link](https://example.com)␊ `, } diff --git a/test/snapshots/markdownlint-test-scenarios.js.snap b/test/snapshots/markdownlint-test-scenarios.js.snap index 1fe795a1..1ef50537 100644 Binary files a/test/snapshots/markdownlint-test-scenarios.js.snap and b/test/snapshots/markdownlint-test-scenarios.js.snap differ