From: Vasilij Schneidermann <v.schneidermann@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 28402@debbugs.gnu.org
Subject: bug#28402: 25.2; shr.el uses shr-tag-img despite set shr-external-rendering-functions
Date: Sun, 24 Sep 2017 15:10:50 +0200 [thread overview]
Message-ID: <20170924131050.6erv6sshvz23dlbu@odonien.localdomain> (raw)
In-Reply-To: <83lglio36q.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 131 bytes --]
> Fair enough. Fortunately, it sounds like Lars have just agreed to
> that.
Alright, I finally got to creating a patch for this.
[-- Attachment #2: 0001-Add-indirection-to-all-shr-tag-calls.patch --]
[-- Type: text/x-diff, Size: 3625 bytes --]
From abe3f5702999b3b11645d924c7d05f48f4a265c4 Mon Sep 17 00:00:00 2001
From: Vasilij Schneidermann <mail@vasilij.de>
Date: Sun, 24 Sep 2017 14:59:10 +0200
Subject: [PATCH] Add indirection to all shr-tag-* calls
The 'shr-external-rendering-functions' variable was previously only
honored in the shr-descend function, now all direct calls to the
shr-tag-* functions have been replaced by a call to
'shr-indirect-call' which tries using an alternative rendering
function first.
* lisp/net/shr.el (shr-indirect-call): New helper function.
(shr-descend, shr-tag-object, shr-tag-video):
(shr-collect-extra-strings-in-table): Fix callers
---
lisp/net/shr.el | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 7af6148e47..fe5197b35f 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -470,12 +470,20 @@ shr-generic
(shr-insert sub)
(shr-descend sub))))
+(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
+ ;; of elements.
+ (external (cdr (assq tag-name shr-external-rendering-functions))))
+ (cond (external
+ (apply external dom args))
+ ((fboundp function)
+ (apply function dom args))
+ (t
+ (apply 'shr-generic dom args)))))
+
(defun shr-descend (dom)
- (let ((function
- (intern (concat "shr-tag-" (symbol-name (dom-tag dom))) obarray))
- ;; Allow other packages to override (or provide) rendering
- ;; of elements.
- (external (cdr (assq (dom-tag dom) shr-external-rendering-functions)))
+ (let ((tag-name (dom-tag dom))
(style (dom-attr dom 'style))
(shr-stylesheet shr-stylesheet)
(shr-depth (1+ shr-depth))
@@ -490,12 +498,7 @@ shr-descend
(setq style nil)))
;; If we have a display:none, then just ignore this part of the DOM.
(unless (equal (cdr (assq 'display shr-stylesheet)) "none")
- (cond (external
- (funcall external dom))
- ((fboundp function)
- (funcall function dom))
- (t
- (shr-generic dom)))
+ (shr-indirect-call tag-name dom)
(when (and shr-target-id
(equal (dom-attr dom 'id) shr-target-id))
;; If the element was empty, we don't have anything to put the
@@ -1404,7 +1407,7 @@ shr-tag-object
(when url
(cond
(image
- (shr-tag-img dom url)
+ (shr-indirect-call 'img dom url)
(setq dom nil))
(multimedia
(shr-insert " [multimedia] ")
@@ -1469,7 +1472,7 @@ shr-tag-video
(unless url
(setq url (car (shr--extract-best-source dom))))
(if (> (length image) 0)
- (shr-tag-img nil image)
+ (shr-indirect-call 'img nil image)
(shr-insert " [video] "))
(shr-urlify start (shr-expand-url url))))
@@ -1964,9 +1967,9 @@ shr-collect-extra-strings-in-table
do (setq tag (dom-tag child)) and
unless (memq tag '(comment style))
if (eq tag 'img)
- do (shr-tag-img child)
+ do (shr-indirect-call 'img child)
else if (eq tag 'object)
- do (shr-tag-object child)
+ do (shr-indirect-call 'object child)
else
do (setq recurse t) and
if (eq tag 'tr)
@@ -1980,7 +1983,7 @@ shr-collect-extra-strings-in-table
do (setq flags nil)
else if (car flags)
do (setq recurse nil)
- (shr-tag-table child)
+ (shr-indirect-call 'table child)
end end end end end end end end end end
when recurse
append (shr-collect-extra-strings-in-table child flags)))
--
2.14.1
next prev parent reply other threads:[~2017-09-24 13:10 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-09 19:39 bug#28402: 25.2; shr.el uses shr-tag-img despite set shr-external-rendering-functions Vasilij Schneidermann
2017-09-11 16:04 ` Eli Zaretskii
2017-09-13 17:22 ` Vasilij Schneidermann
2017-09-13 18:37 ` Eli Zaretskii
2017-09-24 13:10 ` Vasilij Schneidermann [this message]
2017-09-29 7:31 ` Eli Zaretskii
2017-10-05 10:02 ` Eli Zaretskii
2017-10-05 10:18 ` Lars Ingebrigtsen
2017-10-05 11:01 ` Eli Zaretskii
2017-10-05 11:18 ` Lars Ingebrigtsen
2017-10-05 13:14 ` Eli Zaretskii
2017-10-05 13:22 ` Lars Ingebrigtsen
2017-10-05 13:44 ` Eli Zaretskii
2017-10-05 13:52 ` Lars Ingebrigtsen
2017-10-05 20:08 ` Vasilij Schneidermann
2017-10-05 20:10 ` Lars Ingebrigtsen
2017-10-06 12:43 ` Eli Zaretskii
2017-09-13 17:27 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170924131050.6erv6sshvz23dlbu@odonien.localdomain \
--to=v.schneidermann@gmail.com \
--cc=28402@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).