Make <body> background colour rendering prettier.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Sun, 16 Jun 2013 13:39:38 +0000 (15:39 +0200)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Sun, 16 Jun 2013 13:39:38 +0000 (15:39 +0200)
* eww.el (eww-tag-body): Override the shr body rendering so that we can
put a background colour onto the entire buffer.

lisp/ChangeLog
lisp/eww.el

index e619d45..be54368 100644 (file)
@@ -1,5 +1,8 @@
 2013-06-16  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
+       * eww.el (eww-tag-body): Override the shr body rendering so that we can
+       put a background colour onto the entire buffer.
+
        * shr.el (shr-parse-base): Fix parsing error.
 
        * eww.el (eww-submit): Pass the base in to `shr-expand-url'.
index 7db661c..7014003 100644 (file)
          (shr-external-rendering-functions
           '((form . eww-tag-form)
             (input . eww-tag-input)
+            (body . eww-tag-body)
             (select . eww-tag-select))))
       (shr-insert-document document)
       (eww-convert-widgets))
     (goto-char (point-min))))
 
+(defun eww-tag-body (cont)
+  (let* ((start (point))
+        (fgcolor (cdr (or (assq :fgcolor cont)
+                           (assq :text cont))))
+        (bgcolor (cdr (assq :bgcolor cont)))
+        (shr-stylesheet (list (cons 'color fgcolor)
+                              (cons 'background-color bgcolor))))
+    (shr-generic cont)
+    (eww-colorize-region start (point) fgcolor bgcolor)))
+
+(defun eww-colorize-region (start end fg &optional bg)
+  (when (or fg bg)
+    (let ((new-colors (shr-color-check fg bg)))
+      (when new-colors
+       (when fg
+         (eww-put-color start end :foreground (cadr new-colors)))
+       (when bg
+         (eww-put-color start end :background (car new-colors)))))))
+
+(defun eww-put-color (start end type color)
+  (shr-put-color-1 start end type color))
+
 (defun eww-display-raw (charset)
   (let ((data (buffer-substring (point) (point-max))))
     (eww-setup-buffer)