(shr-insert): Handle <pre> better.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Mon, 4 Oct 2010 10:32:21 +0000 (12:32 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Mon, 4 Oct 2010 10:32:21 +0000 (12:32 +0200)
lisp/ChangeLog
lisp/shr.el

index e00eaf9..b1d4198 100644 (file)
@@ -2,6 +2,7 @@
 
        * shr.el (shr-ensure-paragraph): Fix the non-empty line case.
        (shr-insert): Tweak line breaking.
+       (shr-insert): Handle <pre> better.
 
 2010-10-04  Julien Danjou  <julien@danjou.info>
 
index 05fd4b3..564234b 100644 (file)
@@ -214,14 +214,14 @@ fit these criteria."
       image)))
 
 (defun shr-tag-pre (cont)
-  (let ((shr-folding-mode nil))
+  (let ((shr-folding-mode 'none))
     (shr-ensure-newline)
     (shr-generic cont)
     (shr-ensure-newline)))
 
 (defun shr-tag-blockquote (cont)
   (let ((shr-indentation (+ shr-indentation 4)))
-    (shr-tag-pre cont)))
+    (shr-generic cont)))
 
 (defun shr-ensure-newline ()
   (unless (zerop (current-column))
@@ -233,7 +233,7 @@ fit these criteria."
     (setq shr-state nil))
   (cond
    ((eq shr-folding-mode 'none)
-    (insert t))
+    (insert text))
    (t
     (let ((first t)
          column)
@@ -242,12 +242,13 @@ fit these criteria."
        (insert " "))
       (dolist (elem (split-string text))
        (setq column (current-column))
-       (when (and (not first)
-                  (> column 0))
+       (when (> column 0)
          (cond
-          ((> (+ column (length elem) 1) shr-width)
+          ((and (or (not first)
+                    (eq shr-state 'space))
+                (> (+ column (length elem) 1) shr-width))
            (insert "\n"))
-          (t
+          ((not first)
            (insert " "))))
        (setq first nil)
        (when (and (bolp)
@@ -259,9 +260,11 @@ fit these criteria."
        (unless shr-start
          (setq shr-start (point)))
        (insert elem))
+      (setq shr-state nil)
       (when (and (string-match "[ \t\n]\\'" text)
                 (not (bolp)))
-       (insert " "))))))
+       (insert " ")
+       (setq shr-state 'space))))))
 
 (defun shr-get-image-data (url)
   "Get image data for URL.
@@ -294,7 +297,8 @@ Return a string with image data."
   (shr-generic cont))
 
 (defun shr-tag-br (cont)
-  (shr-ensure-newline)
+  (unless (bobp)
+    (insert "\n"))
   (shr-generic cont))
 
 (defun shr-tag-h1 (cont)