From: David Edmondson <dme@dme.org>
To: ding@gnus.org
Subject: Re: <img src="data:..."> and shr
Date: Tue, 16 Apr 2013 07:12:18 +0100 [thread overview]
Message-ID: <cunr4ibrol9.fsf@hotblack-desiato.hh.sledj.net> (raw)
In-Reply-To: <m2y5cjblv9.fsf@igel.home>
[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]
On Mon, Apr 15 2013, Andreas Schwab wrote:
> David Edmondson <dme@dme.org> 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)
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2013-04-16 6:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-11 10:37 David Edmondson
2013-04-15 4:39 ` Katsumi Yamaoka
2013-04-15 18:01 ` David Edmondson
2013-04-15 20:05 ` Andreas Schwab
2013-04-16 6:12 ` David Edmondson [this message]
2013-04-16 6:44 ` Katsumi Yamaoka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cunr4ibrol9.fsf@hotblack-desiato.hh.sledj.net \
--to=dme@dme.org \
--cc=ding@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).