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
|
@ -88,13 +88,17 @@ function lintContent(content, config, frontMatter, resultVersion) {
|
|||
content = content.slice(1);
|
||||
}
|
||||
// Remove front matter (if present at beginning of content)
|
||||
var frontMatterLines = 0;
|
||||
var frontMatterLines = [];
|
||||
if (frontMatter) {
|
||||
var frontMatterMatch = content.match(frontMatter);
|
||||
if (frontMatterMatch && !frontMatterMatch.index) {
|
||||
var contentMatched = frontMatterMatch[0];
|
||||
content = content.slice(contentMatched.length);
|
||||
frontMatterLines = contentMatched.split(shared.newLineRe).length - 1;
|
||||
frontMatterLines = contentMatched.split(shared.newLineRe);
|
||||
if (frontMatterLines.length &&
|
||||
(frontMatterLines[frontMatterLines.length - 1] === "")) {
|
||||
frontMatterLines.length--;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Parse content into tokens and lines
|
||||
|
@ -184,7 +188,7 @@ function lintContent(content, config, frontMatter, resultVersion) {
|
|||
}
|
||||
});
|
||||
}
|
||||
var enabledRulesPerLineNumber = new Array(1 + frontMatterLines);
|
||||
var enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length);
|
||||
lines.forEach(function forLine(line) {
|
||||
var match = shared.inlineCommentRe.exec(line);
|
||||
if (match) {
|
||||
|
@ -200,7 +204,8 @@ function lintContent(content, config, frontMatter, resultVersion) {
|
|||
var params = {
|
||||
"tokens": tokens,
|
||||
"tokenLists": tokenLists,
|
||||
"lines": lines
|
||||
"lines": lines,
|
||||
"frontMatterLines": frontMatterLines
|
||||
};
|
||||
// Run each rule
|
||||
var result = (resultVersion === 1) ? [] : {};
|
||||
|
@ -210,7 +215,7 @@ function lintContent(content, config, frontMatter, resultVersion) {
|
|||
var errors = [];
|
||||
function addError(lineNumber, detail, context) {
|
||||
errors.push({
|
||||
"lineNumber": lineNumber + frontMatterLines,
|
||||
"lineNumber": lineNumber + frontMatterLines.length,
|
||||
"detail": detail || null,
|
||||
"context": context || null
|
||||
});
|
||||
|
@ -255,7 +260,7 @@ function lintContent(content, config, frontMatter, resultVersion) {
|
|||
if (typeof regexp === "function") {
|
||||
regexp = regexp(params.options);
|
||||
}
|
||||
var lineIndex = error.lineNumber - frontMatterLines - 1;
|
||||
var lineIndex = error.lineNumber - frontMatterLines.length - 1;
|
||||
var match = lines[lineIndex].match(regexp);
|
||||
if (match) {
|
||||
var column = match.index + 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue