Function: shr-descend

shr-descend is a byte-compiled function defined in shr.el.gz.

Signature

(shr-descend DOM)

Source Code

;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
(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)))
	(style (dom-attr dom 'style))
	(shr-stylesheet shr-stylesheet)
	(shr-depth (1+ shr-depth))
	(start (point)))
    ;; shr uses many frames per nested node.
    (if (and (> shr-depth (/ max-specpdl-size 15))
             (not (and shr-offer-extend-specpdl
                       (y-or-n-p "Too deeply nested to render properly; increase `max-specpdl-size'?")
                       (setq max-specpdl-size (* max-specpdl-size 2)))))
        (setq shr-warning
              "Not rendering the complete page because of too-deep nesting")
      (when style
	(if (string-match "color\\|display\\|border-collapse" style)
	    (setq shr-stylesheet (nconc (shr-parse-style style)
					shr-stylesheet))
	  (setq style nil)))
      ;; If we have a display:none, then just ignore this part of the DOM.
      (unless (or (equal (cdr (assq 'display shr-stylesheet)) "none")
                  (and shr-discard-aria-hidden
                       (equal (dom-attr dom 'aria-hidden) "true")))
        ;; We don't use shr-indirect-call here, since shr-descend is
        ;; the central bit of shr.el, and should be as fast as
        ;; possible.  Having one more level of indirection with its
        ;; negative effect on performance is deemed unjustified in
        ;; this case.
        (cond (external
               (funcall external dom))
              ((fboundp function)
               (funcall function dom))
              (t
               (shr-generic dom)))
        (when-let* ((id (dom-attr dom 'id)))
	  ;; If the element was empty, we don't have anything to put the
	  ;; anchor on.  So just insert a dummy character.
	  (when (= start (point))
            (if (not (bolp))
                (insert ? )
              (insert ? )
              (shr-mark-fill start))
            (put-text-property (1- (point)) (point) 'display ""))
          (put-text-property (1- (point)) (point) 'shr-target-id id))
	;; If style is set, then this node has set the color.
	(when style
	  (shr-colorize-region
	   start (point)
	   (cdr (assq 'color shr-stylesheet))
	   (cdr (assq 'background-color shr-stylesheet))))))))