From eba1baf31e5980e8e3436addde1f9e62734270cc Mon Sep 17 00:00:00 2001 From: Tomohisa Kuranari Date: Fri, 21 Jul 2023 00:02:26 +0900 Subject: [PATCH] Require a space before the closing sequence of an atx heade --- CHANGES.md | 1 + markdown-mode.el | 2 +- tests/markdown-test.el | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 99cddab0..f2bd099b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,7 @@ * **Breaking changes:** - GNU Emacs 26.1 or later is required. - Don't allow space between label and text in reference link same as CommonMark [GH-774][] + - Whitespace is required before the closing sequence of an atx header. [GH-778][] * New Features: - Introduce `markdown-fontify-whole-heading-line` variable for highlighting diff --git a/markdown-mode.el b/markdown-mode.el index 521e191a..9d260648 100644 --- a/markdown-mode.el +++ b/markdown-mode.el @@ -732,7 +732,7 @@ Group 2 matches only the label, without the surrounding markup. Group 3 matches the closing square bracket.") (defconst markdown-regex-header - "^\\(?:\\(?1:[^\r\n\t -].*\\)\n\\(?:\\(?2:=+\\)\\|\\(?3:-+\\)\\)\\|\\(?4:#+[ \t]+\\)\\(?5:.*?\\)\\(?6:[ \t]*#*\\)\\)$" + "^\\(?:\\(?1:[^\r\n\t -].*\\)\n\\(?:\\(?2:=+\\)\\|\\(?3:-+\\)\\)\\|\\(?4:#+[ \t]+\\)\\(?5:.*?\\)\\(?6:[ \t]+#+\\)?\\)$" "Regexp identifying Markdown headings. Group 1 matches the text of a setext heading. Group 2 matches the underline of a level-1 setext heading. diff --git a/tests/markdown-test.el b/tests/markdown-test.el index b5c26a7e..0793667e 100644 --- a/tests/markdown-test.el +++ b/tests/markdown-test.el @@ -3013,6 +3013,16 @@ puts markdown.to_html (markdown-test-range-has-face 70 72 'font-lock-builtin-face) ; puts (markdown-test-range-has-face 92 94 'markdown-markup-face)))) ; ``` +(ert-deftest test-markdown-font-lock/atx-headers () + "Test font-lock for atx headers" + (markdown-test-string "## abc " + (markdown-test-range-has-face 1 3 'markdown-header-delimiter-face) + (markdown-test-range-has-face 4 8 'markdown-header-face-2)) + (markdown-test-string "## abc ##" + (markdown-test-range-has-face 1 3 'markdown-header-delimiter-face) + (markdown-test-range-has-face 4 6 'markdown-header-face-2) + (markdown-test-range-has-face 7 9 'markdown-header-delimiter-face))) + (ert-deftest test-markdown-font-lock/atx-no-spaces () "Test font-lock for atx headers with no spaces." (markdown-test-string "##abc##" @@ -3020,7 +3030,10 @@ puts markdown.to_html (markdown-test-string "##" (markdown-test-range-has-face 1 2 nil)) (markdown-test-string "###" - (markdown-test-range-has-face 1 3 nil))) + (markdown-test-range-has-face 1 3 nil)) + (markdown-test-string "## abc##" + (markdown-test-range-has-face 1 3 'markdown-header-delimiter-face) + (markdown-test-range-has-face 4 8 'markdown-header-face-2))) (ert-deftest test-markdown-font-lock/atx-whole-line () "Test font-lock for atx headers with whole line flag."