mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Add code_blocks parameter to MD044/proper-names (fixes #50).
This commit is contained in:
parent
15fe91ba38
commit
31c252a55c
6 changed files with 64 additions and 4 deletions
|
|
@ -1127,7 +1127,7 @@ Tags: spelling
|
|||
|
||||
Aliases: proper-names
|
||||
|
||||
Parameters: names (array of string; default `null` for disabled)
|
||||
Parameters: names, code_blocks (string array; default `null`, boolean; default `true`)
|
||||
|
||||
This rule is triggered when any of the strings in the `names` array do not have
|
||||
the specified capitalization. It can be used to enforce a standard letter case
|
||||
|
|
@ -1140,3 +1140,5 @@ the proper capitalization, specify the desired letter case in the `names` array:
|
|||
[
|
||||
"JavaScript"
|
||||
]
|
||||
|
||||
Set the `code_blocks` parameter to `false` to disable this rule for code blocks.
|
||||
|
|
|
|||
10
lib/rules.js
10
lib/rules.js
|
|
@ -1124,6 +1124,8 @@ module.exports = [
|
|||
"regexp": null,
|
||||
"func": function MD044(params, errors) {
|
||||
var names = params.options.names || [];
|
||||
var codeBlocks = params.options.code_blocks;
|
||||
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||
names.forEach(function forName(name) {
|
||||
var escapedName = escapeForRegExp(name);
|
||||
var namePattern = "\\S*\\b(" + escapedName + ")\\b\\S*";
|
||||
|
|
@ -1142,9 +1144,11 @@ module.exports = [
|
|||
});
|
||||
}
|
||||
forEachInlineChild(params, "text", forToken);
|
||||
forEachInlineChild(params, "code_inline", forToken);
|
||||
filterTokens(params, "code_block", forToken);
|
||||
filterTokens(params, "fence", forToken);
|
||||
if (includeCodeBlocks) {
|
||||
forEachInlineChild(params, "code_inline", forToken);
|
||||
filterTokens(params, "code_block", forToken);
|
||||
filterTokens(params, "fence", forToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,6 +226,11 @@ rules.forEach(function forRule(rule) {
|
|||
"type": "string"
|
||||
},
|
||||
"default": null
|
||||
},
|
||||
"code_blocks": {
|
||||
"description": "Include code blocks",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
};
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -896,6 +896,11 @@
|
|||
"type": "string"
|
||||
},
|
||||
"default": null
|
||||
},
|
||||
"code_blocks": {
|
||||
"description": "Include code blocks",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
|
@ -915,6 +920,11 @@
|
|||
"type": "string"
|
||||
},
|
||||
"default": null
|
||||
},
|
||||
"code_blocks": {
|
||||
"description": "Include code blocks",
|
||||
"type": "boolean",
|
||||
"default": true
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
|
|
|||
14
test/proper-names-no-code.json
Normal file
14
test/proper-names-no-code.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"default": true,
|
||||
"MD044": {
|
||||
"names": [
|
||||
"markdownlint",
|
||||
"JavaScript",
|
||||
"Node.js",
|
||||
"GitHub",
|
||||
"npm",
|
||||
"Internet Explorer"
|
||||
],
|
||||
"code_blocks": false
|
||||
}
|
||||
}
|
||||
25
test/proper-names-no-code.md
Normal file
25
test/proper-names-no-code.md
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# markdownlint test file
|
||||
|
||||
Markdownlint is a tool {MD044}
|
||||
|
||||
JavaScript is a language
|
||||
|
||||
JavaScript is not Java
|
||||
|
||||
Nor is it Javascript. {MD044}
|
||||
|
||||
Code in `javascript`
|
||||
|
||||
Execute `via the node.js engine`
|
||||
|
||||
javascript is code
|
||||
node.js is runtime
|
||||
|
||||
```js
|
||||
javascript is code
|
||||
node.js is runtime
|
||||
```
|
||||
|
||||
A short paragraph
|
||||
about node.js and {MD044}
|
||||
javascript. {MD044}
|
||||
Loading…
Add table
Add a link
Reference in a new issue