From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/74784 Path: news.gmane.org!not-for-mail From: Julien Danjou Newsgroups: gmane.emacs.gnus.general Subject: [PATCH] shr: render table with style Date: Mon, 6 Dec 2010 18:30:08 +0100 Message-ID: <1291656608-16263-1-git-send-email-julien@danjou.info> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1291656631 8226 80.91.229.12 (6 Dec 2010 17:30:31 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 6 Dec 2010 17:30:31 +0000 (UTC) Cc: Julien Danjou To: ding@gnus.org Original-X-From: ding-owner+M23140@lists.math.uh.edu Mon Dec 06 18:30:27 2010 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PPetN-0002yF-7Z for ding-account@gmane.org; Mon, 06 Dec 2010 18:30:25 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1PPetG-0005u9-DX; Mon, 06 Dec 2010 11:30:18 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1PPetF-0005ty-6i for ding@lists.math.uh.edu; Mon, 06 Dec 2010 11:30:17 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.72) (envelope-from ) id 1PPetA-00079u-5o for ding@lists.math.uh.edu; Mon, 06 Dec 2010 11:30:16 -0600 Original-Received: from coquelicot-s.easter-eggs.com ([213.215.37.94]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1PPet9-0004Wb-00 for ; Mon, 06 Dec 2010 18:30:11 +0100 Original-Received: from cigue.easter-eggs.fr (cigue.easter-eggs.fr [10.0.0.33]) by rose.easter-eggs.fr (Postfix) with ESMTPS id 2942714035; Mon, 6 Dec 2010 18:30:06 +0100 (CET) Original-Received: from jdanjou by cigue.easter-eggs.fr with local (Exim 4.72) (envelope-from ) id 1PPet8-0004F5-9E; Mon, 06 Dec 2010 18:30:10 +0100 X-Mailer: git-send-email 1.7.2.3 X-Spam-Score: -1.9 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:74784 Archived-At: Signed-off-by: Julien Danjou --- Lars, is the following acceptable? Tested with: Yellow background
Green backgrounds
Red on white
black background table with red text
white text on white background Orange text on white background
Same old, same old
Blue text on white background
You can test how it renders now and how it renders with that patch. :) lisp/ChangeLog | 5 +++++ lisp/shr.el | 42 ++++++++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8f28c7e..d9bd701 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2010-12-06 Julien Danjou + + * shr.el (shr-insert-table-ruler, shr-insert-table): Insert table + content with style. + 2010-12-06 Lars Magne Ingebrigtsen * shr.el (shr-tag-font): Colorize the region. diff --git a/lisp/shr.el b/lisp/shr.el index a860616..117ded1 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -202,13 +202,9 @@ redirects somewhere else." (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 style - shr-stylesheet - (or color background)) - (shr-colorize-region start (point) color background))))) + (when (and style + shr-stylesheet) + (shr-colorize-region-with-style start (point))))) (defun shr-generic (cont) (dolist (sub cont) @@ -293,6 +289,17 @@ redirects somewhere else." (unless (string-match "[ \t\n]\\'" text) (delete-char -1))))) +(defun shr-colorize-with-style (start end) + (shr-colorize-region start end + (cdr (assq 'color shr-stylesheet)) + (cdr (assq 'background-color + shr-stylesheet)))) + +(defun shr-insert-with-style (&rest text) + (let ((start (point))) + (apply 'insert text) + (shr-colorize-with-style start (point)))) + (defun shr-find-fill-point () (when (> (move-to-column shr-width) shr-width) (backward-char 1)) @@ -892,6 +899,7 @@ ones, in case fg and bg are nil." (body (or (cdr (assq 'tbody cont)) cont)) (footer (cdr (assq 'tfoot cont))) (bgcolor (cdr (assq :bgcolor cont))) + (shr-stylesheet (list (cons 'background-color bgcolor))) (nheader (if header (shr-max-columns header))) (nbody (if body (shr-max-columns body))) (nfooter (if footer (shr-max-columns footer)))) @@ -953,7 +961,8 @@ ones, in case fg and bg are nil." max))) (dotimes (i height) (shr-indent) - (insert shr-table-vertical-line "\n")) + (shr-insert-with-style + (concat (char-to-string shr-table-vertical-line) "\n"))) (dolist (column row) (goto-char start) (let ((lines (nth 2 column)) @@ -962,7 +971,8 @@ ones, in case fg and bg are nil." (dolist (line lines) (setq overlay-line (pop overlay-lines)) (end-of-line) - (insert line shr-table-vertical-line) + (shr-insert-with-style + (concat line (char-to-string shr-table-vertical-line))) (dolist (overlay overlay-line) (let ((o (make-overlay (- (point) (nth 0 overlay) 1) (- (point) (nth 1 overlay) 1))) @@ -974,8 +984,9 @@ ones, in case fg and bg are nil." ;; possibly. (dotimes (i (- height (length lines))) (end-of-line) - (insert (make-string (string-width (car lines)) ? ) - shr-table-vertical-line) + (shr-insert-with-style + (concat (make-string (string-width (car lines)) ? ) + (char-to-string shr-table-vertical-line))) (forward-line 1))))) (shr-insert-table-ruler widths))) @@ -983,10 +994,13 @@ ones, in case fg and bg are nil." (when (and (bolp) (> shr-indentation 0)) (shr-indent)) - (insert shr-table-corner) + (shr-insert-with-style + (char-to-string shr-table-corner)) (dotimes (i (length widths)) - (insert (make-string (aref widths i) shr-table-horizontal-line) - shr-table-corner)) + (shr-insert-with-style + (concat + (make-string (aref widths i) shr-table-horizontal-line) + (char-to-string shr-table-corner)))) (insert "\n")) (defun shr-table-widths (table suggested-widths) -- 1.7.2.3