-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: markdownlint rule to disallow newline in link text (#69)
- Loading branch information
1 parent
ebf7835
commit f68f469
Showing
7 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { addError, filterTokens } = require('markdownlint/helpers'); | ||
|
||
module.exports = { | ||
names: ['EMD004', 'no-newline-in-links'], | ||
description: 'Newlines inside link text', | ||
tags: ['newline', 'links'], | ||
parser: 'markdownit', | ||
function: function EMD004(params, onError) { | ||
filterTokens(params, 'inline', (token) => { | ||
const { children } = token; | ||
let { lineNumber } = token; | ||
let inLink = false; | ||
for (const child of children) { | ||
const { type } = child; | ||
if (type === 'link_open') { | ||
inLink = true; | ||
} else if (type === 'link_close') { | ||
inLink = false; | ||
} else if (type === 'softbreak') { | ||
if (inLink) { | ||
addError(onError, lineNumber); | ||
break; | ||
} else { | ||
lineNumber++; | ||
} | ||
} | ||
} | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const EMD002 = require('./emd002.js'); | ||
const EMD003 = require('./emd003.js'); | ||
const EMD004 = require('./emd004.js'); | ||
|
||
module.exports = [EMD002, EMD003]; | ||
module.exports = [EMD002, EMD003, EMD004]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
This has [a link | ||
with a newline](https://google.com) | ||
|
||
This has [a link | ||
with a newline](https://google.com) | ||
|
||
This has [ | ||
a link with a newline](https://google.com) | ||
|
||
This has [a link with a newline | ||
](https://google.com) |