2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
2019-03-13 21:39:15 -07:00
|
|
|
"names": [ "MD041", "first-line-heading", "first-line-h1" ],
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "First line in file should be a top level heading",
|
|
|
|
"tags": [ "headings", "headers" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD041(params, onError) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const level = params.config.level || 1;
|
|
|
|
const tag = "h" + level;
|
2019-03-16 20:21:57 -07:00
|
|
|
const foundFrontMatterTitle =
|
|
|
|
shared.frontMatterHasTitle(
|
|
|
|
params.frontMatterLines,
|
|
|
|
params.config.front_matter_title
|
|
|
|
);
|
2019-03-10 22:10:33 -07:00
|
|
|
if (!foundFrontMatterTitle) {
|
|
|
|
params.tokens.every((token) => {
|
|
|
|
if (token.type === "html_block") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((token.type !== "heading_open") || (token.tag !== tag)) {
|
2018-01-21 21:44:25 -08:00
|
|
|
shared.addErrorContext(onError, token.lineNumber, token.line);
|
|
|
|
}
|
2019-03-10 22:10:33 -07:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
};
|