Function: shr-tag-img
shr-tag-img is a byte-compiled function defined in shr.el.gz.
Signature
(shr-tag-img DOM &optional URL)
Source Code
;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
(defun shr-tag-img (dom &optional url)
(when (or url
(and dom
(or (> (length (dom-attr dom 'src)) 0)
(> (length (dom-attr dom 'srcset)) 0))))
(when (and (not shr-max-inline-image-size)
(> (current-column) 0))
(insert "\n"))
(let ((alt (dom-attr dom 'alt))
(width (shr-string-number (dom-attr dom 'width)))
(height (shr-string-number (dom-attr dom 'height)))
(url (shr-expand-url (or url (shr--preferred-image dom)))))
(let ((start (point-marker)))
(when (zerop (length alt))
(setq alt "*"))
(cond
((null url)
;; After further expansion, there turned out to be no valid
;; src in the img after all.
)
((or (member (dom-attr dom 'height) '("0" "1"))
(member (dom-attr dom 'width) '("0" "1")))
;; 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
(list :width width :height height))
(insert alt))))
((and (not shr-inhibit-images)
(string-match "\\`cid:" url))
(let ((url (substring url (match-end 0)))
image)
(if (or (not shr-content-function)
(not (setq image (funcall shr-content-function url))))
(insert alt)
(funcall shr-put-image-function image alt
(list :width width :height height)))))
((or shr-inhibit-images
(shr-image-blocked-p url))
(setq shr-start (point))
(shr-insert alt))
((and (not shr-ignore-cache)
(url-is-cached url))
(funcall shr-put-image-function (shr-get-image-data url) alt
(list :width width :height height)))
(t
(when (and shr-ignore-cache
(url-is-cached url))
(let ((file (url-cache-create-filename url)))
(when (file-exists-p file)
(delete-file file))))
(if (image-type-available-p 'svg)
(insert-image
(shr-make-placeholder-image dom)
(or (string-trim alt) ""))
;; No SVG support. Just use a space as our placeholder.
(insert " "))
(url-queue-retrieve
url #'shr-image-fetched
(list (current-buffer) start (set-marker (make-marker) (point))
(list :width width :height height))
t
(not (shr--use-cookies-p url shr-base)))))
(when (zerop shr-table-depth) ;; We are not in a table.
(put-text-property start (point) 'keymap shr-image-map)
(put-text-property start (point) 'shr-alt alt)
(put-text-property start (point) 'image-url url)
(put-text-property start (point) 'image-displayer
(shr-image-displayer shr-content-function))
(put-text-property start (point) 'help-echo
(shr-fill-text
(or (dom-attr dom 'title) alt))))))))