unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39504: 27.0.60; [PATCH] eww/shr: Ensure faces of enclosing elements apply to <code> elements
@ 2020-02-08  0:06 Kévin Le Gouguec
  2020-02-08  0:17 ` Kévin Le Gouguec
  2020-02-20 13:31 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 11+ messages in thread
From: Kévin Le Gouguec @ 2020-02-08  0:06 UTC (permalink / raw)
  To: 39504

[-- Attachment #1: Type: text/plain, Size: 218 bytes --]

Hello!

I have a minor gripe with the way eww/shr render <code> elements within
other inline elements.  My main frustration stems from code inside
links[1], but this extends to other elements, e.g. <strong> and <em>:


[-- Attachment #2: foo.html --]
[-- Type: text/html, Size: 259 bytes --]

[-- Attachment #3: Type: text/plain, Size: 38 bytes --]


Here is how Emacs 26.3 rendered it:


[-- Attachment #4: emacs-26.png --]
[-- Type: image/png, Size: 45577 bytes --]

[-- Attachment #5: Type: text/plain, Size: 41 bytes --]


Here is how Emacs 27 and 28 render it:


[-- Attachment #6: emacs-27.png --]
[-- Type: image/png, Size: 58875 bytes --]

[-- Attachment #7: Type: text/plain, Size: 390 bytes --]


Both Emacs variants fail to do what I'd expect:

- Emacs 26 uses variable-pitch for <code> elements,
- Emacs 27+ uses the default face, which does ensure a monospace font,
  but also neutralizes any effects of enclosing elements, e.g.
    - no bold inside <strong>,
    - no italics inside <em>,
    - no blue color nor underline inside <a>.

For example, here is how Firefox 72 does it:


[-- Attachment #8: firefox-72.png --]
[-- Type: image/png, Size: 47052 bytes --]

[-- Attachment #9: Type: text/plain, Size: 125 bytes --]


Here is a first, simple patch that uses fixed-pitch instead of default
to ensure other face attributes are not overridden:


[-- Attachment #10: patch1.patch --]
[-- Type: text/x-diff, Size: 1135 bytes --]

From 36629660e9adf4cd500b081e8b45c76cb1d8cb4d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= <kevin.legouguec@gmail.com>
Date: Sat, 8 Feb 2020 00:08:13 +0100
Subject: [PATCH] Ensure faces of enclosing elements apply to <code> elements
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The default face overrides the attributes of every enclosing element.
E.g. with <a href="…">foo <code>bar</code> baz</a>, since shr applies
'default' top of 'shr-link', "bar" has neither a blue foreground nor
an underline.

* lisp/net/shr.el (shr-tag-code): Use a face that only sets relevant
attributes.
---
 lisp/net/shr.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 241180d471..87106b0bd6 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1438,7 +1438,7 @@ shr-tag-u
   (shr-fontize-dom dom 'underline))
 
 (defun shr-tag-code (dom)
-  (let ((shr-current-font 'default))
+  (let ((shr-current-font 'fixed-pitch))
     (shr-generic dom)))
 
 (defun shr-tag-tt (dom)
-- 
2.20.1


[-- Attachment #11: Type: text/plain, Size: 152 bytes --]


Here is an alternative patch which allows customizing the face used for
<code>, in case the user wants e.g. fixed-pitch-serif instead of
fixed-pitch:


[-- Attachment #12: patch2.patch --]
[-- Type: text/x-diff, Size: 1368 bytes --]

From b648822ac4e401984f967fdc2d78e177697089ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A9vin=20Le=20Gouguec?= <kevin.legouguec@gmail.com>
Date: Sat, 8 Feb 2020 00:08:13 +0100
Subject: [PATCH] Introduce face for <code> elements
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The default face overrides the attributes of every enclosing element.
E.g. with <a href="…">foo <code>bar</code> baz</a>, since shr applies
'default' top of 'shr-link', "bar" has neither a blue foreground nor
an underline.

* lisp/net/shr.el (shr-code): New face.
(shr-tag-code): Use it.
---
 lisp/net/shr.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 241180d471..1215fbddd0 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -142,6 +142,10 @@ shr-strike-through
   "Face for <s> elements."
   :version "24.1")
 
+(defface shr-code '((t :inherit fixed-pitch))
+  "Face for <code> elements."
+  :version "27.1")
+
 (defface shr-link
   '((t :inherit link))
   "Face for link elements."
@@ -1438,7 +1442,7 @@ shr-tag-u
   (shr-fontize-dom dom 'underline))
 
 (defun shr-tag-code (dom)
-  (let ((shr-current-font 'default))
+  (let ((shr-current-font 'shr-code))
     (shr-generic dom)))
 
 (defun shr-tag-tt (dom)
-- 
2.20.1


[-- Attachment #13: Type: text/plain, Size: 38 bytes --]


Both patches give the same results:


[-- Attachment #14: patch.png --]
[-- Type: image/png, Size: 58955 bytes --]

[-- Attachment #15: Type: text/plain, Size: 1017 bytes --]


If the second patch seems like a worthwhile addition, I can augment it
with some documentation.


Thank you for your time.


[1] Cf. for example This Week In Rust:
    https://this-week-in-rust.org/blog/2020/02/04/this-week-in-rust-324/#updates-from-rust-core


In GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.5, cairo version 1.16.0)
 of 2020-01-31 built on hirondell
Repository revision: d3ead375092e2690c1d1d6a5dd82e6e89cdf4f4c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12004000
System Description: Debian GNU/Linux 10 (buster)

Configured using:
 'configure --with-xwidgets --with-cairo'

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY
INOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF
ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS XWIDGETS
LIBSYSTEMD JSON PDUMPER LCMS2 GMP

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-04-03  8:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-08  0:06 bug#39504: 27.0.60; [PATCH] eww/shr: Ensure faces of enclosing elements apply to <code> elements Kévin Le Gouguec
2020-02-08  0:17 ` Kévin Le Gouguec
2020-02-20 13:31 ` Lars Ingebrigtsen
2020-02-20 22:19   ` Kévin Le Gouguec
2020-02-21 12:46     ` Lars Ingebrigtsen
2020-02-21 18:46       ` Kévin Le Gouguec
2020-02-26 14:06         ` Robert Pluim
2020-03-14 12:34         ` Lars Ingebrigtsen
2020-03-14 14:15           ` Kévin Le Gouguec
2020-04-02 11:00             ` Lars Ingebrigtsen
2020-04-03  8:25               ` Kévin Le Gouguec

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).