Skip to content

Commit 0cf7873

Browse files
phstjrblevin
authored andcommitted
Don’t insert trailing whitespace when inserting a blockquote
Fixes #227
1 parent e391581 commit 0cf7873

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

markdown-mode.el

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@
975975
(require 'url-parse)
976976
(require 'button)
977977
(require 'color)
978+
(require 'rx)
978979

979980
(defvar jit-lock-start)
980981
(defvar jit-lock-end)
@@ -4735,7 +4736,9 @@ region. The characters PREFIX will appear at the beginning
47354736
of each line."
47364737
(save-excursion
47374738
(let* ((end-marker (make-marker))
4738-
(beg-marker (make-marker)))
4739+
(beg-marker (make-marker))
4740+
(prefix-without-trailing-whitespace
4741+
(replace-regexp-in-string (rx (+ blank) eos) "" prefix)))
47394742
;; Ensure blank line after and remove extra whitespace
47404743
(goto-char end)
47414744
(skip-syntax-backward "-")
@@ -4752,7 +4755,8 @@ of each line."
47524755
(goto-char beg-marker)
47534756
(while (and (< (line-beginning-position) end-marker)
47544757
(not (eobp)))
4755-
(insert prefix)
4758+
;; Don’t insert trailing whitespace.
4759+
(insert (if (eolp) prefix-without-trailing-whitespace prefix))
47564760
(forward-line)))))
47574761

47584762
(defun markdown-blockquote-region (beg end)

tests/markdown-test.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,11 @@ Test point position upon removal and insertion."
922922
(should (looking-at "^ > $"))
923923
(should (markdown-next-line-blank-p))))
924924

925+
(ert-deftest test-markdown-insertion/blockquote-region-with-newline ()
926+
(markdown-test-string "a\n\nb\n"
927+
(markdown-blockquote-region 1 (point-max))
928+
(should (equal (buffer-string) "> a\n>\n> b\n\n"))))
929+
925930
(ert-deftest test-markdown-insertion/empty-italic ()
926931
"Test `markdown-insert-italic' with no word at point and no region."
927932
(markdown-test-string ""

0 commit comments

Comments
 (0)