2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorDetailIf } = require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"names": [ "MD002", "first-heading-h1", "first-header-h1" ],
|
2020-12-28 13:28:38 -08:00
|
|
|
"description": "First heading should be a top-level heading",
|
2018-03-19 23:39:42 +01:00
|
|
|
"tags": [ "headings", "headers" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD002(params, onError) {
|
2020-01-25 18:40:39 -08:00
|
|
|
const level = Number(params.config.level || 1);
|
2018-04-27 22:05:34 -07:00
|
|
|
const tag = "h" + level;
|
2023-02-18 21:41:07 -08:00
|
|
|
params.parsers.markdownit.tokens.every(function forToken(token) {
|
2018-01-21 21:44:25 -08:00
|
|
|
if (token.type === "heading_open") {
|
2019-04-13 11:18:57 -07:00
|
|
|
addErrorDetailIf(onError, token.lineNumber, tag, token.tag);
|
2018-01-21 21:44:25 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|