Function: eww-readable

eww-readable is an interactive and byte-compiled function defined in eww.el.gz.

Signature

(eww-readable &optional ARG)

Documentation

Toggle display of only the main "readable" parts of the current web page.

This command uses heuristics to find the parts of the web page that contain the main textual portion, leaving out navigation menus and the like.

If called interactively, toggle the display of the readable parts. If the prefix argument is positive, display the readable parts, and if it is zero or negative, display the full page.

If called from Lisp, toggle the display of the readable parts if ARG is toggle. Display the readable parts if ARG is nil, omitted, or is a positive number. Display the full page if ARG is a negative number.

When eww-readable-adds-to-history is non-nil, calling this function adds a new entry to eww-history.

Probably introduced at or before Emacs version 25.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/net/eww.el.gz
(defun eww-readable (&optional arg)
  "Toggle display of only the main \"readable\" parts of the current web page.
This command uses heuristics to find the parts of the web page that
contain the main textual portion, leaving out navigation menus and the
like.

If called interactively, toggle the display of the readable parts.  If
the prefix argument is positive, display the readable parts, and if it
is zero or negative, display the full page.

If called from Lisp, toggle the display of the readable parts if ARG is
`toggle'.  Display the readable parts if ARG is nil, omitted, or is a
positive number.  Display the full page if ARG is a negative number.

When `eww-readable-adds-to-history' is non-nil, calling this function
adds a new entry to `eww-history'."
  (interactive (list (if current-prefix-arg
                         (prefix-numeric-value current-prefix-arg)
                       'toggle))
               eww-mode)
  (let* ((old-data eww-data)
	 (make-readable (cond
                         ((eq arg 'toggle)
                          (not (plist-get old-data :readable)))
                         ((and (numberp arg) (< arg 1))
                          nil)
                         (t t)))
         (dom (with-temp-buffer
		(insert (plist-get old-data :source))
                (eww--parse-html-region (point-min) (point-max))))
         (base (plist-get eww-data :url)))
    (when make-readable
      (unless (setq dom (eww-readable-dom dom))
        (message "Unable to extract readable text from this page")))
    (when dom
      (when eww-readable-adds-to-history
        (eww-save-history)
        (eww--before-browse)
        (dolist (elem '(:source :url :peer))
          (plist-put eww-data elem (plist-get old-data elem))))
      (eww-display-document (eww-document-base base dom))
      (plist-put eww-data :readable make-readable)
      (eww--after-page-change))))