]> git.eshelyaron.com Git - emacs.git/commitdiff
Also use eww URL transformers in the actual links
authorLars Ingebrigtsen <larsi@gnus.org>
Wed, 14 Sep 2022 13:16:27 +0000 (15:16 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Wed, 14 Sep 2022 13:17:58 +0000 (15:17 +0200)
* lisp/net/eww.el (eww-mode): Use it to transform URLs
(bug#57796).

* lisp/net/shr.el (shr-url-transformer): New variable.
(shr-tag-a): Use it.

lisp/net/eww.el
lisp/net/shr.el

index 35e5bdd734298151672a099cc5456a67d012bd41..34e74f8ffaa954d83f27f293f2e9aa3e6e25e45b 100644 (file)
@@ -1180,6 +1180,7 @@ the like."
                       '((url . eww--url-at-point))))
   (setq-local bookmark-make-record-function #'eww-bookmark-make-record)
   (buffer-disable-undo)
+  (setq-local shr-url-transformer #'eww--transform-url)
   (setq buffer-read-only t))
 
 (defun eww--url-at-point ()
index a06978d9ce0223c92a5e1208a85c75b7e3c4d4d6..54ce9b1a41ce14dd89d338730f1b357e6244758a 100644 (file)
@@ -295,6 +295,11 @@ and other things:
               (make-composed-keymap shr-map image-map)
             shr-map))
 
+(defvar shr-url-transformer #'identity
+  "Function to transform URLs.
+It's called with the URL as the parameter, and should return the
+ URL to use.")
+
 ;; Public functions and commands.
 (declare-function libxml-parse-html-region "xml.c"
                  (start end &optional base-url discard-comments))
@@ -1489,7 +1494,9 @@ ones, in case fg and bg are nil."
                          (dom-attr dom 'name)))) ; Obsolete since HTML5.
       (push (cons id (set-marker (make-marker) start)) shr--link-targets))
     (when url
-      (shr-urlify (or shr-start start) (shr-expand-url url) title)
+      (shr-urlify (or shr-start start)
+                  (funcall shr-url-transformer (shr-expand-url url))
+                  title)
       ;; Check whether the URL is suspicious.
       (when-let ((warning (or (textsec-suspicious-p
                                (shr-expand-url url) 'url)