diff --git a/CHANGES.md b/CHANGES.md
index 6d15c370..4226e4a0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -187,6 +187,8 @@
C-c C-f, C-c C-b, and C-c C-u
now move between list items, when the point is in a list,
and move between headings otherwise.
+ - New customization option `markdown-spaces-after-code-fence` to control
+ the number of spaces inserted after a code fence (` ``` `).
* Improvements:
diff --git a/markdown-mode.el b/markdown-mode.el
index f8baf7c0..b4310b79 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -4873,6 +4873,15 @@ if three backquotes inserted at the beginning of line."
(setq markdown-gfm-used-languages
(cons lang (remove lang markdown-gfm-used-languages))))
+(defcustom markdown-spaces-after-code-fence 1
+ "Number of space characters to insert after a code fence.
+\\\\[markdown-insert-gfm-code-block] inserts this many spaces between an
+opening code fence and an info string."
+ :group 'markdown
+ :type 'integer
+ :safe #'natnump
+ :package-version '(markdown-mode . "2.3"))
+
(defun markdown-insert-gfm-code-block (&optional lang)
"Insert GFM code block for language LANG.
If LANG is nil, the language will be queried from user. If a
@@ -4890,7 +4899,9 @@ automatically in order to have the correct markup."
'markdown-gfm-language-history))
(quit "")))))
(unless (string= lang "") (markdown-gfm-add-used-language lang))
- (when (> (length lang) 0) (setq lang (concat " " lang)))
+ (when (> (length lang) 0)
+ (setq lang (concat (make-string markdown-spaces-after-code-fence ?\s)
+ lang)))
(if (markdown-use-region-p)
(let ((b (region-beginning)) (e (region-end)))
(goto-char e)
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index bd8d4c30..a7827fbe 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -4956,6 +4956,11 @@ This includes preserving whitespace after the pipe."
(should (equal (car (markdown-gfm-get-corpus)) "elisp"))
(should (string-equal (buffer-string)
"line 1\n\n``` elisp\n\n```\n\nline 2\n")))
+ ;; Test ‘markdown-spaces-after-code-fence’.
+ (markdown-test-string-gfm ""
+ (let ((markdown-spaces-after-code-fence 0))
+ (markdown-insert-gfm-code-block "elisp")
+ (should (equal (buffer-string) "```elisp\n\n```"))))
;; Test with active region
(markdown-test-string-gfm "line 1\nline 2\nline 3\n"
(forward-line)