On Mon, Apr 15 2013, Andreas Schwab wrote: > David Edmondson writes: > >> That's good to know, thanks. I was surprised that I couldn't quickly >> find a non-w3m function to do the URL decoding already in emacs. It's >> easy to write a new one, of course, but did I miss an existing function? > > (url-unhex-string "%2b%2d%3d") => "+-=" Thank you. Here is an improved patch. diff --git a/lisp/shr.el b/lisp/shr.el index 5df5297..eaf83e2 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -593,6 +593,16 @@ size, and full-buffer size." (put-text-property start (point) type value)))))))))) (kill-buffer image-buffer))) +(defun shr-image-from-data (data) + "Return an image from the data: URI content DATA." + (when (string-match "\\(\\([^/;,]+\\(/[^;,]+\\)?\\)\\(;[^;,]+\\)*\\)?,\\(.*\\)" + data) + (let ((param (match-string 4 data)) + (payload (url-unhex-string (match-string 5 data)))) + (when (string-match "^.*\\(;[ \t]*base64\\)$" param) + (setq payload (base64-decode-string payload))) + payload))) + (defun shr-put-image (data alt &optional flags) "Put image DATA with a string ALT. Return image." (if (display-graphic-p) @@ -983,6 +993,12 @@ ones, in case fg and bg are nil." ;; Ignore zero-sized or single-pixel images. ) ((and (not shr-inhibit-images) + (string-match "\\`data:" url)) + (let ((image (shr-image-from-data (substring url (match-end 0))))) + (if image + (funcall shr-put-image-function image alt) + (insert alt)))) + ((and (not shr-inhibit-images) (string-match "\\`cid:" url)) (let ((url (substring url (match-end 0))) image)