all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 40532@debbugs.gnu.org, Arnaud Fontaine <arnau@mini-dweeb.org>
Subject: bug#40532: 28.0.50; eww/shr: Anchor link does not work
Date: Thu, 21 May 2020 23:34:15 +0100	[thread overview]
Message-ID: <87sgfs9au0.fsf@tcd.ie> (raw)
In-Reply-To: <87k118ru3x.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 19 May 2020 14:23:46 +0200")

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

Lars Ingebrigtsen <larsi@gnus.org> writes:

> The patch is a bit hard to read, because it seems to have a lot of
> unrelated changes like:
>
>> -(require 'shr)
>> -(require 'url)
>> -(require 'url-queue)
>> -(require 'thingatpt)
>>  (require 'mm-url)
>>  (require 'puny)
>> -(eval-when-compile (require 'subr-x)) ;; for string-trim
>> +(require 'shr)
>> +(require 'text-property-search)
>> +(require 'thingatpt)
>> +(require 'url)
>> +(require 'url-queue)
>> +(eval-when-compile (require 'subr-x))

This is just adding (require 'text-property-search) and removing a stale
comment.  The only unrelated change is the lexicographic reordering.

> and
>
>> -    (when (and shr-target-id
>> -	       (equal (dom-attr dom 'name) shr-target-id))
>> -      ;; We have a zero-length <a name="foo"> element, so just
>> -      ;; insert...  something.
>> +    (when-let* ((id (or (dom-attr dom 'id)
>> +                        ;; Obsolete since HTML5.
>> +                        (dom-attr dom 'name))))
>> +      ;; We have an empty element, so just insert... something.

This is not an unrelated change; I'm changing the condition from:

  (and shr-target-id
       (equal (dom-attr dom 'name) shr-target-id))

to:

  (or (dom-attr dom 'id)
      (dom-attr dom 'name))

and storing the result of the condition for later reuse.  The key thing
to note is that the 'name' attribute is obsolete in HTML5 and the 'id'
attribute is recommended instead, which is why I'm checking both.

Though, now that I think about it again, we could avoid checking the
'id' attribute in both shr-tag-a and shr-descend by instead writing:

  (when-let* ((id (unless (dom-attr dom 'id) ; Handled by `shr-descend'.
                    (dom-attr dom 'name))))  ; Obsolete since HTML5.

> and
>
>> -	    (insert "*"))
>> -	  (put-text-property start (1+ start) 'shr-target-id shr-target-id))
>> +            (insert ?*)
>> +            (put-text-property (1- (point)) (point) 'display ""))
>> +          (put-text-property start (1+ start) 'shr-target-id id))
>
> so I can't really make out what the changes you're making in this area is...

Sorry, I didn't imagine a patch touching 20-odd lines would be
problematic.  Here's the updated patch in as minimal a form as possible:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Propertize-all-shr-fragment-IDs-as-shr-target-id.patch --]
[-- Type: text/x-diff, Size: 3137 bytes --]

From 8cced1ac250078f2ea1cf1b82538c98621f7ca2f Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Thu, 21 May 2020 23:18:33 +0100
Subject: [PATCH] Propertize all shr fragment IDs as shr-target-id

* lisp/net/shr.el (shr-descend, shr-tag-a): Display dummy anchor
characters as the empty string.  Give all relevant 'id' or 'name'
fragment identifier attributes the shr-target-id text property.
This ensures that cached content, such as tables, retains the
property across renders.  (Bug#40532)

* lisp/net/eww.el (eww-display-html): Adapt shr-target-id property
search accordingly.
---
 lisp/net/eww.el |  7 ++++---
 lisp/net/shr.el | 18 +++++++++---------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index a6c1abdbb1..b5780a6685 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -27,6 +27,7 @@
 (require 'cl-lib)
 (require 'format-spec)
 (require 'shr)
+(require 'text-property-search)
 (require 'url)
 (require 'url-queue)
 (require 'thingatpt)
@@ -543,10 +544,10 @@ eww-display-html
 	  (goto-char point))
 	 (shr-target-id
 	  (goto-char (point-min))
-	  (let ((point (next-single-property-change
-			(point-min) 'shr-target-id)))
+	  (let ((point (text-property-search-forward
+			'shr-target-id shr-target-id t)))
 	    (when point
-	      (goto-char point))))
+	      (goto-char (prop-match-beginning point)))))
 	 (t
 	  (goto-char (point-min))
 	  ;; Don't leave point inside forms, because the normal eww
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index 1f80ab74db..55c0c1d8ad 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -531,13 +531,13 @@ shr-descend
                (funcall function dom))
               (t
                (shr-generic dom)))
-	(when (and shr-target-id
-		   (equal (dom-attr dom 'id) shr-target-id))
+	(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))
-	    (insert "*"))
-	  (put-text-property start (1+ start) 'shr-target-id shr-target-id))
+	    (insert "*")
+	    (put-text-property (1- (point)) (point) 'display ""))
+	  (put-text-property start (1+ start) 'shr-target-id id))
 	;; If style is set, then this node has set the color.
 	(when style
 	  (shr-colorize-region
@@ -1497,14 +1497,14 @@ shr-tag-a
 	(start (point))
 	shr-start)
     (shr-generic dom)
-    (when (and shr-target-id
-	       (equal (dom-attr dom 'name) shr-target-id))
+    (when-let* ((id (unless (dom-attr dom 'id) ; Handled by `shr-descend'.
+                      (dom-attr dom 'name))))  ; Obsolete since HTML5.
       ;; We have a zero-length <a name="foo"> element, so just
       ;; insert...  something.
       (when (= start (point))
-	(shr-ensure-newline)
-	(insert " "))
-      (put-text-property start (1+ start) 'shr-target-id shr-target-id))
+	(insert " ")
+	(put-text-property (1- (point)) (point) 'display ""))
+      (put-text-property start (1+ start) 'shr-target-id id))
     (when url
       (shr-urlify (or shr-start start) (shr-expand-url url) title))))
 
-- 
2.26.2


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


WDYT?  Thanks,

-- 
Basil

  reply	other threads:[~2020-05-21 22:34 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10  3:56 bug#40532: 28.0.50; eww/shr: Anchor link does not work Arnaud Fontaine
2020-04-22  6:24 ` Arnaud Fontaine
2020-04-22 11:38   ` Basil L. Contovounesios
2020-04-22 12:55     ` Basil L. Contovounesios
2020-04-25 14:46       ` Arnaud Fontaine
2020-04-25 20:28         ` Basil L. Contovounesios
2020-04-30  4:11           ` Lars Ingebrigtsen
2020-04-30 10:20             ` Basil L. Contovounesios
2020-05-08  1:10               ` Basil L. Contovounesios
2020-05-12  4:57                 ` Arnaud Fontaine
2020-05-21 22:34                   ` Basil L. Contovounesios
2020-05-19 12:23                 ` Lars Ingebrigtsen
2020-05-21 22:34                   ` Basil L. Contovounesios [this message]
2020-06-13 15:06                     ` Basil L. Contovounesios
2020-06-18 15:54                       ` Basil L. Contovounesios
2020-04-22 13:53     ` Eli Zaretskii
2020-04-22 15:44       ` Basil L. Contovounesios
2020-04-22 15:57         ` Eli Zaretskii
2020-04-22 16:15           ` Basil L. Contovounesios
2020-04-22 16:21             ` Eli Zaretskii
2020-04-22 22:32               ` Basil L. Contovounesios
2020-04-22 20:10           ` Arnaud Fontaine
2020-04-22 22:32             ` Basil L. Contovounesios
2020-04-25 10:14           ` Eli Zaretskii
2020-04-30  4:13             ` Lars Ingebrigtsen
2020-04-30 10:15               ` Basil L. Contovounesios
2020-04-30 22:09                 ` Lars Ingebrigtsen
2020-05-03 23:49                   ` Basil L. Contovounesios
2020-05-07  4:02                     ` Arnaud Fontaine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sgfs9au0.fsf@tcd.ie \
    --to=contovob@tcd.ie \
    --cc=40532@debbugs.gnu.org \
    --cc=arnau@mini-dweeb.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.