diff options
| author | Vasilij Schneidermann | 2017-10-05 13:00:13 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-10-05 13:00:13 +0300 |
| commit | e3f4b71c9de72bce59b4b7cb71627b626e82b573 (patch) | |
| tree | a140062603a47e4be10d38326eaabb24e9889bbb | |
| parent | 1c66720f3b2308acae4ed91cb65859c2bd7965ee (diff) | |
| download | emacs-e3f4b71c9de72bce59b4b7cb71627b626e82b573.tar.gz emacs-e3f4b71c9de72bce59b4b7cb71627b626e82b573.zip | |
Support indirection for 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 to call via
shr-indirect-call. (Bug#28402)
| -rw-r--r-- | lisp/net/shr.el | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lisp/net/shr.el b/lisp/net/shr.el index 7af6148e473..fe5197b35f7 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el | |||
| @@ -470,12 +470,20 @@ size, and full-buffer size." | |||
| 470 | (shr-insert sub) | 470 | (shr-insert sub) |
| 471 | (shr-descend sub)))) | 471 | (shr-descend sub)))) |
| 472 | 472 | ||
| 473 | (defun shr-indirect-call (tag-name dom &rest args) | ||
| 474 | (let ((function (intern (concat "shr-tag-" (symbol-name tag-name)) obarray)) | ||
| 475 | ;; Allow other packages to override (or provide) rendering | ||
| 476 | ;; of elements. | ||
| 477 | (external (cdr (assq tag-name shr-external-rendering-functions)))) | ||
| 478 | (cond (external | ||
| 479 | (apply external dom args)) | ||
| 480 | ((fboundp function) | ||
| 481 | (apply function dom args)) | ||
| 482 | (t | ||
| 483 | (apply 'shr-generic dom args))))) | ||
| 484 | |||
| 473 | (defun shr-descend (dom) | 485 | (defun shr-descend (dom) |
| 474 | (let ((function | 486 | (let ((tag-name (dom-tag dom)) |
| 475 | (intern (concat "shr-tag-" (symbol-name (dom-tag dom))) obarray)) | ||
| 476 | ;; Allow other packages to override (or provide) rendering | ||
| 477 | ;; of elements. | ||
| 478 | (external (cdr (assq (dom-tag dom) shr-external-rendering-functions))) | ||
| 479 | (style (dom-attr dom 'style)) | 487 | (style (dom-attr dom 'style)) |
| 480 | (shr-stylesheet shr-stylesheet) | 488 | (shr-stylesheet shr-stylesheet) |
| 481 | (shr-depth (1+ shr-depth)) | 489 | (shr-depth (1+ shr-depth)) |
| @@ -490,12 +498,7 @@ size, and full-buffer size." | |||
| 490 | (setq style nil))) | 498 | (setq style nil))) |
| 491 | ;; If we have a display:none, then just ignore this part of the DOM. | 499 | ;; If we have a display:none, then just ignore this part of the DOM. |
| 492 | (unless (equal (cdr (assq 'display shr-stylesheet)) "none") | 500 | (unless (equal (cdr (assq 'display shr-stylesheet)) "none") |
| 493 | (cond (external | 501 | (shr-indirect-call tag-name dom) |
| 494 | (funcall external dom)) | ||
| 495 | ((fboundp function) | ||
| 496 | (funcall function dom)) | ||
| 497 | (t | ||
| 498 | (shr-generic dom))) | ||
| 499 | (when (and shr-target-id | 502 | (when (and shr-target-id |
| 500 | (equal (dom-attr dom 'id) shr-target-id)) | 503 | (equal (dom-attr dom 'id) shr-target-id)) |
| 501 | ;; If the element was empty, we don't have anything to put the | 504 | ;; If the element was empty, we don't have anything to put the |
| @@ -1404,7 +1407,7 @@ ones, in case fg and bg are nil." | |||
| 1404 | (when url | 1407 | (when url |
| 1405 | (cond | 1408 | (cond |
| 1406 | (image | 1409 | (image |
| 1407 | (shr-tag-img dom url) | 1410 | (shr-indirect-call 'img dom url) |
| 1408 | (setq dom nil)) | 1411 | (setq dom nil)) |
| 1409 | (multimedia | 1412 | (multimedia |
| 1410 | (shr-insert " [multimedia] ") | 1413 | (shr-insert " [multimedia] ") |
| @@ -1469,7 +1472,7 @@ The preference is a float determined from `shr-prefer-media-type'." | |||
| 1469 | (unless url | 1472 | (unless url |
| 1470 | (setq url (car (shr--extract-best-source dom)))) | 1473 | (setq url (car (shr--extract-best-source dom)))) |
| 1471 | (if (> (length image) 0) | 1474 | (if (> (length image) 0) |
| 1472 | (shr-tag-img nil image) | 1475 | (shr-indirect-call 'img nil image) |
| 1473 | (shr-insert " [video] ")) | 1476 | (shr-insert " [video] ")) |
| 1474 | (shr-urlify start (shr-expand-url url)))) | 1477 | (shr-urlify start (shr-expand-url url)))) |
| 1475 | 1478 | ||
| @@ -1964,9 +1967,9 @@ flags that control whether to collect or render objects." | |||
| 1964 | do (setq tag (dom-tag child)) and | 1967 | do (setq tag (dom-tag child)) and |
| 1965 | unless (memq tag '(comment style)) | 1968 | unless (memq tag '(comment style)) |
| 1966 | if (eq tag 'img) | 1969 | if (eq tag 'img) |
| 1967 | do (shr-tag-img child) | 1970 | do (shr-indirect-call 'img child) |
| 1968 | else if (eq tag 'object) | 1971 | else if (eq tag 'object) |
| 1969 | do (shr-tag-object child) | 1972 | do (shr-indirect-call 'object child) |
| 1970 | else | 1973 | else |
| 1971 | do (setq recurse t) and | 1974 | do (setq recurse t) and |
| 1972 | if (eq tag 'tr) | 1975 | if (eq tag 'tr) |
| @@ -1980,7 +1983,7 @@ flags that control whether to collect or render objects." | |||
| 1980 | do (setq flags nil) | 1983 | do (setq flags nil) |
| 1981 | else if (car flags) | 1984 | else if (car flags) |
| 1982 | do (setq recurse nil) | 1985 | do (setq recurse nil) |
| 1983 | (shr-tag-table child) | 1986 | (shr-indirect-call 'table child) |
| 1984 | end end end end end end end end end end | 1987 | end end end end end end end end end end |
| 1985 | when recurse | 1988 | when recurse |
| 1986 | append (shr-collect-extra-strings-in-table child flags))) | 1989 | append (shr-collect-extra-strings-in-table child flags))) |