Copy over overlays from the TD elements to the main document.
authorLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Tue, 5 Oct 2010 16:12:24 +0000 (18:12 +0200)
committerLars Magne Ingebrigtsen <larsi@quimbies.gnus.org>
Tue, 5 Oct 2010 16:12:24 +0000 (18:12 +0200)
lisp/ChangeLog
lisp/shr.el

index f375d91..bddd86c 100644 (file)
@@ -3,6 +3,8 @@
        * shr.el (shr-find-elements): New function.
        (shr-tag-table): Put all the images after the table.
        (shr-tag-table): Really inhibit images inside the table.
+       (shr-collect-overlays): Copy over overlays from the TD elements to the
+       main document.
 
        * mm-decode.el (mm-shr): Bind shr-blocked-images to
        gnus-blocked-images.
index 9d0aaef..18dd72d 100644 (file)
@@ -445,11 +445,20 @@ Return a string with image data."
        (insert "|\n"))
       (dolist (column row)
        (goto-char start)
-       (let ((lines (split-string (nth 2 column) "\n")))
+       (let ((lines (split-string (nth 2 column) "\n"))
+             (overlay-lines (nth 3 column))
+             overlay)
          (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)))
          ;; Add blank lines at padding at the bottom of the TD,
          ;; possibly.
@@ -510,7 +519,30 @@ Return a string with image data."
          (when (> (- width (current-column)) 0)
            (insert (make-string (- width (current-column)) ? )))
          (forward-line 1)))
-      (list max (count-lines (point-min) (point-max)) (buffer-string)))))
+      (list max
+           (count-lines (point-min) (point-max))
+           (buffer-string)
+           (and fill
+                (shr-collect-overlays))))))
+
+(defun shr-collect-overlays ()
+  (save-excursion
+    (goto-char (point-min))
+    (let ((overlays nil))
+      (while (not (eobp))
+       (push (shr-overlays-in-region (point) (line-end-position))
+             overlays)
+       (forward-line 1))
+      (nreverse overlays))))
+
+(defun shr-overlays-in-region (start end)
+  (let (result)
+    (dolist (overlay (overlays-in start end))
+      (push (list (max start (- end (overlay-start overlay)))
+                 (min end (- end (overlay-end overlay) start))
+                 (overlay-properties overlay))
+           result))
+    (nreverse result)))
 
 (defun shr-pro-rate-columns (columns)
   (let ((total-percentage 0)