mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Merge 414e774480 into eabe2387bc
This commit is contained in:
commit
f1ca023124
4 changed files with 41 additions and 0 deletions
|
|
@ -76,6 +76,7 @@ playground for learning and exploring.
|
||||||
* **MD038** - Spaces inside code span elements
|
* **MD038** - Spaces inside code span elements
|
||||||
* **MD039** - Spaces inside link text
|
* **MD039** - Spaces inside link text
|
||||||
* **MD040** - Fenced code blocks should have a language specified
|
* **MD040** - Fenced code blocks should have a language specified
|
||||||
|
* **ignore** - Ignore certain parts of the markdown file (can be `RegExp`, `Function`, `"frontmatter"`), should be used with disabled `MD012`
|
||||||
|
|
||||||
See [Rules.md](doc/Rules.md) for more details.
|
See [Rules.md](doc/Rules.md) for more details.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,24 @@ function uniqueFilterForSorted(value, index, array) {
|
||||||
return (index === 0) || (value > array[index - 1]);
|
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
|
// Lints a single string
|
||||||
function lintContent(content, config) {
|
function lintContent(content, config) {
|
||||||
|
// ignore portions of content
|
||||||
|
if (config.ignore) {
|
||||||
|
content = ignoreContent(content, config);
|
||||||
|
}
|
||||||
// Parse content into tokens and lines
|
// Parse content into tokens and lines
|
||||||
var tokens = md.parse(content, {});
|
var tokens = md.parse(content, {});
|
||||||
var lines = content.split(shared.newLineRe);
|
var lines = content.split(shared.newLineRe);
|
||||||
|
|
@ -170,6 +186,18 @@ function markdownlint(options, callback) {
|
||||||
var config = options.config || { "default": true };
|
var config = options.config || { "default": true };
|
||||||
var synchronous = (callback === markdownlintSynchronousCallback);
|
var synchronous = (callback === markdownlintSynchronousCallback);
|
||||||
var results = new Results();
|
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
|
// Helper to lint the next file in the array
|
||||||
function lintFilesArray() {
|
function lintFilesArray() {
|
||||||
var file = files.shift();
|
var file = files.shift();
|
||||||
|
|
|
||||||
5
test/ignore_frontmatter.json
Normal file
5
test/ignore_frontmatter.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"ignore": "frontmatter",
|
||||||
|
"MD012": false
|
||||||
|
}
|
||||||
7
test/ignore_frontmatter.md
Normal file
7
test/ignore_frontmatter.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
front: matter
|
||||||
|
---
|
||||||
|
|
||||||
|
# Header 1 #
|
||||||
|
|
||||||
|
## Header 2 ##
|
||||||
Loading…
Add table
Add a link
Reference in a new issue