From: Lars Ingebrigtsen Date: Wed, 14 Sep 2022 13:16:27 +0000 (+0200) Subject: Also use eww URL transformers in the actual links X-Git-Tag: emacs-29.0.90~1856^2~519 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c2c4c89dbc4be55114f2874284bf46cf5bb711ed;p=emacs.git Also use eww URL transformers in the actual links * 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. --- diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 35e5bdd7342..34e74f8ffaa 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -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 () diff --git a/lisp/net/shr.el b/lisp/net/shr.el index a06978d9ce0..54ce9b1a41c 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -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)