aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2010-10-05 23:42:01 +0000
committerKatsumi Yamaoka2010-10-05 23:42:01 +0000
commita0ec382af2995fab6c903fcf112eea37caab5945 (patch)
tree8b517ea74c86dd09c525d2cbe1aad6521f8acab6
parent130e977f46b869b229e7b95dd3bda8506a8323a4 (diff)
downloademacs-a0ec382af2995fab6c903fcf112eea37caab5945.tar.gz
emacs-a0ec382af2995fab6c903fcf112eea37caab5945.zip
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 @@
12010-10-05 Lars Magne Ingebrigtsen <larsi@gnus.org> 12010-10-05 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 2
3 * shr.el (shr-render-td): Allow blank/missing <TD>s.
4
5 * shr.el: Document the table-rendering algorithm.
6
3 * gnus-html.el (gnus-html-schedule-image-fetching): Protect against 7 * gnus-html.el (gnus-html-schedule-image-fetching): Protect against
4 invalid URLs. 8 invalid URLs.
5 9
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."
427 (apply #'shr-fontize-cont cont types) 427 (apply #'shr-fontize-cont cont types)
428 (shr-ensure-paragraph)) 428 (shr-ensure-paragraph))
429 429
430;; Table rendering is the only complicated thing here. We do this by
431;; first counting how many TDs there are in each TR, and registering
432;; how wide they think they should be ("width=45%", etc). Then we
433;; render each TD separately (this is done in temporary buffers, so
434;; that we can use all the rendering machinery as if we were in the
435;; main buffer). Now we know how much space each TD really takes, so
436;; we then render everything again with the new widths, and finally
437;; insert all these boxes into the main buffer.
430(defun shr-tag-table (cont) 438(defun shr-tag-table (cont)
431 (shr-ensure-paragraph) 439 (shr-ensure-paragraph)
432 (setq cont (or (cdr (assq 'tbody cont)) 440 (setq cont (or (cdr (assq 'tbody cont))
433 cont)) 441 cont))
434 (let* ((shr-inhibit-images t) 442 (let* ((shr-inhibit-images t)
443 ;; Find all suggested widths.
435 (columns (shr-column-specs cont)) 444 (columns (shr-column-specs cont))
445 ;; Compute how many characters wide each TD should be.
436 (suggested-widths (shr-pro-rate-columns columns)) 446 (suggested-widths (shr-pro-rate-columns columns))
447 ;; Do a "test rendering" to see how big each TD is (this can
448 ;; be smaller (if there's little text) or bigger (if there's
449 ;; unbreakable text).
437 (sketch (shr-make-table cont suggested-widths)) 450 (sketch (shr-make-table cont suggested-widths))
438 (sketch-widths (shr-table-widths sketch (length suggested-widths)))) 451 (sketch-widths (shr-table-widths sketch (length suggested-widths))))
452 ;; Then render the table again with these new "hard" widths.
439 (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths)) 453 (shr-insert-table (shr-make-table cont sketch-widths t) sketch-widths))
454 ;; Finally, insert all the images after the table. The Emacs buffer
455 ;; model isn't strong enough to allow us to put the images actually
456 ;; into the tables.
440 (dolist (elem (shr-find-elements cont 'img)) 457 (dolist (elem (shr-find-elements cont 'img))
441 (shr-tag-img (cdr elem)))) 458 (shr-tag-img (cdr elem))))
442 459
@@ -506,10 +523,14 @@ Return a string with image data."
506 (let ((trs nil)) 523 (let ((trs nil))
507 (dolist (row cont) 524 (dolist (row cont)
508 (when (eq (car row) 'tr) 525 (when (eq (car row) 'tr)
509 (let ((i 0) 526 (let ((tds nil)
510 (tds nil)) 527 (columns (cdr row))
511 (dolist (column (cdr row)) 528 (i 0)
512 (when (memq (car column) '(td th)) 529 column)
530 (while (< i (length widths))
531 (setq column (pop columns))
532 (when (or (memq (car column) '(td th))
533 (null column))
513 (push (shr-render-td (cdr column) (aref widths i) fill) 534 (push (shr-render-td (cdr column) (aref widths i) fill)
514 tds) 535 tds)
515 (setq i (1+ i)))) 536 (setq i (1+ i))))
@@ -531,11 +552,16 @@ Return a string with image data."
531 (forward-line 1)) 552 (forward-line 1))
532 (when fill 553 (when fill
533 (goto-char (point-min)) 554 (goto-char (point-min))
534 (while (not (eobp)) 555 ;; If the buffer is totally empty, then put a single blank
535 (end-of-line) 556 ;; line here.
536 (when (> (- width (current-column)) 0) 557 (if (zerop (buffer-size))
537 (insert (make-string (- width (current-column)) ? ))) 558 (insert (make-string width ? ))
538 (forward-line 1))) 559 ;; Otherwise, fill the buffer.
560 (while (not (eobp))
561 (end-of-line)
562 (when (> (- width (current-column)) 0)
563 (insert (make-string (- width (current-column)) ? )))
564 (forward-line 1))))
539 (list max 565 (list max
540 (count-lines (point-min) (point-max)) 566 (count-lines (point-min) (point-max))
541 (buffer-string) 567 (buffer-string)