* shr.el (shr-insert): Don't insert double spaces.
[gnus] / lisp / shr.el
index 73011af..daafa61 100644 (file)
@@ -30,6 +30,7 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
 (require 'browse-url)
 
 (defgroup shr nil
@@ -187,21 +188,10 @@ redirects somewhere else."
     (let ((first t)
          column)
       (when (and (string-match "\\`[ \t\n]" text)
-                (not (bolp)))
-       (insert " ")
-       (setq shr-state 'space))
+                (not (bolp))
+                (not (eq (char-after (1- (point))) ? )))
+       (insert " "))
       (dolist (elem (split-string text))
-       (setq column (current-column))
-       (when (> column 0)
-         (cond
-          ((and (or (not first)
-                    (eq shr-state 'space))
-                (> (+ column (length elem) 1) shr-width))
-           (insert "\n")
-           (put-text-property (1- (point)) (point) 'shr-break t))
-          ((not first)
-           (insert " "))))
-       (setq first nil)
        (when (and (bolp)
                   (> shr-indentation 0))
          (shr-indent))
@@ -210,12 +200,19 @@ redirects somewhere else."
        ;; starts.
        (unless shr-start
          (setq shr-start (point)))
-       (insert elem))
-      (setq shr-state nil)
-      (when (and (string-match "[ \t\n]\\'" text)
-                (not (bolp)))
-       (insert " ")
-       (setq shr-state 'space))))))
+       (insert elem)
+       (when (> (current-column) shr-width)
+         (if (not (search-backward " " (line-beginning-position) t))
+             (insert "\n")
+           (delete-char 1)
+           (insert "\n")
+           (put-text-property (1- (point)) (point) 'shr-break t)
+           (when (> shr-indentation 0)
+             (shr-indent))
+           (end-of-line)))
+       (insert " "))
+      (unless (string-match "[ \t\n]\\'" text)
+       (delete-char -1))))))
 
 (defun shr-ensure-newline ()
   (unless (zerop (current-column))
@@ -409,11 +406,14 @@ Return a string with image data."
 (defun shr-tag-ul (cont)
   (shr-ensure-paragraph)
   (let ((shr-list-mode 'ul))
-    (shr-generic cont)))
+    (shr-generic cont))
+  (shr-ensure-paragraph))
 
 (defun shr-tag-ol (cont)
+  (shr-ensure-paragraph)
   (let ((shr-list-mode 1))
-    (shr-generic cont)))
+    (shr-generic cont))
+  (shr-ensure-paragraph))
 
 (defun shr-tag-li (cont)
   (shr-ensure-newline)
@@ -450,6 +450,10 @@ Return a string with image data."
 (defun shr-tag-h6 (cont)
   (shr-heading cont))
 
+(defun shr-tag-hr (cont)
+  (shr-ensure-newline)
+  (insert (make-string shr-width ?-) "\n"))
+
 ;;; Table rendering algorithm.
 
 ;; Table rendering is the only complicated thing here.  We do this by
@@ -509,16 +513,15 @@ Return a string with image data."
              overlay overlay-line)
          (dolist (line lines)
            (setq overlay-line (pop overlay-lines))
-           (when (> (length line) 0)
-             (end-of-line)
-             (insert line "|")
-             (dolist (overlay overlay-line)
-               (let ((o (make-overlay (- (point) (nth 0 overlay) 1)
-                                      (- (point) (nth 1 overlay) 1)))
-                     (properties (nth 2 overlay)))
-                 (while properties
-                   (overlay-put o (pop properties) (pop properties)))))
-             (forward-line 1)))
+           (end-of-line)
+           (insert line "|")
+           (dolist (overlay overlay-line)
+             (let ((o (make-overlay (- (point) (nth 0 overlay) 1)
+                                    (- (point) (nth 1 overlay) 1)))
+                   (properties (nth 2 overlay)))
+               (while properties
+                 (overlay-put o (pop properties) (pop properties)))))
+           (forward-line 1))
          ;; Add blank lines at padding at the bottom of the TD,
          ;; possibly.
          (dotimes (i (- height (length lines)))
@@ -546,8 +549,8 @@ Return a string with image data."
          (aset natural-widths i (max (aref natural-widths i)
                                      (cadr column)))
          (setq i (1+ i)))))
-    (let ((extra (- (reduce '+ suggested-widths)
-                   (reduce '+ widths)))
+    (let ((extra (- (apply '+ (append suggested-widths nil))
+                   (apply '+ (append widths nil))))
          (expanded-columns 0))
       (when (> extra 0)
        (dotimes (i length)