From 32cd4feaea03d425f549e3bb9f1c00abd77ff13b Mon Sep 17 00:00:00 2001 From: Christopher Lopes Date: Tue, 23 Feb 2016 21:22:46 -0800 Subject: [PATCH 1/3] Add style option setext_with_atx_closed to header style rule MD003 Atx-style headers which are closed can now be used with setext style headers, when at header level 3 or more. --- doc/Rules.md | 11 ++++++----- lib/rules.js | 6 ++++-- test/headers_good_setext_with_atx_closed.json | 6 ++++++ test/headers_good_setext_with_atx_closed.md | 7 +++++++ 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 test/headers_good_setext_with_atx_closed.json create mode 100644 test/headers_good_setext_with_atx_closed.md diff --git a/doc/Rules.md b/doc/Rules.md index 33e65389..8ac40369 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -59,7 +59,8 @@ Tags: headers Aliases: header-style -Parameters: style ("consistent", "atx", "atx_closed", "setext", "setext_with_atx"; default "consistent") +Parameters: style ("consistent", "atx", "atx_closed", "setext", +"setext_with_atx", "setext_with_atx_closed"; default "consistent") This rule is triggered when different header styles (atx, setext, and 'closed' atx) are used in the same document: @@ -77,8 +78,8 @@ 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: +The setext_with_atx and settext_with_atx_closed doc styles allows atx-style +headers of level 3 or more in documents with setext style headers: Setext style H1 =============== @@ -89,8 +90,8 @@ documents with setext style headers: ### ATX style H3 Note: the configured header style can be a specific style to use (atx, -atx_closed, setext, setext_with_atx), or simply require that the usage be -consistent within the document. +atx_closed, setext, setext_with_atx, setext_with_atx_closed), 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 6b0f300b..617fbdd9 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -197,9 +197,11 @@ module.exports = [ style = styleForToken; } if ((styleForToken !== style) && - !((style === "setext_with_atx") && + !((style === "setext_with_atx" || style === "setext_with_atx_closed") && (/h[12]/.test(token.tag) && (styleForToken === "setext")) || - (/h[^12]/.test(token.tag) && (styleForToken === "atx")))) { + (/h[^12]/.test(token.tag) && + (styleForToken === "atx" || styleForToken === "atx_closed"))) + ) { errors.push(token.lineNumber); } }); diff --git a/test/headers_good_setext_with_atx_closed.json b/test/headers_good_setext_with_atx_closed.json new file mode 100644 index 00000000..fad19527 --- /dev/null +++ b/test/headers_good_setext_with_atx_closed.json @@ -0,0 +1,6 @@ +{ + "default": true, + "MD003": { + "style": "setext_with_atx_closed" + } +} diff --git a/test/headers_good_setext_with_atx_closed.md b/test/headers_good_setext_with_atx_closed.md new file mode 100644 index 00000000..5bbbf15f --- /dev/null +++ b/test/headers_good_setext_with_atx_closed.md @@ -0,0 +1,7 @@ +Header 1 +======== + +Header 2 +-------- + +### Header 3 ### From d06681198a1811bc1ebfc8adcdf4e7d6365158ab Mon Sep 17 00:00:00 2001 From: Christopher Lopes Date: Wed, 24 Feb 2016 19:32:35 -0800 Subject: [PATCH 2/3] Conform to style guidelines in setext_with_atx_closed feature Indentation was off in logic. Also update documentation grammar appropriately. --- doc/Rules.md | 2 +- lib/rules.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Rules.md b/doc/Rules.md index 8ac40369..a05282ed 100644 --- a/doc/Rules.md +++ b/doc/Rules.md @@ -78,7 +78,7 @@ Be consistent with the style of header used in a document: ## ATX style H2 -The setext_with_atx and settext_with_atx_closed doc styles allows atx-style +The setext_with_atx and settext_with_atx_closed doc styles allow atx-style headers of level 3 or more in documents with setext style headers: Setext style H1 diff --git a/lib/rules.js b/lib/rules.js index 617fbdd9..08ca3aa7 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -200,7 +200,7 @@ module.exports = [ !((style === "setext_with_atx" || style === "setext_with_atx_closed") && (/h[12]/.test(token.tag) && (styleForToken === "setext")) || (/h[^12]/.test(token.tag) && - (styleForToken === "atx" || styleForToken === "atx_closed"))) + (styleForToken === "atx" || styleForToken === "atx_closed"))) ) { errors.push(token.lineNumber); } From f866fac2d33b4fad53ea04a67da472806d2dc076 Mon Sep 17 00:00:00 2001 From: David Anson Date: Wed, 24 Feb 2016 21:11:58 -0800 Subject: [PATCH 3/3] Add test for new behavior, refactor to fix and clarify. --- lib/rules.js | 21 ++++++++++++++------- test/headers_good_setext_with_atx.md | 2 ++ test/headers_good_setext_with_atx_closed.md | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/rules.js b/lib/rules.js index 08ca3aa7..feaf24cc 100644 --- a/lib/rules.js +++ b/lib/rules.js @@ -196,13 +196,20 @@ module.exports = [ if (style === "consistent") { style = styleForToken; } - if ((styleForToken !== style) && - !((style === "setext_with_atx" || style === "setext_with_atx_closed") && - (/h[12]/.test(token.tag) && (styleForToken === "setext")) || - (/h[^12]/.test(token.tag) && - (styleForToken === "atx" || styleForToken === "atx_closed"))) - ) { - errors.push(token.lineNumber); + if (styleForToken !== style) { + var h12 = /h[12]/.test(token.tag); + var hOther = /h[^12]/.test(token.tag); + var setextWithAtx = + (style === "setext_with_atx") && + ((h12 && (styleForToken === "setext")) || + (hOther && (styleForToken === "atx"))); + var setextWithAtxClosed = + (style === "setext_with_atx_closed") && + ((h12 && (styleForToken === "setext")) || + (hOther && (styleForToken === "atx_closed"))); + if (!setextWithAtx && !setextWithAtxClosed) { + errors.push(token.lineNumber); + } } }); } diff --git a/test/headers_good_setext_with_atx.md b/test/headers_good_setext_with_atx.md index 726817f2..f3f276df 100644 --- a/test/headers_good_setext_with_atx.md +++ b/test/headers_good_setext_with_atx.md @@ -5,3 +5,5 @@ Header 2 -------- ### Header 3 + +#### Header 4 {MD003} #### diff --git a/test/headers_good_setext_with_atx_closed.md b/test/headers_good_setext_with_atx_closed.md index 5bbbf15f..4cdd532a 100644 --- a/test/headers_good_setext_with_atx_closed.md +++ b/test/headers_good_setext_with_atx_closed.md @@ -5,3 +5,5 @@ Header 2 -------- ### Header 3 ### + +#### Header 4 {MD003}