feature(config): adding config.ignore to replace metadata (e.g. frontmatter) before linting

This commit is contained in:
Rodney Rehm 2015-07-20 14:16:52 +02:00 committed by David Anson
parent a958a33860
commit cae451967a
4 changed files with 41 additions and 0 deletions

View file

@ -53,8 +53,24 @@ function uniqueFilterForSorted(value, index, array) {
return (index === 0) || (value > array[index - 1]);
}
function ignoreContent(content, config) {
if (typeof config.ignore === "function") {
// allow custom ignore callback
return config.ignore(content);
}
return content.replace(config.ignore, function removeNonLineBreaks(m) {
// maintain line breaks
return m.replace(/[^\n]+/g, "");
});
}
// Lints a single string
function lintContent(content, config) {
// ignore portions of content
if (config.ignore) {
content = ignoreContent(content, config);
}
// Parse content into tokens and lines
var tokens = md.parse(content, {});
var lines = content.split(shared.newLineRe);
@ -170,6 +186,18 @@ function markdownlint(options, callback) {
var config = options.config || { "default": true };
var synchronous = (callback === markdownlintSynchronousCallback);
var results = new Results();
if (config.ignore) {
if (config.ignore === "frontmatter") {
// see http://jekyllrb.com/docs/frontmatter/
config.ignore = /^---([\s\S]+?)---/;
}
if (typeof config.ignore !== "function" &&
!config.ignore.test &&
!config.ignore.exec
) {
throw new TypeError("config.ignore must be a RegExp or Function");
}
}
// Helper to lint the next file in the array
function lintFilesArray() {
var file = files.shift();