mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add level parameter to MD002/MD025/MD041 (fixes #19).
This commit is contained in:
parent
7a1773ea77
commit
f2060b4607
6 changed files with 51 additions and 15 deletions
14
lib/rules.js
14
lib/rules.js
|
|
@ -170,13 +170,15 @@ module.exports = [
|
|||
|
||||
{
|
||||
"name": "MD002",
|
||||
"desc": "First header should be a h1 header",
|
||||
"desc": "First header should be a top level header",
|
||||
"tags": [ "headers" ],
|
||||
"aliases": [ "first-header-h1" ],
|
||||
"func": function MD002(params, errors) {
|
||||
var level = params.options.level || 1;
|
||||
var tag = "h" + level;
|
||||
params.tokens.every(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
if (token.tag !== "h1") {
|
||||
if (token.tag !== tag) {
|
||||
errors.push(token.lineNumber);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -536,9 +538,11 @@ module.exports = [
|
|||
"tags": [ "headers" ],
|
||||
"aliases": [ "single-h1" ],
|
||||
"func": function MD025(params, errors) {
|
||||
var level = params.options.level || 1;
|
||||
var tag = "h" + level;
|
||||
var hasTopLevelHeading = false;
|
||||
filterTokens(params, "heading_open", function forToken(token) {
|
||||
if (token.tag === "h1") {
|
||||
if (token.tag === tag) {
|
||||
if (hasTopLevelHeading) {
|
||||
errors.push(token.lineNumber);
|
||||
} else if (token.lineNumber === 1) {
|
||||
|
|
@ -886,6 +890,8 @@ module.exports = [
|
|||
"tags": [ "headers" ],
|
||||
"aliases": [ "first-line-h1" ],
|
||||
"func": function MD041(params, errors) {
|
||||
var level = params.options.level || 1;
|
||||
var tag = "h" + level;
|
||||
var firstHeader = null;
|
||||
params.tokens.every(function forToken(token) {
|
||||
if (token.type === "heading_open") {
|
||||
|
|
@ -898,7 +904,7 @@ module.exports = [
|
|||
});
|
||||
if (!firstHeader ||
|
||||
(firstHeader.lineNumber !== 1) ||
|
||||
(firstHeader.tag !== "h1")) {
|
||||
(firstHeader.tag !== tag)) {
|
||||
errors.push(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue