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

@ -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;