(shr-insert): Get white space at the beginning/end of elements right.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Sun, 3 Oct 2010 21:51:18 +0000 (23:51 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Sun, 3 Oct 2010 21:51:18 +0000 (23:51 +0200)
lisp/ChangeLog
lisp/shr.el

index 20b9acf..9e00c6b 100644 (file)
@@ -3,6 +3,7 @@
        * shr.el: Add headings.
        (shr-ensure-paragraph): Actually work.
        (shr-tag-li): Make <ul> prettier.
+       (shr-insert): Get white space at the beginning/end of elements right.
 
 2010-10-03  Julien Danjou  <julien@danjou.info>
 
index 65a893c..e5294ed 100644 (file)
@@ -232,13 +232,20 @@ fit these criteria."
    ((eq shr-folding-mode 'none)
     (insert t))
    (t
-    (let (column)
+    (let ((first t)
+         column)
+      (when (and (string-match "^[ \n]" text)
+                (not (bolp)))
+       (insert " "))
       (dolist (elem (split-string text))
        (setq column (current-column))
        (when (plusp column)
-         (if (> (+ column (length elem) 1) shr-width)
-             (insert "\n")
-           (insert " ")))
+         (cond
+          ((> (+ column (length elem) 1) shr-width)
+           (insert "\n"))
+          ((not first)
+           (insert " "))))
+       (setq first nil)
        (when (and (bolp)
                   (plusp shr-indentation))
          (insert (make-string shr-indentation ? )))
@@ -247,7 +254,10 @@ fit these criteria."
        ;; starts.
        (unless shr-start
          (setq shr-start (point)))
-       (insert elem))))))
+       (insert elem))
+      (when (and (string-match "[ \n]$" text)
+                (not (bolp)))
+       (insert " "))))))
 
 (defun shr-get-image-data (url)
   "Get image data for URL.