-
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 opening angle brackets (#50)
- Loading branch information
1 parent
84c79b4
commit 33b2a5c
Showing
8 changed files
with
500 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,25 @@ | ||
const { addError, filterTokens } = require('markdownlint/helpers'); | ||
|
||
module.exports = { | ||
names: ['EMD002', 'no-angle-brackets'], | ||
description: 'No unescaped opening angle brackets in text (does not play nice with MDX)', | ||
tags: ['brackets'], | ||
function: function EMD002(params, onError) { | ||
filterTokens(params, 'inline', (token) => { | ||
for (const childToken of token.children) { | ||
// childToken.line has the raw content, but may also contain | ||
// more content than just childToken.content. This may cause | ||
// the same line to produce multiple errors, unfortunately. | ||
if ( | ||
childToken.type === 'text' && | ||
childToken.markup !== '<' && | ||
childToken.markup !== '<' && | ||
childToken.content.includes('<') && | ||
childToken.line.match(/(?<!\\)</g) !== null | ||
) { | ||
addError(onError, token.lineNumber, 'Unescaped opening angle bracket'); | ||
} | ||
} | ||
}); | ||
}, | ||
}; |
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,6 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`electron-markdownlint should not allow opening angle brackets if EMD002 enabled 1`] = ` | ||
"<root>angle-brackets.md:114 EMD002/no-angle-brackets No unescaped opening angle brackets in text (does not play nice with MDX) [Unescaped opening angle bracket] | ||
" | ||
`; |
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
Oops, something went wrong.