--- shr.el.old 2021-12-18 16:04:43.000000000 +0800 +++ shr.el 2021-12-18 16:18:30.000000000 +0800 @@ -56,8 +56,16 @@ :version "24.1" :type 'float) +(defcustom shr-safe-images nil + "Only images that have URLs matching this regexp will be displayed. +The nil value means all URLs are allowed. This can be overrided +by `shr-blocked-images'." + :version "29.1" + :type '(choice (const nil) regexp)) + (defcustom shr-blocked-images nil - "Images that have URLs matching this regexp will be blocked." + "Images that have URLs matching this regexp will be blocked. +This take effect in prior to `shr-safe-images'." :version "24.1" :type '(choice (const nil) regexp)) @@ -483,6 +491,12 @@ (shr-insert sub) (shr-descend sub)))) +(defsubst shr-image-is-blocked (url) + (or (and shr-blocked-images + (string-match shr-blocked-images url)) + (and shr-safe-images + (not (string-match shr-safe-images url))))) + (defun shr-indirect-call (tag-name dom &rest args) (let ((function (intern (concat "shr-tag-" (symbol-name tag-name)) obarray)) ;; Allow other packages to override (or provide) rendering @@ -1186,7 +1200,7 @@ ;; SVG images may contain references to further images that we may ;; want to block. So special-case these by parsing the XML data ;; and remove anything that looks like a blocked bit. - (when (and shr-blocked-images + (when (and (or shr-safe-images shr-blocked-images) (eq content-type 'image/svg+xml)) (setq data ;; Note that libxml2 doesn't parse everything perfectly, @@ -1380,8 +1394,7 @@ ((or (not (eq (dom-tag elem) 'image)) ;; Filter out blocked elements inside the SVG image. (not (setq url (dom-attr elem ':xlink:href))) - (not shr-blocked-images) - (not (string-match shr-blocked-images url))) + (not (shr-image-is-blocked url))) (insert " ") (shr-dom-print elem))))) (insert (format "" (dom-tag dom)))) @@ -1657,8 +1670,7 @@ (funcall shr-put-image-function image alt (list :width width :height height))))) ((or shr-inhibit-images - (and shr-blocked-images - (string-match shr-blocked-images url))) + (shr-image-is-blocked url)) (setq shr-start (point)) (shr-insert alt)) ((and (not shr-ignore-cache)