mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD034/no-bare-urls to allow quoting bare URLs.
This commit is contained in:
parent
e319f9501c
commit
320acfd7cc
4 changed files with 28 additions and 5 deletions
|
@ -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>
|
||||
|
|
|
@ -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+)[.)]/;
|
||||
|
||||
|
|
10
lib/md034.js
10
lib/md034.js
|
@ -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 : [
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue