Update MD041/first-line-h1 to ignore leading HTML comments (fixes #37).

This commit is contained in:
David Anson 2017-02-23 22:08:54 -08:00
parent 15b37d51ff
commit acd36d5802
8 changed files with 56 additions and 15 deletions

View file

@ -1019,21 +1019,19 @@ module.exports = [
"func": function MD041(params, errors) {
var level = params.options.level || 1;
var tag = "h" + level;
var firstHeader = null;
params.tokens.every(function forToken(token) {
params.tokens.every(function forToken(token, index) {
if (token.type === "heading_open") {
firstHeader = token;
return false;
} else if (token.lineNumber > 1) {
if (!((token.lineNumber === 1) || (index > 0)) ||
(token.tag !== tag)) {
errors.addContext(token.lineNumber, token.line);
}
return false;
} else if (token.type === "html_block") {
return true;
}
return true;
errors.addContext(token.lineNumber, token.line);
return false;
});
if (!firstHeader ||
(firstHeader.lineNumber !== 1) ||
(firstHeader.tag !== tag)) {
errors.addContext(1, params.lines[0]);
}
}
},