From 7a5886b976e88d9d5e0307538ca4cd08934c1f40 Mon Sep 17 00:00:00 2001 From: David Anson Date: Thu, 28 Apr 2022 21:53:51 -0700 Subject: [PATCH] Update MD035/hr-style to preserve embedded spaces in thematic break markup (fixes #498). --- demo/markdownlint-browser.js | 9 +++++++-- lib/md035.js | 9 +++++++-- test/hr-in-blockquote-dash.md | 2 +- test/hr-in-blockquote-star.md | 2 +- test/hr-in-blockquote-under.md | 2 +- test/hr-style-custom.md | 28 ++++++++++++++++++++++++++++ test/hr_style_dashes.md | 3 ++- test/hr_style_inconsistent.md | 2 +- test/hr_style_stars.md | 2 +- 9 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 test/hr-style-custom.md diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 7798ed6b..471f04e7 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -3613,9 +3613,14 @@ module.exports = { "description": "Horizontal rule style", "tags": ["hr"], "function": function MD035(params, onError) { - var style = String(params.config.style || "consistent"); + var style = String(params.config.style || "consistent").trim(); filterTokens(params, "hr", function (token) { - var lineNumber = token.lineNumber, markup = token.markup; + var line = token.line, lineNumber = token.lineNumber; + var markup = token.markup; + var match = line.match(/[_*\-\s\t]+$/); + if (match) { + markup = match[0].trim(); + } if (style === "consistent") { style = markup; } diff --git a/lib/md035.js b/lib/md035.js index 80425867..e6afb544 100644 --- a/lib/md035.js +++ b/lib/md035.js @@ -9,9 +9,14 @@ module.exports = { "description": "Horizontal rule style", "tags": [ "hr" ], "function": function MD035(params, onError) { - let style = String(params.config.style || "consistent"); + let style = String(params.config.style || "consistent").trim(); filterTokens(params, "hr", (token) => { - const { lineNumber, markup } = token; + const { line, lineNumber } = token; + let { markup } = token; + const match = line.match(/[_*\-\s\t]+$/); + if (match) { + markup = match[0].trim(); + } if (style === "consistent") { style = markup; } diff --git a/test/hr-in-blockquote-dash.md b/test/hr-in-blockquote-dash.md index 689563bb..4da50c38 100644 --- a/test/hr-in-blockquote-dash.md +++ b/test/hr-in-blockquote-dash.md @@ -36,4 +36,4 @@ ___ > > Text -{MD035:31} {MD035:33} +{MD035:23} {MD035:31} {MD035:33} diff --git a/test/hr-in-blockquote-star.md b/test/hr-in-blockquote-star.md index ad24cc0e..298cb138 100644 --- a/test/hr-in-blockquote-star.md +++ b/test/hr-in-blockquote-star.md @@ -36,4 +36,4 @@ ___ > > Text -{MD035:29} {MD035:33} +{MD035:23} {MD035:29} {MD035:33} diff --git a/test/hr-in-blockquote-under.md b/test/hr-in-blockquote-under.md index 6829fc30..2e2dccf1 100644 --- a/test/hr-in-blockquote-under.md +++ b/test/hr-in-blockquote-under.md @@ -36,4 +36,4 @@ _ _ _ > > Text -{MD035:29} {MD035:31} +{MD035:23} {MD035:29} {MD035:31} diff --git a/test/hr-style-custom.md b/test/hr-style-custom.md new file mode 100644 index 00000000..ab4c7b3a --- /dev/null +++ b/test/hr-style-custom.md @@ -0,0 +1,28 @@ +# HR Style Custom + +Text + +--- +{MD035:5} + +Text + +- - - +{MD035:10} + +Text + +- - - + +Text + +*** +{MD035:19} + +Text + + diff --git a/test/hr_style_dashes.md b/test/hr_style_dashes.md index 59e17f8b..a8f01753 100644 --- a/test/hr_style_dashes.md +++ b/test/hr_style_dashes.md @@ -20,4 +20,5 @@ _____ *** -{MD035:3} {MD035:5} {MD035:7} {MD035:13} {MD035:15} {MD035:17} {MD035:19} {MD035:21} +{MD035:3} {MD035:5} {MD035:7} {MD035:11} {MD035:13} +{MD035:15} {MD035:17} {MD035:19} {MD035:21} diff --git a/test/hr_style_inconsistent.md b/test/hr_style_inconsistent.md index 0da18c58..02070572 100644 --- a/test/hr_style_inconsistent.md +++ b/test/hr_style_inconsistent.md @@ -20,4 +20,4 @@ _____ *** -{MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15} {MD035:17} {MD035:19} +{MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15} {MD035:17} {MD035:19} diff --git a/test/hr_style_stars.md b/test/hr_style_stars.md index f9e7839c..8f67161b 100644 --- a/test/hr_style_stars.md +++ b/test/hr_style_stars.md @@ -20,4 +20,4 @@ _____ *** -{MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15} {MD035:17} {MD035:19} +{MD035:5} {MD035:7} {MD035:9} {MD035:11} {MD035:13} {MD035:15} {MD035:17} {MD035:19}