aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2014-11-13 17:02:07 +0100
committerLars Magne Ingebrigtsen2014-11-13 17:16:51 +0100
commitcbf8ea6f7f527fe97039f6f1e99c78258ec18ac2 (patch)
tree93f74aa158a0bdad0f13f591b0ddfccf56d5c289
parentd856e6b0d87fed67001e83fcfccba9c932af3487 (diff)
downloademacs-cbf8ea6f7f527fe97039f6f1e99c78258ec18ac2.tar.gz
emacs-cbf8ea6f7f527fe97039f6f1e99c78258ec18ac2.zip
Display SVG images in external <object> files
Fixes: debbugs:16244 * net/eww.el (eww-form-file): Fix version number. * net/shr.el (shr-parse-image-data): Remove blocked bits from external SVG images. (shr-tag-object): Display images in <object> forms. (shr-tag-table): Also insert <objects> after the tables.
-rw-r--r--lisp/net/eww.el11
-rw-r--r--lisp/net/shr.el69
2 files changed, 55 insertions, 25 deletions
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index f16ecb8c172..329c94407c2 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -420,11 +420,12 @@ word(s) will be searched for via `eww-search-prefix'."
420 (let ((buf (get-buffer-create "*eww-source*")) 420 (let ((buf (get-buffer-create "*eww-source*"))
421 (source (plist-get eww-data :source))) 421 (source (plist-get eww-data :source)))
422 (with-current-buffer buf 422 (with-current-buffer buf
423 (delete-region (point-min) (point-max)) 423 (let ((inhibit-read-only t))
424 (insert (or source "no source")) 424 (delete-region (point-min) (point-max))
425 (goto-char (point-min)) 425 (insert (or source "no source"))
426 (when (fboundp 'html-mode) 426 (goto-char (point-min))
427 (html-mode))) 427 (when (fboundp 'html-mode)
428 (html-mode))))
428 (view-buffer buf))) 429 (view-buffer buf)))
429 430
430(defun eww-readable () 431(defun eww-readable ()
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 5db03244780..7a5e2942d5d 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -783,6 +783,8 @@ element is the data blob and the second element is the content-type."
783 ((eq size 'original) 783 ((eq size 'original)
784 (create-image data nil t :ascent 100 784 (create-image data nil t :ascent 100
785 :format content-type)) 785 :format content-type))
786 ((eq content-type 'image/svg+xml)
787 (create-image data 'svg t :ascent 100))
786 ((eq size 'full) 788 ((eq size 'full)
787 (ignore-errors 789 (ignore-errors
788 (shr-rescale-image data content-type))) 790 (shr-rescale-image data content-type)))
@@ -845,14 +847,25 @@ Return a string with image data."
845 (shr-parse-image-data))))) 847 (shr-parse-image-data)))))
846 848
847(defun shr-parse-image-data () 849(defun shr-parse-image-data ()
848 (list 850 (let ((data (buffer-substring (point) (point-max)))
849 (buffer-substring (point) (point-max)) 851 (content-type
850 (save-excursion 852 (save-excursion
851 (save-restriction 853 (save-restriction
852 (narrow-to-region (point-min) (point)) 854 (narrow-to-region (point-min) (point))
853 (let ((content-type (mail-fetch-field "content-type"))) 855 (let ((content-type (mail-fetch-field "content-type")))
854 (and content-type 856 (and content-type
855 (intern content-type obarray))))))) 857 ;; Remove any comments in the type string.
858 (intern (replace-regexp-in-string ";.*" "" content-type)
859 obarray)))))))
860 ;; SVG images may contain references to further images that we may
861 ;; want to block. So special-case these by parsing the XML data
862 ;; and remove the blocked bits.
863 (when (eq content-type 'image/svg+xml)
864 (setq data
865 (shr-dom-to-xml
866 (shr-transform-dom
867 (libxml-parse-xml-region (point) (point-max))))))
868 (list data content-type)))
856 869
857(defun shr-image-displayer (content-function) 870(defun shr-image-displayer (content-function)
858 "Return a function to display an image. 871 "Return a function to display an image.
@@ -1130,18 +1143,32 @@ ones, in case fg and bg are nil."
1130 (shr-urlify (or shr-start start) (shr-expand-url url) title)))) 1143 (shr-urlify (or shr-start start) (shr-expand-url url) title))))
1131 1144
1132(defun shr-tag-object (cont) 1145(defun shr-tag-object (cont)
1133 (let ((start (point)) 1146 (unless shr-inhibit-images
1134 url) 1147 (let ((start (point))
1135 (dolist (elem cont) 1148 url multimedia image)
1136 (when (eq (car elem) 'embed) 1149 (dolist (elem cont)
1137 (setq url (or url (cdr (assq :src (cdr elem)))))) 1150 (cond
1138 (when (and (eq (car elem) 'param) 1151 ((eq (car elem) 'embed)
1139 (equal (cdr (assq :name (cdr elem))) "movie")) 1152 (setq url (or url (cdr (assq :src (cdr elem))))
1140 (setq url (or url (cdr (assq :value (cdr elem))))))) 1153 multimedia t))
1141 (when url 1154 ((and (eq (car elem) 'param)
1142 (shr-insert " [multimedia] ") 1155 (equal (cdr (assq :name (cdr elem))) "movie"))
1143 (shr-urlify start (shr-expand-url url))) 1156 (setq url (or url (cdr (assq :value (cdr elem))))
1144 (shr-generic cont))) 1157 multimedia t))
1158 ((and (eq (car elem) :type)
1159 (string-match "\\`image/svg" (cdr elem)))
1160 (setq url (cdr (assq :data cont))
1161 image t))))
1162 (when url
1163 (cond
1164 (image
1165 (shr-tag-img cont url)
1166 (setq cont nil))
1167 (multimedia
1168 (shr-insert " [multimedia] ")
1169 (shr-urlify start (shr-expand-url url)))))
1170 (when cont
1171 (shr-generic cont)))))
1145 1172
1146(defcustom shr-prefer-media-type-alist '(("webm" . 1.0) 1173(defcustom shr-prefer-media-type-alist '(("webm" . 1.0)
1147 ("ogv" . 1.0) 1174 ("ogv" . 1.0)
@@ -1483,6 +1510,8 @@ The preference is a float determined from `shr-prefer-media-type'."
1483 ;; model isn't strong enough to allow us to put the images actually 1510 ;; model isn't strong enough to allow us to put the images actually
1484 ;; into the tables. 1511 ;; into the tables.
1485 (when (zerop shr-table-depth) 1512 (when (zerop shr-table-depth)
1513 (dolist (elem (shr-find-elements cont 'object))
1514 (shr-tag-object (cdr elem)))
1486 (dolist (elem (shr-find-elements cont 'img)) 1515 (dolist (elem (shr-find-elements cont 'img))
1487 (shr-tag-img (cdr elem)))))) 1516 (shr-tag-img (cdr elem))))))
1488 1517