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

Make number of spaces after code fence customizable #232

Merged
merged 1 commit into from
Aug 1, 2017
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
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