mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Support front matter title property override for MD041/first-line-h1 (fixes #53).
This commit is contained in:
parent
4ae649c462
commit
942f0600d2
18 changed files with 131 additions and 12 deletions
10
lib/rules.js
10
lib/rules.js
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue