mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-18 06:50:12 +01:00
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`.
32 lines
1.1 KiB
JavaScript
32 lines
1.1 KiB
JavaScript
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;
|
|
});
|
|
}
|
|
};
|