summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen <larsi@gnus.org>2010-10-05 23:42:01 +0000
committerKatsumi Yamaoka <yamaoka@jpl.org>2010-10-05 23:42:01 +0000
commita0ec382af2995fab6c903fcf112eea37caab5945 (patch)
tree8b517ea74c86dd09c525d2cbe1aad6521f8acab6
parent130e977f46b869b229e7b95dd3bda8506a8323a4 (diff)
downloademacs-a0ec382af2995fab6c903fcf112eea37caab5945.tar.gz
shr.el (shr-render-td): Allow blank/missing <TD>s.
shr.el: Document the table-rendering algorithm.
-rw-r--r--lisp/gnus/ChangeLog4
-rw-r--r--lisp/gnus/shr.el44
2 files changed, 39 insertions, 9 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog
index 1217f548a6a..ed6c541c4f0 100644
--- a/lisp/gnus/ChangeLog
+++ b/lisp/gnus/ChangeLog
@@ -1,5 +1,9 @@
2010-10-05 Lars Magne Ingebrigtsen <larsi@gnus.org>
+ * shr.el (shr-render-td): Allow blank/missing <TD>s.
+
+ * shr.el: Document the table-rendering algorithm.
+
* gnus-html.el (gnus-html-schedule-image-fetching): Protect against
invalid URLs.
diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el
index 2d5d4d623fb..c7f94ebc6b3 100644
--- a/lisp/gnus/shr.el
+++ b/lisp/gnus/shr.el
@@ -427,16 +427,33 @@ Return a string with image data."
(apply #'shr-fontize-cont cont types)
(shr-ensure-paragraph))
+;; Table rendering is the only complicated thing here. We do this by
+;; first counting how many TDs there are in each TR, and registering
+;; how wide they think they should be ("width=45%", etc). Then we
+;; render each TD separately (this is done in temporary buffers, so
+;; that we can use all the rendering machinery as if we were in the
+;; main buffer). Now we know how much space each TD really takes, so
+;; we then render everything again with the new widths, and finally
+;; insert all these boxes into the main buffer.
(defun shr-tag-table (cont)
(shr-ensure-paragraph)
(setq cont (or (cdr (assq 'tbody cont))
cont))
(let* ((shr-inhibit-images t)
+ ;; Find all suggested widths.
(columns (shr-column-specs cont))
+ ;; Compute how many characters wide each TD should be.
(suggested-widths (shr-pro-rate-columns columns))
+ ;; Do a "test rendering" to see how big each TD is (this can
+ ;; be smaller (if there's little text) or bigger (if there's
+ ;; unbreakable text).
(sketch (shr-make-table cont suggested-widths))
(sketch-widths (shr-table-widths sketch (length suggested-widths))))
+ ;; Then render the table again with these new "hard" widths.
(shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths))
+ ;; Finally, insert all the images after the table. The Emacs buffer
+ ;; model isn't strong enough to allow us to put the images actually
+ ;; into the tables.
(dolist (elem (shr-find-elements cont 'img))
(shr-tag-img (cdr elem))))
@@ -506,10 +523,14 @@ Return a string with image data."
(let ((trs nil))
(dolist (row cont)
(when (eq (car row) 'tr)
- (let ((i 0)
- (tds nil))
- (dolist (column (cdr row))
- (when (memq (car column) '(td th))
+ (let ((tds nil)
+ (columns (cdr row))
+ (i 0)
+ column)
+ (while (< i (length widths))
+ (setq column (pop columns))
+ (when (or (memq (car column) '(td th))
+ (null column))
(push (shr-render-td (cdr column) (aref widths i) fill)
tds)
(setq i (1+ i))))
@@ -531,11 +552,16 @@ Return a string with image data."
(forward-line 1))
(when fill
(goto-char (point-min))
- (while (not (eobp))
- (end-of-line)
- (when (> (- width (current-column)) 0)
- (insert (make-string (- width (current-column)) ? )))
- (forward-line 1)))
+ ;; 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))))
(list max
(count-lines (point-min) (point-max))
(buffer-string)