diff options
| author | Lars Magne Ingebrigtsen | 2010-09-09 00:08:06 +0000 |
|---|---|---|
| committer | Katsumi Yamaoka | 2010-09-09 00:08:06 +0000 |
| commit | 9778a07a35ea45f81d16d3f0714de23d8bf914c5 (patch) | |
| tree | 0a315f9f4564179620f13d673bbd80b1ba38df6e | |
| parent | 99fcd180127e80565002271cdc125cd5c02559d6 (diff) | |
| download | emacs-9778a07a35ea45f81d16d3f0714de23d8bf914c5.tar.gz emacs-9778a07a35ea45f81d16d3f0714de23d8bf914c5.zip | |
gnus-html (gnus-html-wash-tags): Search for images first, so that <a><img> works better; (gnus-html-displayed-image-map): Bind RET and TAB on images for better UX.
| -rw-r--r-- | lisp/gnus/ChangeLog | 2 | ||||
| -rw-r--r-- | lisp/gnus/gnus-html.el | 176 |
2 files changed, 103 insertions, 75 deletions
diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 29e17b99e64..f518536685d 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | (gnus-html-browse-image): Ditto. | 4 | (gnus-html-browse-image): Ditto. |
| 5 | (gnus-html-wash-tags): Add the data to allow showing the ALT text and | 5 | (gnus-html-wash-tags): Add the data to allow showing the ALT text and |
| 6 | to browse the image directly. | 6 | to browse the image directly. |
| 7 | (gnus-html-wash-tags): Search for images first, so that <a><img> works | ||
| 8 | better. | ||
| 7 | 9 | ||
| 8 | * gnus-async.el (gnus-async-article-callback): Call | 10 | * gnus-async.el (gnus-async-article-callback): Call |
| 9 | `gnus-html-prefetch-images' unconditionally. | 11 | `gnus-html-prefetch-images' unconditionally. |
diff --git a/lisp/gnus/gnus-html.el b/lisp/gnus/gnus-html.el index fc672197467..03089414e3f 100644 --- a/lisp/gnus/gnus-html.el +++ b/lisp/gnus/gnus-html.el | |||
| @@ -76,6 +76,9 @@ fit these criteria." | |||
| 76 | (let ((map (make-sparse-keymap))) | 76 | (let ((map (make-sparse-keymap))) |
| 77 | (define-key map "a" 'gnus-html-show-alt-text) | 77 | (define-key map "a" 'gnus-html-show-alt-text) |
| 78 | (define-key map "i" 'gnus-html-browse-image) | 78 | (define-key map "i" 'gnus-html-browse-image) |
| 79 | (define-key map "\r" 'gnus-html-browse-url) | ||
| 80 | (define-key map "u" 'gnus-article-copy-string) | ||
| 81 | (define-key map [tab] 'widget-forward) | ||
| 79 | map)) | 82 | map)) |
| 80 | 83 | ||
| 81 | ;;;###autoload | 84 | ;;;###autoload |
| @@ -117,15 +120,99 @@ fit these criteria." | |||
| 117 | 120 | ||
| 118 | (defvar gnus-article-mouse-face) | 121 | (defvar gnus-article-mouse-face) |
| 119 | 122 | ||
| 123 | (defun gnus-html-pre-wash () | ||
| 124 | (goto-char (point-min)) | ||
| 125 | (while (re-search-forward " *<pre_int> *</pre_int> *\n" nil t) | ||
| 126 | (replace-match "" t t)) | ||
| 127 | (goto-char (point-min)) | ||
| 128 | (while (re-search-forward "<a name[^\n>]+>" nil t) | ||
| 129 | (replace-match "" t t))) | ||
| 130 | |||
| 120 | (defun gnus-html-wash-tags () | 131 | (defun gnus-html-wash-tags () |
| 121 | (let (tag parameters string start end images url) | 132 | (let (tag parameters string start end images url) |
| 133 | (gnus-html-pre-wash) | ||
| 122 | (goto-char (point-min)) | 134 | (goto-char (point-min)) |
| 123 | (while (re-search-forward " *<pre_int> *</pre_int> *\n" nil t) | 135 | |
| 124 | (replace-match "" t t)) | 136 | ;; Search for all the images first. |
| 125 | (goto-char (point-min)) | 137 | (while (re-search-forward "<img_alt \\([^>]*\\)>" nil t) |
| 126 | (while (re-search-forward "<a name[^\n>]+>" nil t) | 138 | (setq parameters (match-string 1) |
| 127 | (replace-match "" t t)) | 139 | start (match-beginning 0)) |
| 140 | (delete-region start (point)) | ||
| 141 | (when (search-forward "</img_alt>" (line-end-position) t) | ||
| 142 | (delete-region (match-beginning 0) (match-end 0))) | ||
| 143 | (setq end (point)) | ||
| 144 | (when (string-match "src=\"\\([^\"]+\\)" parameters) | ||
| 145 | (setq url (match-string 1 parameters)) | ||
| 146 | (gnus-message 8 "gnus-html-wash-tags: fetching image URL %s" url) | ||
| 147 | (if (string-match "^cid:\\(.*\\)" url) | ||
| 148 | ;; URLs with cid: have their content stashed in other | ||
| 149 | ;; parts of the MIME structure, so just insert them | ||
| 150 | ;; immediately. | ||
| 151 | (let ((handle (mm-get-content-id | ||
| 152 | (setq url (match-string 1 url)))) | ||
| 153 | image) | ||
| 154 | (when handle | ||
| 155 | (mm-with-part handle | ||
| 156 | (setq image (gnus-create-image (buffer-string) | ||
| 157 | nil t)))) | ||
| 158 | (when image | ||
| 159 | (let ((string (buffer-substring start end))) | ||
| 160 | (delete-region start end) | ||
| 161 | (gnus-put-image image (gnus-string-or string "*") 'cid) | ||
| 162 | (gnus-add-image 'cid image)))) | ||
| 163 | ;; Normal, external URL. | ||
| 164 | (if (gnus-html-image-url-blocked-p | ||
| 165 | url | ||
| 166 | (if (buffer-live-p gnus-summary-buffer) | ||
| 167 | (with-current-buffer gnus-summary-buffer | ||
| 168 | gnus-blocked-images) | ||
| 169 | gnus-blocked-images)) | ||
| 170 | (progn | ||
| 171 | (widget-convert-button | ||
| 172 | 'link start end | ||
| 173 | :action 'gnus-html-insert-image | ||
| 174 | :help-echo url | ||
| 175 | :keymap gnus-html-image-map | ||
| 176 | :button-keymap gnus-html-image-map) | ||
| 177 | (let ((overlay (gnus-make-overlay start end)) | ||
| 178 | (spec (list url | ||
| 179 | (set-marker (make-marker) start) | ||
| 180 | (set-marker (make-marker) end)))) | ||
| 181 | (gnus-overlay-put overlay 'local-map gnus-html-image-map) | ||
| 182 | (gnus-overlay-put overlay 'gnus-image spec) | ||
| 183 | (gnus-put-text-property | ||
| 184 | start end | ||
| 185 | 'gnus-image spec))) | ||
| 186 | (let ((file (gnus-html-image-id url)) | ||
| 187 | width height alt-text) | ||
| 188 | (when (string-match "height=\"?\\([0-9]+\\)" parameters) | ||
| 189 | (setq height (string-to-number (match-string 1 parameters)))) | ||
| 190 | (when (string-match "width=\"?\\([0-9]+\\)" parameters) | ||
| 191 | (setq width (string-to-number (match-string 1 parameters)))) | ||
| 192 | (when (string-match "\\(alt\\|title\\)=\"\\([^\"]+\\)" | ||
| 193 | parameters) | ||
| 194 | (setq alt-text (match-string 2 parameters))) | ||
| 195 | ;; Don't fetch images that are really small. They're | ||
| 196 | ;; probably tracking pictures. | ||
| 197 | (when (and (or (null height) | ||
| 198 | (> height 4)) | ||
| 199 | (or (null width) | ||
| 200 | (> width 4))) | ||
| 201 | (if (file-exists-p file) | ||
| 202 | ;; It's already cached, so just insert it. | ||
| 203 | (let ((string (buffer-substring start end))) | ||
| 204 | ;; Delete the IMG text. | ||
| 205 | (delete-region start end) | ||
| 206 | (gnus-html-put-image file (point) string url alt-text)) | ||
| 207 | ;; We don't have it, so schedule it for fetching | ||
| 208 | ;; asynchronously. | ||
| 209 | (push (list url | ||
| 210 | (set-marker (make-marker) start) | ||
| 211 | (point-marker)) | ||
| 212 | images)))))))) | ||
| 213 | |||
| 128 | (goto-char (point-min)) | 214 | (goto-char (point-min)) |
| 215 | ;; Then do the other tags. | ||
| 129 | (while (re-search-forward "<\\([^ />]+\\)\\([^>]*\\)>" nil t) | 216 | (while (re-search-forward "<\\([^ />]+\\)\\([^>]*\\)>" nil t) |
| 130 | (setq tag (match-string 1) | 217 | (setq tag (match-string 1) |
| 131 | parameters (match-string 2) | 218 | parameters (match-string 2) |
| @@ -138,76 +225,7 @@ fit these criteria." | |||
| 138 | (setq end (point)) | 225 | (setq end (point)) |
| 139 | (cond | 226 | (cond |
| 140 | ;; Fetch and insert a picture. | 227 | ;; Fetch and insert a picture. |
| 141 | ((equal tag "img_alt") | 228 | ((equal tag "img_alt")) |
| 142 | (when (string-match "src=\"\\([^\"]+\\)" parameters) | ||
| 143 | (setq url (match-string 1 parameters)) | ||
| 144 | (gnus-message 8 "gnus-html-wash-tags: fetching image URL %s" url) | ||
| 145 | (if (string-match "^cid:\\(.*\\)" url) | ||
| 146 | ;; URLs with cid: have their content stashed in other | ||
| 147 | ;; parts of the MIME structure, so just insert them | ||
| 148 | ;; immediately. | ||
| 149 | (let ((handle (mm-get-content-id | ||
| 150 | (setq url (match-string 1 url)))) | ||
| 151 | image) | ||
| 152 | (when handle | ||
| 153 | (mm-with-part handle | ||
| 154 | (setq image (gnus-create-image (buffer-string) | ||
| 155 | nil t)))) | ||
| 156 | (when image | ||
| 157 | (let ((string (buffer-substring start end))) | ||
| 158 | (delete-region start end) | ||
| 159 | (gnus-put-image image (gnus-string-or string "*") 'cid) | ||
| 160 | (gnus-add-image 'cid image)))) | ||
| 161 | ;; Normal, external URL. | ||
| 162 | (if (gnus-html-image-url-blocked-p | ||
| 163 | url | ||
| 164 | (if (buffer-live-p gnus-summary-buffer) | ||
| 165 | (with-current-buffer gnus-summary-buffer | ||
| 166 | gnus-blocked-images) | ||
| 167 | gnus-blocked-images)) | ||
| 168 | (progn | ||
| 169 | (widget-convert-button | ||
| 170 | 'link start end | ||
| 171 | :action 'gnus-html-insert-image | ||
| 172 | :help-echo url | ||
| 173 | :keymap gnus-html-image-map | ||
| 174 | :button-keymap gnus-html-image-map) | ||
| 175 | (let ((overlay (gnus-make-overlay start end)) | ||
| 176 | (spec (list url | ||
| 177 | (set-marker (make-marker) start) | ||
| 178 | (set-marker (make-marker) end)))) | ||
| 179 | (gnus-overlay-put overlay 'local-map gnus-html-image-map) | ||
| 180 | (gnus-overlay-put overlay 'gnus-image spec) | ||
| 181 | (gnus-put-text-property | ||
| 182 | start end | ||
| 183 | 'gnus-image spec))) | ||
| 184 | (let ((file (gnus-html-image-id url)) | ||
| 185 | width height alt-text) | ||
| 186 | (when (string-match "height=\"?\\([0-9]+\\)" parameters) | ||
| 187 | (setq height (string-to-number (match-string 1 parameters)))) | ||
| 188 | (when (string-match "width=\"?\\([0-9]+\\)" parameters) | ||
| 189 | (setq width (string-to-number (match-string 1 parameters)))) | ||
| 190 | (when (string-match "\\(alt\\|title\\)=\"\\([^\"]+\\)" | ||
| 191 | parameters) | ||
| 192 | (setq alt-text (match-string 2 parameters))) | ||
| 193 | ;; Don't fetch images that are really small. They're | ||
| 194 | ;; probably tracking pictures. | ||
| 195 | (when (and (or (null height) | ||
| 196 | (> height 4)) | ||
| 197 | (or (null width) | ||
| 198 | (> width 4))) | ||
| 199 | (if (file-exists-p file) | ||
| 200 | ;; It's already cached, so just insert it. | ||
| 201 | (let ((string (buffer-substring start end))) | ||
| 202 | ;; Delete the IMG text. | ||
| 203 | (delete-region start end) | ||
| 204 | (gnus-html-put-image file (point) string url alt-text)) | ||
| 205 | ;; We don't have it, so schedule it for fetching | ||
| 206 | ;; asynchronously. | ||
| 207 | (push (list url | ||
| 208 | (set-marker (make-marker) start) | ||
| 209 | (point-marker)) | ||
| 210 | images)))))))) | ||
| 211 | ;; Add a link. | 229 | ;; Add a link. |
| 212 | ((or (equal tag "a") | 230 | ((or (equal tag "a") |
| 213 | (equal tag "A")) | 231 | (equal tag "A")) |
| @@ -256,6 +274,14 @@ fit these criteria." | |||
| 256 | (interactive) | 274 | (interactive) |
| 257 | (browse-url (get-text-property (point) 'gnus-image))) | 275 | (browse-url (get-text-property (point) 'gnus-image))) |
| 258 | 276 | ||
| 277 | (defun gnus-html-browse-url () | ||
| 278 | "Browse the image under point." | ||
| 279 | (interactive) | ||
| 280 | (let ((url (get-text-property (point) 'gnus-string))) | ||
| 281 | (if (not url) | ||
| 282 | (message "No URL at point") | ||
| 283 | (browse-url url)))) | ||
| 284 | |||
| 259 | (defun gnus-html-schedule-image-fetching (buffer images) | 285 | (defun gnus-html-schedule-image-fetching (buffer images) |
| 260 | (gnus-message 8 "gnus-html-schedule-image-fetching: buffer %s, images %s" | 286 | (gnus-message 8 "gnus-html-schedule-image-fetching: buffer %s, images %s" |
| 261 | buffer images) | 287 | buffer images) |