Support front matter title property override for MD041/first-line-h1 (fixes #53).

This commit is contained in:
David Anson 2017-05-06 15:25:14 -07:00
parent 4ae649c462
commit 942f0600d2
18 changed files with 131 additions and 12 deletions

View file

@ -1029,7 +1029,10 @@ module.exports = [
"regexp": null,
"func": function MD041(params, errors) {
var level = params.options.level || 1;
var frontMatterTitle = params.options.front_matter_title;
var tag = "h" + level;
var frontMatterTitleRe =
new RegExp(frontMatterTitle || "^\\s*title:", "i");
params.tokens.every(function forToken(token, index) {
if (token.type === "heading_open") {
if (!((token.lineNumber === 1) || (index > 0)) ||
@ -1040,7 +1043,12 @@ module.exports = [
} else if (token.type === "html_block") {
return true;
}
errors.addContext(token.lineNumber, token.line);
if (((frontMatterTitle !== undefined) && !frontMatterTitle) ||
!params.frontMatterLines.some(function forLine(line) {
return frontMatterTitleRe.test(line);
})) {
errors.addContext(token.lineNumber, token.line);
}
return false;
});
}