mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Update MD041/first-line-h1 to allow secondary headings if a YAML title is present (refs #116).
This commit is contained in:
parent
ed295cd947
commit
c71bb4fbd5
4 changed files with 46 additions and 27 deletions
28
lib/md041.js
28
lib/md041.js
|
|
@ -10,24 +10,24 @@ module.exports = {
|
|||
"tags": [ "headings", "headers" ],
|
||||
"function": function MD041(params, onError) {
|
||||
const level = params.config.level || 1;
|
||||
const frontMatterTitle = params.config.front_matter_title;
|
||||
const tag = "h" + level;
|
||||
const frontMatterTitle = params.config.front_matter_title;
|
||||
const ignoreFrontMatter =
|
||||
(frontMatterTitle !== undefined) && !frontMatterTitle;
|
||||
const frontMatterTitleRe =
|
||||
new RegExp(frontMatterTitle || "^\\s*title\\s*[:=]", "i");
|
||||
params.tokens.every(function forToken(token) {
|
||||
if (token.type === "html_block") {
|
||||
return true;
|
||||
} else if (token.type === "heading_open") {
|
||||
if (token.tag !== tag) {
|
||||
const foundFrontMatterTitle = !ignoreFrontMatter &&
|
||||
params.frontMatterLines.some((line) => frontMatterTitleRe.test(line));
|
||||
if (!foundFrontMatterTitle) {
|
||||
params.tokens.every((token) => {
|
||||
if (token.type === "html_block") {
|
||||
return true;
|
||||
}
|
||||
if ((token.type !== "heading_open") || (token.tag !== tag)) {
|
||||
shared.addErrorContext(onError, token.lineNumber, token.line);
|
||||
}
|
||||
} else if (((frontMatterTitle !== undefined) && !frontMatterTitle) ||
|
||||
!params.frontMatterLines.some(function forLine(line) {
|
||||
return frontMatterTitleRe.test(line);
|
||||
})) {
|
||||
shared.addErrorContext(onError, token.lineNumber, token.line);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue