diff --git a/doc/Rules.md b/doc/Rules.md index 587eb578..852cd842 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -53,7 +53,7 @@ The first header in the document should be a h1 header: Tags: headers -Parameters: style ("consistent", "atx", "atx_closed", "setext"; default "consistent") +Parameters: style ("consistent", "atx", "atx_closed", "setext", "setext_with_atx"; default "consistent") This rule is triggered when different header styles (atx, setext, and 'closed' atx) are used in the same document: @@ -71,9 +71,20 @@ Be consistent with the style of header used in a document: ## ATX style H2 +The setext_with_atx doc style allows atx-style headers of level 3 or more in +documents with setext style headers: + + Setext style H1 + =============== + + Setext style H2 + --------------- + + ### ATX style H3 + Note: the configured header style can be a specific style to use (atx, -atx_closed, setext), or simply require that the usage be consistent within the -document. +atx_closed, setext, setext_with_atx), or simply require that the usage be +consistent within the document. ## MD004 - Unordered list style diff --git a/lib/rules.js b/lib/rules.js index 545f9c90..21b5950c 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -173,10 +173,14 @@ module.exports = [ "func": function MD003(params, errors) { var style = params.options.style || "consistent"; filterTokens(params, "heading_open", function forToken(token) { + var styleForToken = headingStyleFor(token); if (style === "consistent") { - style = headingStyleFor(token); + style = styleForToken; } - if (headingStyleFor(token) !== style) { + if ((styleForToken !== style) && + !((style === "setext_with_atx") && + (/h[12]/.test(token.tag) && (styleForToken === "setext")) || + (/h[^12]/.test(token.tag) && (styleForToken === "atx")))) { errors.push(token.lineNumber); } }); diff --git a/test/headers_good_setext_with_atx.json b/test/headers_good_setext_with_atx.json new file mode 100644 index 00000000..8f73395a --- /dev/null +++ b/test/headers_good_setext_with_atx.json @@ -0,0 +1,6 @@ +{ + "default": true, + "MD003": { + "style": "setext_with_atx" + } +} diff --git a/test/headers_good_setext_with_atx.md b/test/headers_good_setext_with_atx.md new file mode 100644 index 00000000..726817f2 --- /dev/null +++ b/test/headers_good_setext_with_atx.md @@ -0,0 +1,7 @@ +Header 1 +======== + +Header 2 +-------- + +### Header 3