2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-13 11:18:57 -07:00
|
|
|
const { addErrorContext, filterTokens, rangeFromRegExp } =
|
|
|
|
require("../helpers");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2019-01-08 22:10:06 -08:00
|
|
|
const spaceBeforeHeadingRe = /^((?:\s+)|(?:[>\s]+\s\s))[^>\s]/;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"names": [ "MD023", "heading-start-left", "header-start-left" ],
|
|
|
|
"description": "Headings must start at the beginning of the line",
|
|
|
|
"tags": [ "headings", "headers", "spaces" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD023(params, onError) {
|
2019-04-13 11:18:57 -07:00
|
|
|
filterTokens(params, "heading_open", function forToken(token) {
|
2018-03-19 23:39:42 +01:00
|
|
|
if (spaceBeforeHeadingRe.test(token.line)) {
|
2019-04-13 11:18:57 -07:00
|
|
|
addErrorContext(onError, token.lineNumber, token.line, null,
|
|
|
|
null, rangeFromRegExp(token.line, spaceBeforeHeadingRe));
|
2018-01-21 21:44:25 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|