Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require a space before the closing sequence of an atx heade #779

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 14 additions & 1 deletion tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -3013,14 +3013,27 @@ 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##"
(markdown-test-range-has-face 1 7 nil))
(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."
Expand Down