diff options
| author | Katsumi Yamaoka | 2010-10-15 10:24:10 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2010-10-15 10:24:10 +0000 |
| commit | 68f6bd17e5ecd16961702fc8c66639d589baadee (patch) | |
| tree | 74539aae3416e3ac65b5a0e2379122d693bc8dcf | |
| parent | c56dfd3651db8b71107400005ee3e171c37fd2b4 (diff) | |
| download | emacs-68f6bd17e5ecd16961702fc8c66639d589baadee.tar.gz emacs-68f6bd17e5ecd16961702fc8c66639d589baadee.zip | |
shr.el (shr-tag-img): Ignore images with no data.
| -rw-r--r-- | lisp/gnus/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/gnus/shr.el | 117 |
2 files changed, 63 insertions, 58 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 4c722b3d8aa..765309e28a0 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2010-10-15 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 2 | |||
| 3 | * shr.el (shr-tag-img): Ignore images with no data. | ||
| 4 | |||
| 1 | 2010-10-15 Katsumi Yamaoka <yamaoka@jpl.org> | 5 | 2010-10-15 Katsumi Yamaoka <yamaoka@jpl.org> |
| 2 | 6 | ||
| 3 | * shr.el (shr-generic): Remove trailing space. | 7 | * shr.el (shr-generic): Remove trailing space. |
diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el index 0ebd60c7543..6499b35d072 100644 --- a/lisp/gnus/shr.el +++ b/lisp/gnus/shr.el | |||
| @@ -421,64 +421,65 @@ Return a string with image data." | |||
| 421 | (browse-url-url-encode-chars url "[)$ ]")) | 421 | (browse-url-url-encode-chars url "[)$ ]")) |
| 422 | 422 | ||
| 423 | (defun shr-tag-img (cont) | 423 | (defun shr-tag-img (cont) |
| 424 | (when (and (> (current-column) 0) | 424 | (when cont |
| 425 | (not (eq shr-state 'image))) | 425 | (when (and (> (current-column) 0) |
| 426 | (insert "\n")) | 426 | (not (eq shr-state 'image))) |
| 427 | (let ((alt (cdr (assq :alt cont))) | 427 | (insert "\n")) |
| 428 | (url (cdr (assq :src cont))) | 428 | (let ((alt (cdr (assq :alt cont))) |
| 429 | (width (cdr (assq :width cont)))) | 429 | (url (cdr (assq :src cont))) |
| 430 | ;; Only respect align if width specified. | 430 | (width (cdr (assq :width cont)))) |
| 431 | (when width | 431 | ;; Only respect align if width specified. |
| 432 | ;; Check that width is not larger than max width, otherwise ignore | 432 | (when width |
| 433 | ;; align | 433 | ;; Check that width is not larger than max width, otherwise ignore |
| 434 | (let ((max-width (* shr-width (frame-char-width))) | 434 | ;; align |
| 435 | (width (string-to-number width))) | 435 | (let ((max-width (* shr-width (frame-char-width))) |
| 436 | (when (< width max-width) | 436 | (width (string-to-number width))) |
| 437 | (let ((align (cdr (assq :align cont)))) | 437 | (when (< width max-width) |
| 438 | (cond | 438 | (let ((align (cdr (assq :align cont)))) |
| 439 | ((string= align "right") | 439 | (cond |
| 440 | (insert (propertize | 440 | ((string= align "right") |
| 441 | " " 'display | 441 | (insert (propertize |
| 442 | `(space . (:align-to | 442 | " " 'display |
| 443 | ,(list (- max-width width))))))) | 443 | `(space . (:align-to |
| 444 | ((string= align "center") | 444 | ,(list (- max-width width))))))) |
| 445 | (insert (propertize | 445 | ((string= align "center") |
| 446 | " " 'display | 446 | (insert (propertize |
| 447 | `(space . (:balign-to | 447 | " " 'display |
| 448 | ,(list (- (/ max-width 2) width)))))))))))) | 448 | `(space . (:balign-to |
| 449 | (let ((start (point-marker))) | 449 | ,(list (- (/ max-width 2) width)))))))))))) |
| 450 | (when (zerop (length alt)) | 450 | (let ((start (point-marker))) |
| 451 | (setq alt "[img]")) | 451 | (when (zerop (length alt)) |
| 452 | (cond | 452 | (setq alt "[img]")) |
| 453 | ((and (not shr-inhibit-images) | 453 | (cond |
| 454 | (string-match "\\`cid:" url)) | 454 | ((and (not shr-inhibit-images) |
| 455 | (let ((url (substring url (match-end 0))) | 455 | (string-match "\\`cid:" url)) |
| 456 | image) | 456 | (let ((url (substring url (match-end 0))) |
| 457 | (if (or (not shr-content-function) | 457 | image) |
| 458 | (not (setq image (funcall shr-content-function url)))) | 458 | (if (or (not shr-content-function) |
| 459 | (insert alt) | 459 | (not (setq image (funcall shr-content-function url)))) |
| 460 | (shr-put-image image (point) alt)))) | 460 | (insert alt) |
| 461 | ((or shr-inhibit-images | 461 | (shr-put-image image (point) alt)))) |
| 462 | (and shr-blocked-images | 462 | ((or shr-inhibit-images |
| 463 | (string-match shr-blocked-images url))) | 463 | (and shr-blocked-images |
| 464 | (setq shr-start (point)) | 464 | (string-match shr-blocked-images url))) |
| 465 | (let ((shr-state 'space)) | 465 | (setq shr-start (point)) |
| 466 | (if (> (length alt) 8) | 466 | (let ((shr-state 'space)) |
| 467 | (shr-insert (substring alt 0 8)) | 467 | (if (> (length alt) 8) |
| 468 | (shr-insert alt)))) | 468 | (shr-insert (substring alt 0 8)) |
| 469 | ((url-is-cached (shr-encode-url url)) | 469 | (shr-insert alt)))) |
| 470 | (shr-put-image (shr-get-image-data url) (point) alt)) | 470 | ((url-is-cached (shr-encode-url url)) |
| 471 | (t | 471 | (shr-put-image (shr-get-image-data url) (point) alt)) |
| 472 | (insert alt) | 472 | (t |
| 473 | (ignore-errors | 473 | (insert alt) |
| 474 | (url-retrieve (shr-encode-url url) 'shr-image-fetched | 474 | (ignore-errors |
| 475 | (list (current-buffer) start (point-marker)) | 475 | (url-retrieve (shr-encode-url url) 'shr-image-fetched |
| 476 | t)))) | 476 | (list (current-buffer) start (point-marker)) |
| 477 | (insert " ") | 477 | t)))) |
| 478 | (put-text-property start (point) 'keymap shr-map) | 478 | (insert " ") |
| 479 | (put-text-property start (point) 'shr-alt alt) | 479 | (put-text-property start (point) 'keymap shr-map) |
| 480 | (put-text-property start (point) 'shr-image url) | 480 | (put-text-property start (point) 'shr-alt alt) |
| 481 | (setq shr-state 'image)))) | 481 | (put-text-property start (point) 'shr-image url) |
| 482 | (setq shr-state 'image))))) | ||
| 482 | 483 | ||
| 483 | (defun shr-tag-pre (cont) | 484 | (defun shr-tag-pre (cont) |
| 484 | (let ((shr-folding-mode 'none)) | 485 | (let ((shr-folding-mode 'none)) |