From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ralph Schleicher Newsgroups: gmane.emacs.bugs Subject: bug#47705: [PATCH] EWW: Customize display of images Date: Tue, 13 Apr 2021 23:06:24 +0200 Organization: Ralph Schleicher Message-ID: <86im4pnbcf.fsf@lima.oberreute.mueller-schleicher.de> References: <86zgy5m8ja.fsf@lima.oberreute.mueller-schleicher.de> <87wnt7zyph.fsf@gnus.org> <86o8ejmmls.fsf@lima.oberreute.mueller-schleicher.de> <875z0qtz8l.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12216"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cc: 47705@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 13 23:07:20 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWQFh-00030j-9H for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 13 Apr 2021 23:07:17 +0200 Original-Received: from localhost ([::1]:51212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWQFg-0003vK-C8 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 13 Apr 2021 17:07:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lWQFS-0003uw-F5 for bug-gnu-emacs@gnu.org; Tue, 13 Apr 2021 17:07:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lWQFS-0003eE-7h for bug-gnu-emacs@gnu.org; Tue, 13 Apr 2021 17:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lWQFS-0003Hq-1V for bug-gnu-emacs@gnu.org; Tue, 13 Apr 2021 17:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ralph Schleicher Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Apr 2021 21:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47705 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: fixed patch Original-Received: via spool by 47705-submit@debbugs.gnu.org id=B47705.161834798812593 (code B ref 47705); Tue, 13 Apr 2021 21:07:01 +0000 Original-Received: (at 47705) by debbugs.gnu.org; 13 Apr 2021 21:06:28 +0000 Original-Received: from localhost ([127.0.0.1]:60990 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWQEt-0003H3-W5 for submit@debbugs.gnu.org; Tue, 13 Apr 2021 17:06:28 -0400 Original-Received: from dd22110.kasserver.com ([85.13.141.233]:35910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWQEs-0003Gv-TK for 47705@debbugs.gnu.org; Tue, 13 Apr 2021 17:06:27 -0400 Original-Received: from charlie.oberreute.mueller-schleicher.de (dslb-094-216-126-070.094.216.pools.vodafone-ip.de [94.216.126.70]) by dd22110.kasserver.com (Postfix) with ESMTPA id 5A94318115B; Tue, 13 Apr 2021 23:06:25 +0200 (CEST) Original-Received: from lima.oberreute.mueller-schleicher.de (lima.oberreute.mueller-schleicher.de [192.168.23.12]) by charlie.oberreute.mueller-schleicher.de (Postfix) with ESMTP id 6118220614; Tue, 13 Apr 2021 23:06:24 +0200 (CEST) Original-Received: by lima.oberreute.mueller-schleicher.de (Postfix, from userid 1001) id 1A0E94A0486; Tue, 13 Apr 2021 23:06:24 +0200 (CEST) In-Reply-To: <875z0qtz8l.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 13 Apr 2021 09:33:46 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:203989 Archived-At: --=-=-= Content-Type: text/plain Hi Lars, I have thought about it again and maybe we should approach the topic from another side. Images are inline elements and so, first of all, there is no reason why the renderer should insert line breaks at all. The decision whether an image shall be displayed as an inline element or as a block element is actually made by the creator of the web page. The renderer should only follow the instructions. That means, if an image is intermixed with text, or if multiple images are placed on a single line, we should assume that there must be a reason and SHR shouldn't try to be too smart. After all, the user should be able to take the final decision. Thus, I've added an eww-toggle-inline-images command. I checked the result with, e.g. www.gnu.org, www.gnu.org/software/emacs, docs.gtk.org/gtk4, and www.lispworks.com/documentation/HyperSpec/Front -- it looks good. Maybe you reconsider adding the patch. Thank you. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-eww-toggle-inline-images.patch diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index cc546a92d6..9500624859 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi @@ -143,6 +143,13 @@ Basics toggles whether to display images or not. This also sets the @code{shr-inhibit-images} variable. +@findex eww-toggle-inline-images +@vindex shr-inline-images +@cindex Image Display + The command @code{eww-toggle-inline-images} toggles whether to +display images as inline elements or not. This also sets the +@code{shr-inline-images} variable. + @findex eww-download @vindex eww-download-directory @kindex d @@ -314,9 +321,12 @@ Advanced specific images completely by customizing @code{shr-blocked-images}. @vindex shr-inhibit-images +@vindex shr-inline-images You can control image display by customizing @code{shr-inhibit-images}. If this variable is @code{nil}, display -the ``ALT'' text of images instead. +the ``ALT'' text of images instead. By definition, images are inline +elements. However, if the variable @code{shr-inline-images} is +@code{nil}, images are displayed on a separate line. @vindex shr-color-visible-distance-min @vindex shr-color-visible-luminance-min diff --git a/lisp/net/eww.el b/lisp/net/eww.el index eec3ec7ba8..e6046bf145 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -1017,6 +1017,7 @@ eww-mode-map ["Toggle fonts" eww-toggle-fonts t] ["Toggle colors" eww-toggle-colors t] ["Toggle images" eww-toggle-images t] + ["Toggle inline images" eww-toggle-inline-images t] ["Character Encoding" eww-set-character-encoding] ["Toggle Paragraph Direction" eww-toggle-paragraph-direction])) map)) @@ -1903,6 +1904,14 @@ eww-toggle-images (message "Images are now %s" (if shr-inhibit-images "off" "on"))) +(defun eww-toggle-inline-images () + "Toggle whether or not to display images as inline elements." + (interactive nil eww-mode) + (setq shr-inline-images (not shr-inline-images)) + (eww-reload) + (message "Inline images are now %s" + (if shr-inline-images "on" "off"))) + ;;; Bookmarks code (defvar eww-bookmarks nil) diff --git a/lisp/net/shr.el b/lisp/net/shr.el index cbdeb65ba8..673c4787a3 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -188,6 +188,11 @@ shr-inhibit-images :version "28.1" :type 'boolean) +(defcustom shr-inline-images t + "If non-nil, render images as inline elements." + :version "28.1" + :type 'boolean) + (defvar shr-external-rendering-functions nil "Alist of tag/function pairs used to alter how shr renders certain tags. For instance, eww uses this to alter rendering of title, forms @@ -672,7 +677,9 @@ shr--translate-insertion-chars (defun shr-insert (text) (when (and (not (bolp)) - (get-text-property (1- (point)) 'image-url)) + (get-text-property (1- (point)) 'image-url) + (not shr-inhibit-images) + (not shr-inline-images)) (insert "\n")) (cond ((eq shr-folding-mode 'none) @@ -1147,7 +1154,8 @@ shr-put-image ;; When inserting big-ish pictures, put them at the ;; beginning of the line. (when (and (> (current-column) 0) - (> (car (image-size image t)) 400)) + (> (car (image-size image t)) 400) + (not shr-inline-images)) (insert "\n")) (if (eq size 'original) (insert-sliced-image image (or alt "*") nil 20 1) @@ -1662,7 +1670,9 @@ shr-tag-img (and dom (or (> (length (dom-attr dom 'src)) 0) (> (length (dom-attr dom 'srcset)) 0)))) - (when (> (current-column) 0) + (when (and (> (current-column) 0) + (not shr-inhibit-images) + (not shr-inline-images)) (insert "\n")) (let ((alt (dom-attr dom 'alt)) (width (shr-string-number (dom-attr dom 'width))) --=-=-= Content-Type: text/plain -- Ralph --=-=-=--