mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add MD038, MD039 with tests.
This commit is contained in:
parent
b85e53a9c4
commit
7e431f4499
6 changed files with 98 additions and 11 deletions
51
lib/rules.js
51
lib/rules.js
|
@ -60,12 +60,14 @@ function forEachLine(params, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
// Calls the provided function for each text token
|
||||
function forEachText(params, callback) {
|
||||
// Calls the provided function for each specified inline child token
|
||||
function forEachInlineChild(params, type, callback) {
|
||||
filterTokens(params.tokens, "inline")
|
||||
.forEach(function forToken(token) {
|
||||
filterTokens(token.children, "text")
|
||||
.forEach(callback);
|
||||
filterTokens(token.children, type)
|
||||
.forEach(function forChild(child) {
|
||||
callback(child, token);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -275,7 +277,7 @@ module.exports = [
|
|||
"desc": "Reversed link syntax",
|
||||
"tags": [ "links" ],
|
||||
"func": function MD011(params, errors) {
|
||||
forEachText(params, function forToken(token) {
|
||||
forEachInlineChild(params, "text", function forToken(token) {
|
||||
if (/\([^)]+\)\[[^\]]+\]/.test(token.content)) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
|
@ -706,12 +708,49 @@ module.exports = [
|
|||
"desc": "Spaces inside emphasis markers",
|
||||
"tags": [ "whitespace", "emphasis" ],
|
||||
"func": function MD037(params, errors) {
|
||||
forEachText(params, function forToken(token) {
|
||||
forEachInlineChild(params, "text", function forToken(token) {
|
||||
if (/\s(\*\*?|__?)\s.+\1/.test(token.content) ||
|
||||
/(\*\*?|__?).+\s\1\s/.test(token.content)) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD038",
|
||||
"desc": "Spaces inside code span elements",
|
||||
"tags": [ "whitespace", "code" ],
|
||||
"func": function MD038(params, errors) {
|
||||
forEachInlineChild(params, "code_inline",
|
||||
function forToken(token, inline) {
|
||||
if (inline.content.indexOf("`" + token.content + "`") === -1) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD039",
|
||||
"desc": "Spaces inside link text",
|
||||
"tags": [ "whitespace", "links" ],
|
||||
"func": function MD039(params, errors) {
|
||||
filterTokens(params.tokens, "inline")
|
||||
.forEach(function forToken(token) {
|
||||
var inLink = false;
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type === "link_open") {
|
||||
inLink = true;
|
||||
} else if (child.type === "link_close") {
|
||||
inLink = false;
|
||||
} else if ((child.type === "text") &&
|
||||
inLink &&
|
||||
(child.content.trim().length !== child.content.length)) {
|
||||
errors.push(child.lineNumber);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue