2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorContext, filterTokens, frontMatterHasTitle } =
|
|
|
|
require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
2019-03-16 20:21:57 -07:00
|
|
|
"names": [ "MD025", "single-title", "single-h1" ],
|
2020-12-28 13:28:38 -08:00
|
|
|
"description": "Multiple top-level headings in the same document",
|
2018-03-19 23:39:42 +01:00
|
|
|
"tags": [ "headings", "headers" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD025(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;
|
2019-03-16 20:21:57 -07:00
|
|
|
const foundFrontMatterTitle =
|
2019-04-13 11:18:57 -07:00
|
|
|
frontMatterHasTitle(
|
2019-03-16 20:21:57 -07:00
|
|
|
params.frontMatterLines,
|
|
|
|
params.config.front_matter_title
|
|
|
|
);
|
2018-04-27 22:05:34 -07:00
|
|
|
let hasTopLevelHeading = false;
|
2019-04-13 11:18:57 -07:00
|
|
|
filterTokens(params, "heading_open", function forToken(token) {
|
2018-01-21 21:44:25 -08:00
|
|
|
if (token.tag === tag) {
|
2019-03-16 20:21:57 -07:00
|
|
|
if (hasTopLevelHeading || foundFrontMatterTitle) {
|
2019-04-13 11:18:57 -07:00
|
|
|
addErrorContext(onError, token.lineNumber,
|
2018-01-21 21:44:25 -08:00
|
|
|
token.line.trim());
|
|
|
|
} else if (token.lineNumber === 1) {
|
|
|
|
hasTopLevelHeading = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|