Skip to content

Commit c37a7aa

Browse files
author
Visuwesh
committed
Don't break when rendering local pages
* eww-plz.el (eww-plz-retrieve-advice): New :around advice to fall back to the original function for local files. (eww-plz-tag-img): Fall back to shr-tag-img for local files too. (eww-plz--hook): Document breaking thing. We could just set it globally though.
1 parent 28ebaee commit c37a7aa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

eww-plz.el

+13-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ It returns the redirection status, if any."
119119
(car (plz-error-curl-error error))
120120
(cdr (plz-error-curl-error error))))))
121121
(apply callback nil cbargs))))))
122-
(advice-add 'eww-retrieve :override #'eww-plz-retrieve)
122+
123+
(defun eww-plz-retrieve-advice (oldfun &rest args)
124+
(if (string-match-p "\\`https?://" (car args))
125+
(apply #'eww-plz-retrieve args)
126+
(apply oldfun args)))
127+
128+
(advice-add 'eww-retrieve :around #'eww-plz-retrieve-advice)
123129

124130
(defun eww-plz-tag-img (dom &optional url)
125131
"Replacement for `shr-tag-img', which see."
@@ -134,8 +140,9 @@ It returns the redirection status, if any."
134140
(null url)
135141
(member (dom-attr dom 'height) '("0" "1"))
136142
(member (dom-attr dom 'width) '("0" "1"))
137-
(string-match "\\`data:" url)
138-
(string-match "\\`cid:" url)
143+
(string-prefix-p "data:" url)
144+
(string-prefix-p "cid:" url)
145+
(string-prefix-p "file:" url)
139146
(shr-image-blocked-p url)
140147
(url-is-cached url))
141148
(shr-tag-img dom url)
@@ -184,6 +191,9 @@ It returns the redirection status, if any."
184191

185192
(defun eww-plz--hook ()
186193
"Setup the image tag routines to use the plz backed ones."
194+
;; TODO: This can break user customisation for table rendering code
195+
;; because of bad interaction between let-binding and buffer-local
196+
;; binding. Best to set it globally.
187197
(setq-local shr-external-rendering-functions
188198
(cons (cons 'img #'eww-plz-tag-img)
189199
shr-external-rendering-functions))

0 commit comments

Comments
 (0)