markdownlint/lib/md025.js
Milos Levacic 45424cf459 Change "header" to "heading" across the library
This should be backward compatible, as all "header" aliases are still
available, though documented as discouraged for future use.
2018-04-18 22:27:48 -07:00

26 lines
726 B
JavaScript

// @ts-check
"use strict";
var shared = require("./shared");
module.exports = {
"names": [ "MD025", "single-h1" ],
"description": "Multiple top level headings in the same document",
"tags": [ "headings", "headers" ],
"function": function MD025(params, onError) {
var level = params.config.level || 1;
var tag = "h" + level;
var hasTopLevelHeading = false;
shared.filterTokens(params, "heading_open", function forToken(token) {
if (token.tag === tag) {
if (hasTopLevelHeading) {
shared.addErrorContext(onError, token.lineNumber,
token.line.trim());
} else if (token.lineNumber === 1) {
hasTopLevelHeading = true;
}
}
});
}
};