Function: shr-insert-document

shr-insert-document is an autoloaded and byte-compiled function defined in shr.el.gz.

Signature

(shr-insert-document DOM)

Documentation

Render the parsed document DOM into the current buffer.

DOM should be a parse tree as generated by libxml-parse-html-region or similar.

View in manual

Source Code

;; Defined in /usr/src/emacs/lisp/net/shr.el.gz
;;;###autoload
(defun shr-insert-document (dom)
  "Render the parsed document DOM into the current buffer.
DOM should be a parse tree as generated by
`libxml-parse-html-region' or similar."
  (setq shr-content-cache nil)
  (let ((start (point))
	(shr-start nil)
	(shr-base nil)
	(shr-depth 0)
	(shr-table-id 0)
	(shr-warning nil)
	(shr-table-separator-pixel-width (shr-string-pixel-width "-"))
	(shr-internal-bullet (cons shr-bullet
				   (shr-string-pixel-width shr-bullet)))
	(shr-internal-width
         (if shr-width
             ;; Specified width; use it.
	     (if (not shr-use-fonts)
		 shr-width
	       (* shr-width (frame-char-width)))
           (shr--window-width)))
        (shr--link-targets nil)
        (hscroll (window-hscroll))
        ;; `bidi-display-reordering' is supposed to be only used for
        ;; debugging purposes, but Shr's naïve filling algorithm
        ;; cannot cope with the complexity of RTL text in an LTR
        ;; paragraph, when a long line has been continued, and for
        ;; most scripts the character metrics don't change when they
        ;; are reordered, so...  this is the best we could do :-(
        bidi-display-reordering)
    ;; Adjust for max width specification.
    (when (and shr-max-width
               (not shr-width))
      (setq shr-internal-width
            (min shr-internal-width
                 (if shr-use-fonts
                     (* shr-max-width (frame-char-width))
                   shr-max-width))))
    ;; If the window was hscrolled for some reason, shr-fill-lines
    ;; below will misbehave, because it silently assumes that it
    ;; starts with a non-hscrolled window (vertical-motion will move
    ;; to a wrong place otherwise).
    (unwind-protect
        (progn
          (set-window-hscroll nil 0)
          (shr-descend dom)
          (shr-fill-lines start (point))
          (shr--remove-blank-lines-at-the-end start (point))
          (shr--set-target-ids shr--link-targets))
      (set-window-hscroll nil hscroll))
    (when shr-warning
      (message "%s" shr-warning))))