From 9a2e7412ae672c1b2c7169513646e8acfd7f53fe Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 6 Dec 2010 16:05:13 +0100 Subject: [PATCH] shr: colorize only in one place Signed-off-by: Julien Danjou --- lisp/ChangeLog | 2 ++ lisp/shr.el | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 49c465b86..2139ae41f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -4,6 +4,8 @@ will be applied to too. (shr-descend): Fix stylesheet color retrieval. (shr-colorize-region): Render background even if fg is not set. + (shr-tag-body, shr-tag-font): Enhance stylesheet with tag information. + (shr-descend): Simplify colorize. 2010-12-06 Katsumi Yamaoka diff --git a/lisp/shr.el b/lisp/shr.el index 1643a0a01..8ee1e9939 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -195,18 +195,19 @@ redirects somewhere else." (shr-stylesheet shr-stylesheet) (start (point))) (when (and style + ;; HACK: we only parse if there's color information, since + ;; that's the only thing we are rendering. (string-match "color" style)) (setq shr-stylesheet (nconc (shr-parse-style style) shr-stylesheet))) + ;; Render content (if (fboundp function) (funcall function (cdr dom)) (shr-generic (cdr dom))) - (let ((color (cdr (assq :color shr-stylesheet))) - (background (cdr (assq :background-color - shr-stylesheet)))) - (when (and shr-stylesheet - (or color background)) - (shr-colorize-region start (point) color background))))) + ;; Apply style + (shr-colorize-region start (point) + (cdr (assq 'color shr-stylesheet)) + (cdr (assq 'background-color shr-stylesheet))))) (defun shr-generic (cont) (dolist (sub cont) @@ -636,10 +637,15 @@ Apply color check via `shr-color-check'." (let* ((start (point)) (fgcolor (cdr (assq :fgcolor cont))) (bgcolor (cdr (assq :bgcolor cont))) - (shr-stylesheet (list (cons :color fgcolor) - (cons :background-color bgcolor)))) - (shr-generic cont) - (shr-colorize-region start (point) fgcolor bgcolor))) + (shr-stylesheet (if fgcolor + (if bgcolor + `((color . ,fgcolor) + (background-color . ,bgcolor) ,@shr-stylesheet) + `((color . ,fgcolor) ,@shr-stylesheet)) + (if bgcolor + `((background-color . ,bgcolor) ,@shr-stylesheet) + shr-stylesheet)))) + (shr-generic cont))) (defun shr-tag-p (cont) (shr-ensure-paragraph) @@ -840,10 +846,12 @@ Apply color check via `shr-color-check'." (shr-heading cont 'bold 'underline)) (defun shr-tag-font (cont) - (let ((start (point)) - (color (cdr (assq :color cont)))) - (shr-generic cont) - (shr-colorize-region start (point) color))) + (let* ((start (point)) + (color (cdr (assq :color cont))) + (shr-stylesheet (if color + `((color . ,fgcolor) ,@shr-stylesheet) + shr-stylesheet))) + (shr-generic cont))) ;;; Table rendering algorithm. -- 2.25.1