mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Add MD023, MD024, MD025 with tests.
This commit is contained in:
parent
2b289ab5f3
commit
1112ac729d
5 changed files with 80 additions and 0 deletions
53
lib/rules.js
53
lib/rules.js
|
|
@ -375,6 +375,59 @@ module.exports = [
|
|||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD023",
|
||||
"desc": "Headers must start at the beginning of the line",
|
||||
"func": function MD023(params, errors) {
|
||||
filterTokens(params.tokens, "heading_open")
|
||||
.forEach(function forToken(token) {
|
||||
if (/^\s/.test(token.line)) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD024",
|
||||
"desc": "Multiple headers with the same content",
|
||||
"func": function MD024(params, errors) {
|
||||
var content = [];
|
||||
var inHeading = false;
|
||||
params.tokens.forEach(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
inHeading = true;
|
||||
} else if (token.type === "heading_close") {
|
||||
inHeading = false;
|
||||
} else if ((token.type === "inline") && inHeading) {
|
||||
if (content.indexOf(token.content) === -1) {
|
||||
content.push(token.content);
|
||||
} else {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD025",
|
||||
"desc": "Multiple top level headers in the same document",
|
||||
"func": function MD025(params, errors) {
|
||||
var hasTopLevelHeading = false;
|
||||
filterTokens(params.tokens, "heading_open")
|
||||
.forEach(function forToken(token) {
|
||||
if (token.hLevel === 1) {
|
||||
if (hasTopLevelHeading) {
|
||||
errors.push(token.lineNumber);
|
||||
} else if (token.lineNumber === 1) {
|
||||
hasTopLevelHeading = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "MD028",
|
||||
"desc": "Blank line inside blockquote",
|
||||
|
|
|
|||
11
test/header_duplicate_content.md
Normal file
11
test/header_duplicate_content.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Header 1
|
||||
|
||||
## Header 2
|
||||
|
||||
## Header 1
|
||||
|
||||
### Header 2
|
||||
|
||||
## Header 3
|
||||
|
||||
{MD024:5} {MD024:7}
|
||||
3
test/header_multiple_toplevel.md
Normal file
3
test/header_multiple_toplevel.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Heading 1
|
||||
|
||||
# Heading 2 {MD025}
|
||||
4
test/headers_with_spaces_at_the_beginning.json
Normal file
4
test/headers_with_spaces_at_the_beginning.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD003": false
|
||||
}
|
||||
9
test/headers_with_spaces_at_the_beginning.md
Normal file
9
test/headers_with_spaces_at_the_beginning.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
Some text
|
||||
|
||||
# Header 1 {MD023}
|
||||
|
||||
Setext style fully indented {MD023}
|
||||
===================================
|
||||
|
||||
Setext style title only indented {MD023}
|
||||
=========================================
|
||||
Loading…
Add table
Add a link
Reference in a new issue