* shr.el (shr-render-td): Render td content with shr-descend, so style
will be applied to <td> 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 <yamaoka@jpl.org>
(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)))
- ;; Apply style
- (shr-colorize-region start (point)
- (cdr (assq 'color shr-stylesheet))
- (cdr (assq 'background-color shr-stylesheet)))))
+ (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)))))
(defun shr-generic (cont)
(dolist (sub cont)
(shr-color-visible bg fg)))))))
(defun shr-colorize-region (start end fg &optional bg)
- "Colorize region from START to END.
-Use foreground color FG and background color BG.
-Apply color check via `shr-color-check'."
- (when (or fg bg)
+ (when fg
(let ((new-colors (shr-color-check fg bg)))
(when new-colors
(shr-put-color start end :foreground (cadr new-colors))
(let* ((start (point))
(fgcolor (cdr (assq :fgcolor cont)))
(bgcolor (cdr (assq :bgcolor cont)))
- (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)))
+ (shr-stylesheet (list (cons :color fgcolor)
+ (cons :background-color bgcolor))))
+ (shr-generic cont)
+ (shr-colorize-region start (point) fgcolor bgcolor)))
(defun shr-tag-p (cont)
(shr-ensure-paragraph)
(shr-heading cont 'bold 'underline))
(defun shr-tag-font (cont)
- (let* ((start (point))
- (color (cdr (assq :color cont)))
- (shr-stylesheet (if color
- `((color . ,color) ,@shr-stylesheet)
- shr-stylesheet)))
- (shr-generic cont)))
+ (let ((start (point))
+ (color (cdr (assq :color cont))))
+ (shr-generic cont)
+ (shr-colorize-region start (point) color)))
;;; Table rendering algorithm.