mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add MD026, MD027 with tests.
This commit is contained in:
parent
1112ac729d
commit
285a30e124
5 changed files with 109 additions and 15 deletions
72
lib/rules.js
72
lib/rules.js
|
|
@ -53,6 +53,19 @@ function forEachLine(params, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function forEachHeading(params, callback) {
|
||||||
|
var heading = null;
|
||||||
|
params.tokens.forEach(function forToken(token) {
|
||||||
|
if (token.type === "heading_open") {
|
||||||
|
heading = token;
|
||||||
|
} else if (token.type === "heading_close") {
|
||||||
|
heading = null;
|
||||||
|
} else if ((token.type === "inline") && heading) {
|
||||||
|
callback(heading, token.content);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function flattenLists(tokens, filterBy) {
|
function flattenLists(tokens, filterBy) {
|
||||||
var lists = [];
|
var lists = [];
|
||||||
var stack = [];
|
var stack = [];
|
||||||
|
|
@ -273,8 +286,7 @@ module.exports = [
|
||||||
"func": function MD014(params, errors) {
|
"func": function MD014(params, errors) {
|
||||||
filterTokens(params.tokens, "code_block", "fence")
|
filterTokens(params.tokens, "code_block", "fence")
|
||||||
.forEach(function forToken(token) {
|
.forEach(function forToken(token) {
|
||||||
if (token.content && token.content
|
if (token.content && token.content.split(shared.newLineRe)
|
||||||
.split(shared.newLineRe)
|
|
||||||
.filter(function filterLine(line) {
|
.filter(function filterLine(line) {
|
||||||
return line;
|
return line;
|
||||||
}).every(function forLine(line) {
|
}).every(function forLine(line) {
|
||||||
|
|
@ -392,19 +404,12 @@ module.exports = [
|
||||||
"name": "MD024",
|
"name": "MD024",
|
||||||
"desc": "Multiple headers with the same content",
|
"desc": "Multiple headers with the same content",
|
||||||
"func": function MD024(params, errors) {
|
"func": function MD024(params, errors) {
|
||||||
var content = [];
|
var knownContent = [];
|
||||||
var inHeading = false;
|
forEachHeading(params, function forHeading(heading, content) {
|
||||||
params.tokens.forEach(function forToken(token) {
|
if (knownContent.indexOf(content) === -1) {
|
||||||
if (token.type === "heading_open") {
|
knownContent.push(content);
|
||||||
inHeading = true;
|
} else {
|
||||||
} else if (token.type === "heading_close") {
|
errors.push(heading.lineNumber);
|
||||||
inHeading = false;
|
|
||||||
} else if ((token.type === "inline") && inHeading) {
|
|
||||||
if (content.indexOf(token.content) === -1) {
|
|
||||||
content.push(token.content);
|
|
||||||
} else {
|
|
||||||
errors.push(token.lineNumber);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -428,6 +433,43 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "MD026",
|
||||||
|
"desc": "Trailing punctuation in header",
|
||||||
|
"func": function MD026(params, errors) {
|
||||||
|
var punctuation = params.options.punctuation || ".,;:!?";
|
||||||
|
var re = new RegExp("[" + punctuation + "]$");
|
||||||
|
forEachHeading(params, function forHeading(heading, content) {
|
||||||
|
if (re.test(content)) {
|
||||||
|
errors.push(heading.lineNumber);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "MD027",
|
||||||
|
"desc": "Multiple spaces after blockquote symbol",
|
||||||
|
"func": function MD027(params, errors) {
|
||||||
|
var inBlockquote = false;
|
||||||
|
params.tokens.forEach(function forToken(token) {
|
||||||
|
if (token.type === "blockquote_open") {
|
||||||
|
inBlockquote = true;
|
||||||
|
} else if (token.type === "blockquote_close") {
|
||||||
|
inBlockquote = false;
|
||||||
|
} else if ((token.type === "inline") && inBlockquote) {
|
||||||
|
token.content.split(shared.newLineRe)
|
||||||
|
.forEach(function forLine(line, offset) {
|
||||||
|
if (/^\s/.test(line) ||
|
||||||
|
(!offset && /^\s*>\s\s/.test(token.line))) {
|
||||||
|
errors.push(token.lineNumber + offset);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "MD028",
|
"name": "MD028",
|
||||||
"desc": "Blank line inside blockquote",
|
"desc": "Blank line inside blockquote",
|
||||||
|
|
|
||||||
21
test/blockquote_spaces.md
Normal file
21
test/blockquote_spaces.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
Some text
|
||||||
|
|
||||||
|
> Hello world
|
||||||
|
> Foo {MD027}
|
||||||
|
> Bar {MD027}
|
||||||
|
|
||||||
|
This tests other things embedded in the blockquote:
|
||||||
|
|
||||||
|
> *Hello world*
|
||||||
|
> *foo* {MD027}
|
||||||
|
> **bar** {MD027}
|
||||||
|
> "Baz" {MD027}
|
||||||
|
> *foo*
|
||||||
|
> **bar**
|
||||||
|
> 'baz'
|
||||||
|
|
||||||
|
Test the first line being indented too much:
|
||||||
|
|
||||||
|
> Foo {MD027}
|
||||||
|
> Bar {MD027}
|
||||||
|
> Baz
|
||||||
11
test/header_trailing_punctuation.md
Normal file
11
test/header_trailing_punctuation.md
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Heading 1 {MD026}.
|
||||||
|
|
||||||
|
## Heading 2 {MD026},
|
||||||
|
|
||||||
|
## Heading 3 {MD026}!
|
||||||
|
|
||||||
|
## Heading 4 {MD026}:
|
||||||
|
|
||||||
|
## Heading 5 {MD026};
|
||||||
|
|
||||||
|
## Heading 6 {MD026}?
|
||||||
6
test/header_trailing_punctuation_customized.json
Normal file
6
test/header_trailing_punctuation_customized.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD026": {
|
||||||
|
"punctuation": ".,;:!"
|
||||||
|
}
|
||||||
|
}
|
||||||
14
test/header_trailing_punctuation_customized.md
Normal file
14
test/header_trailing_punctuation_customized.md
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Heading 1 {MD026}.
|
||||||
|
|
||||||
|
## Heading 2 {MD026},
|
||||||
|
|
||||||
|
## Heading 3 {MD026}!
|
||||||
|
|
||||||
|
## Heading 4 {MD026}:
|
||||||
|
|
||||||
|
## Heading 5 {MD026};
|
||||||
|
|
||||||
|
## Heading 6?
|
||||||
|
|
||||||
|
The rule has been customized to allow question marks while disallowing
|
||||||
|
everything else.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue