Skip to content

Commit

Permalink
Make number of spaces after code fence customizable
Browse files Browse the repository at this point in the history
Fixes #219
  • Loading branch information
phst authored and jrblevin committed Aug 1, 2017
1 parent d29cea8 commit 884a72d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
<kbd>C-c C-f</kbd>, <kbd>C-c C-b</kbd>, and <kbd>C-c C-u</kbd>
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:

Expand Down
13 changes: 12 additions & 1 deletion markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
\\<gfm-mode-map>\\[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
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 884a72d

Please sign in to comment.