Skip to content

Commit 58ba6a3

Browse files
committed
Require a space after hash marks for ATX headers
This was required by the original ATX specification, although Markdown.pl didn't enforce it. It prevents false positives for #hashtags and things like "Engine #1" when lines wrap. It also reinforces good style.
1 parent f043658 commit 58ba6a3

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

markdown-mode.el

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ Group 2 matches only the label, without the surrounding markup.
12151215
Group 3 matches the closing square bracket.")
12161216

12171217
(defconst markdown-regex-header
1218-
"^\\(?:\\(.+?\\)\n\\(?:\\(=+\\)\\|\\(-+\\)\\)\\|\\(#+\\)[ \t]*\\(.+?\\)[ \t]*\\(#*\\)\\)$"
1218+
"^\\(?:\\(.+?\\)\n\\(?:\\(=+\\)\\|\\(-+\\)\\)\\|\\(#+\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)\\)$"
12191219
"Regexp identifying Markdown headings.
12201220
Group 1 matches the text of a setext heading.
12211221
Group 2 matches the underline of a level-1 setext heading.
@@ -1225,27 +1225,27 @@ Group 5 matches the text, without surrounding whitespace, of an atx heading.
12251225
Group 6 matches the closing hash marks of an atx heading.")
12261226

12271227
(defconst markdown-regex-header-1-atx
1228-
"^\\(#\\)[ \t]*\\([^\\.].*?\\)[ \t]*\\(#*\\)$"
1228+
"^\\(#\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)$"
12291229
"Regular expression for level 1 atx-style (hash mark) headers.")
12301230

12311231
(defconst markdown-regex-header-2-atx
1232-
"^\\(##\\)[ \t]*\\(.+?\\)[ \t]*\\(#*\\)$"
1232+
"^\\(##\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)$"
12331233
"Regular expression for level 2 atx-style (hash mark) headers.")
12341234

12351235
(defconst markdown-regex-header-3-atx
1236-
"^\\(###\\)[ \t]*\\(.+?\\)[ \t]*\\(#*\\)$"
1236+
"^\\(###\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)$"
12371237
"Regular expression for level 3 atx-style (hash mark) headers.")
12381238

12391239
(defconst markdown-regex-header-4-atx
1240-
"^\\(####\\)[ \t]*\\(.+?\\)[ \t]*\\(#*\\)$"
1240+
"^\\(####\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)$"
12411241
"Regular expression for level 4 atx-style (hash mark) headers.")
12421242

12431243
(defconst markdown-regex-header-5-atx
1244-
"^\\(#####\\)[ \t]*\\(.+?\\)[ \t]*\\(#*\\)$"
1244+
"^\\(#####\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)$"
12451245
"Regular expression for level 5 atx-style (hash mark) headers.")
12461246

12471247
(defconst markdown-regex-header-6-atx
1248-
"^\\(######\\)[ \t]*\\(.+?\\)[ \t]*\\(#*\\)$"
1248+
"^\\(######\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)$"
12491249
"Regular expression for level 6 atx-style (hash mark) headers.")
12501250

12511251
(defconst markdown-regex-header-1-setext
@@ -1261,7 +1261,7 @@ Group 6 matches the closing hash marks of an atx heading.")
12611261
"Regular expression for generic setext-style (underline) headers.")
12621262

12631263
(defconst markdown-regex-header-atx
1264-
"^\\(#+\\)[ \t]*\\(.*?\\)[ \t]*\\(#*\\)$"
1264+
"^\\(#+\\)[ \t]+\\(.*?\\)[ \t]*\\(#*\\)$"
12651265
"Regular expression for generic atx-style (hash mark) headers.")
12661266

12671267
(defconst markdown-regex-hr

tests/markdown-test.el

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,8 +1430,7 @@ the opening bracket of [^2], and then subsequent functions would kill [^2])."
14301430
(should (looking-at markdown-regex-header-atx))
14311431
(should-not (markdown-incomplete-atx-p)))
14321432
(markdown-test-string "###abc###"
1433-
(should (looking-at markdown-regex-header-atx))
1434-
(should (markdown-incomplete-atx-p)))
1433+
(should-not (looking-at markdown-regex-header-atx)))
14351434
(markdown-test-string "### ###"
14361435
(should (looking-at markdown-regex-header-atx))
14371436
(should (markdown-incomplete-atx-p))))
@@ -2205,15 +2204,11 @@ for (var i = 0; i < 10; i++) {
22052204
(ert-deftest test-markdown-font-lock/atx-no-spaces ()
22062205
"Test font-lock for atx headers with no spaces."
22072206
(markdown-test-string "##abc##"
2208-
(markdown-test-range-has-face 1 2 markdown-header-delimiter-face)
2209-
(markdown-test-range-has-face 3 5 markdown-header-face-2)
2210-
(markdown-test-range-has-face 6 7 markdown-header-delimiter-face))
2207+
(markdown-test-range-has-face 1 7 nil))
22112208
(markdown-test-string "##"
2212-
(markdown-test-range-has-face 1 1 markdown-header-delimiter-face)
2213-
(markdown-test-range-has-face 2 2 markdown-header-face-1))
2209+
(markdown-test-range-has-face 1 2 nil))
22142210
(markdown-test-string "###"
2215-
(markdown-test-range-has-face 1 2 markdown-header-delimiter-face)
2216-
(markdown-test-range-has-face 3 3 markdown-header-face-2)))
2211+
(markdown-test-range-has-face 1 3 nil)))
22172212

22182213
(ert-deftest test-markdown-font-lock/setext-1-letter ()
22192214
"An edge case for level-one setext headers."

0 commit comments

Comments
 (0)