Skip to content

Commit

Permalink
Don’t insert trailing whitespace when inserting a blockquote
Browse files Browse the repository at this point in the history
Fixes #227
  • Loading branch information
phst authored and jrblevin committed Sep 25, 2017
1 parent e391581 commit 0cf7873
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@
(require 'url-parse)
(require 'button)
(require 'color)
(require 'rx)

(defvar jit-lock-start)
(defvar jit-lock-end)
Expand Down Expand Up @@ -4735,7 +4736,9 @@ region. The characters PREFIX will appear at the beginning
of each line."
(save-excursion
(let* ((end-marker (make-marker))
(beg-marker (make-marker)))
(beg-marker (make-marker))
(prefix-without-trailing-whitespace
(replace-regexp-in-string (rx (+ blank) eos) "" prefix)))
;; Ensure blank line after and remove extra whitespace
(goto-char end)
(skip-syntax-backward "-")
Expand All @@ -4752,7 +4755,8 @@ of each line."
(goto-char beg-marker)
(while (and (< (line-beginning-position) end-marker)
(not (eobp)))
(insert prefix)
;; Don’t insert trailing whitespace.
(insert (if (eolp) prefix-without-trailing-whitespace prefix))
(forward-line)))))

(defun markdown-blockquote-region (beg end)
Expand Down
5 changes: 5 additions & 0 deletions tests/markdown-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,11 @@ Test point position upon removal and insertion."
(should (looking-at "^ > $"))
(should (markdown-next-line-blank-p))))

(ert-deftest test-markdown-insertion/blockquote-region-with-newline ()
(markdown-test-string "a\n\nb\n"
(markdown-blockquote-region 1 (point-max))
(should (equal (buffer-string) "> a\n>\n> b\n\n"))))

(ert-deftest test-markdown-insertion/empty-italic ()
"Test `markdown-insert-italic' with no word at point and no region."
(markdown-test-string ""
Expand Down

0 comments on commit 0cf7873

Please sign in to comment.