From: Julien Danjou Date: Wed, 24 Nov 2010 22:43:57 +0000 (+0100) Subject: shr: copy bg before rendering td X-Git-Url: http://cgit.sxemacs.org/?a=commitdiff_plain;h=c6a0508ba27bdef91d6323c86fa286db61d221d6;p=gnus shr: copy bg before rendering td Signed-off-by: Julien Danjou --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 256511673..6670686f6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -14,11 +14,14 @@ 2010-11-24 Julien Danjou * shr.el (shr-insert-background-overlay): Fix typo. + (shr-render-td): Copy the background before rendering. * shr-color.el (shr-color-visible): Fix docstring. * shr.el (shr-tag-table): Add bgcolor support. (shr-render-td): Add bgcolor support. + (shr-get-background): Add. + (shr-insert-foreground-overlay): Use shr-get-background. * message.el (message-goto-body): Use called-interactively-p. (message-in-body-p): message-goto-body returns point. diff --git a/lisp/shr.el b/lisp/shr.el index aaa54c89e..26d2b3b4c 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -520,14 +520,17 @@ ones, in case fg and bg are nil." (t (shr-color-visible bg fg))))))) +(defun shr-get-background (pos) + "Return background color at POS." + (dolist (overlay (overlays-in start (1+ start))) + (let ((background (plist-get (overlay-get overlay 'face) + :background))) + (when background + (return background))))) + (defun shr-insert-foreground-overlay (fg start end) (when fg - (let ((bg - (dolist (overlay (overlays-in start end)) - (let ((background (plist-get (overlay-get overlay 'face) - :background))) - (when background - (return background)))))) + (let ((bg (shr-get-background start))) (let ((new-colors (shr-color-check fg bg))) (when new-colors (overlay-put (make-overlay start end) 'face @@ -949,45 +952,48 @@ text will be inserted at start." (nreverse trs))) (defun shr-render-td (cont width fill) - (with-temp-buffer - (let ((cache (cdr (assoc (cons width cont) shr-content-cache)))) - (if cache - (insert cache) - (shr-insert-background-overlay (cdr (assq :bgcolor cont)) (point)) - (let ((shr-width width) - (shr-indentation 0)) - (shr-generic cont)) - (delete-region - (point) - (+ (point) - (skip-chars-backward " \t\n"))) - (push (cons (cons width cont) (buffer-string)) - shr-content-cache))) - (goto-char (point-min)) - (let ((max 0)) - (while (not (eobp)) - (end-of-line) - (setq max (max max (current-column))) - (forward-line 1)) - (when fill - (goto-char (point-min)) - ;; If the buffer is totally empty, then put a single blank - ;; line here. - (if (zerop (buffer-size)) - (insert (make-string width ? )) - ;; Otherwise, fill the buffer. - (while (not (eobp)) - (end-of-line) - (when (> (- width (current-column)) 0) - (insert (make-string (- width (current-column)) ? ))) - (forward-line 1)))) - (if fill - (list max - (count-lines (point-min) (point-max)) - (split-string (buffer-string) "\n") - (shr-collect-overlays)) - (list max - (shr-natural-width)))))) + (let ((background (shr-get-background (point)))) + (with-temp-buffer + (let ((cache (cdr (assoc (cons width cont) shr-content-cache)))) + (if cache + (insert cache) + (shr-insert-background-overlay (or (cdr (assq :bgcolor cont)) + background) + (point)) + (let ((shr-width width) + (shr-indentation 0)) + (shr-generic cont)) + (delete-region + (point) + (+ (point) + (skip-chars-backward " \t\n"))) + (push (cons (cons width cont) (buffer-string)) + shr-content-cache))) + (goto-char (point-min)) + (let ((max 0)) + (while (not (eobp)) + (end-of-line) + (setq max (max max (current-column))) + (forward-line 1)) + (when fill + (goto-char (point-min)) + ;; If the buffer is totally empty, then put a single blank + ;; line here. + (if (zerop (buffer-size)) + (insert (make-string width ? )) + ;; Otherwise, fill the buffer. + (while (not (eobp)) + (end-of-line) + (when (> (- width (current-column)) 0) + (insert (make-string (- width (current-column)) ? ))) + (forward-line 1)))) + (if fill + (list max + (count-lines (point-min) (point-max)) + (split-string (buffer-string) "\n") + (shr-collect-overlays)) + (list max + (shr-natural-width))))))) (defun shr-natural-width () (goto-char (point-min))