Skip to content

Commit

Permalink
Add a space before the language in gfm code blocks
Browse files Browse the repository at this point in the history
Support this for font lock as well.
  • Loading branch information
jrblevin committed Nov 2, 2015
1 parent 4f75107 commit 59a4986
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,7 @@ Group 3 matches the closing backticks."
"Match GFM quoted code blocks from point to LAST."
(let (open lang body close all)
(if (search-forward-regexp
"\\(?:\\`\\|[\n\r]+\\s *[\n\r]\\)\\(```\\)\\([^[:space:]]+[[:space:]]*\\|{[^}]*}\\)?$" last t)
"\\(?:\\`\\|[\n\r]+\\s *[\n\r]\\)\\(```\\)[ ]?\\([^[:space:]]+[[:space:]]*\\|{[^}]*}\\)?$" last t)
(progn
(beginning-of-line)
(setq open (list (match-beginning 1) (match-end 1))
Expand Down Expand Up @@ -2815,6 +2815,7 @@ region is active, wrap this region with the markup instead. If
the region boundaries are not on empty lines, these are added
automatically in order to have the correct markup."
(interactive "sProgramming language [none]: ")
(when (> (length lang) 0) (setq lang (concat " " lang)))
(if (markdown-use-region-p)
(let ((b (region-beginning)) (e (region-end)))
(goto-char e)
Expand Down
4 changes: 2 additions & 2 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ indented the same amount."
(end-of-line)
(markdown-insert-gfm-code-block "elisp")
(should (string-equal (buffer-string)
"line 1\n\n```elisp\n\n```\n\nline 2\n")))
"line 1\n\n``` elisp\n\n```\n\nline 2\n")))
;; Test with active region
(markdown-test-string-gfm "line 1\nline 2\nline 3\n"
(forward-line)
Expand All @@ -2807,7 +2807,7 @@ indented the same amount."
(should (markdown-use-region-p))
(markdown-insert-gfm-code-block "elisp")
(should (string-equal (buffer-string)
"line 1\n\n```elisp\nline 2\n```\n\nline 3\n"))))
"line 1\n\n``` elisp\nline 2\n```\n\nline 3\n"))))

(ert-deftest test-markdown-gfm/code-block-font-lock ()
"GFM code block font lock test."
Expand Down

0 comments on commit 59a4986

Please sign in to comment.