Update MD034/no-bare-urls to allow quoting bare URLs.

This commit is contained in:
David Anson 2020-04-08 21:58:52 -07:00
parent e319f9501c
commit 320acfd7cc
4 changed files with 28 additions and 5 deletions

View file

@ -1262,7 +1262,14 @@ with `MD011`/`no-reversed-links`:
[https://www.example.com]
```
Rationale: Without angle brackets, the URL isn't converted into a link in many
The use of quotes around a bare link will _not_ trigger this rule, either:
```markdown
"https://www.example.com"
'https://www.example.com'
```
Rationale: Without angle brackets, the URL isn't converted into a link by many
markdown parsers.
<a name="md035"></a>

View file

@ -21,7 +21,7 @@ const inlineCommentRe =
module.exports.inlineCommentRe = inlineCommentRe;
// Regular expressions for range matching
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]]*/ig;
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*/ig;
module.exports.listItemMarkerRe = /^([\s>]*)(?:[*+-]|\d+[.)])\s+/;
module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;

View file

@ -24,10 +24,14 @@ module.exports = {
const matchIndex = match.index;
const bareUrlLength = bareUrl.length;
// Allow "[https://example.com]" to avoid conflicts with
// MD011/no-reversed-links
// MD011/no-reversed-links; allow quoting as another way
// of deliberately including a bare URL
const leftChar = content[matchIndex - 1];
const rightChar = content[matchIndex + bareUrlLength];
if (
(content[matchIndex - 1] !== "[") ||
(content[matchIndex + bareUrlLength] !== "]")
!((leftChar === "[") && (rightChar === "]")) &&
!((leftChar === "\"") && (rightChar === "\"")) &&
!((leftChar === "'") && (rightChar === "'"))
) {
const index = line.indexOf(content);
const range = (index === -1) ? null : [

View file

@ -16,3 +16,15 @@ The following are allowed to avoid conflicts with MD011/no-reversed-links:
[https://example.com]
[https://example.com/search?query=text]
The following are allowed to avoid conflicts with HTML-like syntax:
"https://example.com"
"https://example.com/search?query=text"
'https://example.com'
'https://example.com/search?query=text'
Other enclosures are not allowed:
(https://example.com) {MD034}
{https://example.com} {MD034}