diff --git a/doc/Rules.md b/doc/Rules.md index a0edafd0..45710027 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -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. diff --git a/lib/rules.js b/lib/rules.js index cf09ff9e..5b545708 100644 --- a/lib/rules.js +++ b/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); + } }); } } diff --git a/schema/build-config-schema.js b/schema/build-config-schema.js index 9d0c05f1..9250882c 100644 --- a/schema/build-config-schema.js +++ b/schema/build-config-schema.js @@ -226,6 +226,11 @@ rules.forEach(function forRule(rule) { "type": "string" }, "default": null + }, + "code_blocks": { + "description": "Include code blocks", + "type": "boolean", + "default": true } }; break; diff --git a/schema/markdownlint-config-schema.json b/schema/markdownlint-config-schema.json index a83ee102..d7225e73 100644 --- a/schema/markdownlint-config-schema.json +++ b/schema/markdownlint-config-schema.json @@ -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 diff --git a/test/proper-names-no-code.json b/test/proper-names-no-code.json new file mode 100644 index 00000000..7b60da03 --- /dev/null +++ b/test/proper-names-no-code.json @@ -0,0 +1,14 @@ +{ + "default": true, + "MD044": { + "names": [ + "markdownlint", + "JavaScript", + "Node.js", + "GitHub", + "npm", + "Internet Explorer" + ], + "code_blocks": false + } +} diff --git a/test/proper-names-no-code.md b/test/proper-names-no-code.md new file mode 100644 index 00000000..367c043a --- /dev/null +++ b/test/proper-names-no-code.md @@ -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}