mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-19 07:20:13 +01:00
Moved rules into their own files
Everything under `lib/rules/*` is a rules file (with the name of the rule in camelCase), re-exported into an array in `lib/rules.js`. Moved the regular expressions from `lib/rules.js` to `lib/expressions.js`, and the rest of the variables into `lib/shared.js`.
This commit is contained in:
parent
77e27cbe09
commit
b63647f6b1
43 changed files with 1283 additions and 1177 deletions
32
lib/rules/firstLineH1.js
Normal file
32
lib/rules/firstLineH1.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
module.exports = {
|
||||
"name": "MD041",
|
||||
"desc": "First line in file should be a top level header",
|
||||
"tags": [ "headers" ],
|
||||
"aliases": [ "first-line-h1" ],
|
||||
"regexp": null,
|
||||
"func": function MD041(params, errors) {
|
||||
var level = params.options.level || 1;
|
||||
var frontMatterTitle = params.options.front_matter_title;
|
||||
var tag = "h" + level;
|
||||
var frontMatterTitleRe =
|
||||
new RegExp(frontMatterTitle || "^\\s*title:", "i");
|
||||
params.tokens.every(function forToken(token, index) {
|
||||
if (token.type === "heading_open") {
|
||||
if (!((token.lineNumber === 1) || (index > 0)) ||
|
||||
(token.tag !== tag)) {
|
||||
errors.addContext(token.lineNumber, token.line);
|
||||
}
|
||||
return false;
|
||||
} else if (token.type === "html_block") {
|
||||
return true;
|
||||
}
|
||||
if (((frontMatterTitle !== undefined) && !frontMatterTitle) ||
|
||||
!params.frontMatterLines.some(function forLine(line) {
|
||||
return frontMatterTitleRe.test(line);
|
||||
})) {
|
||||
errors.addContext(token.lineNumber, token.line);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue