From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#40532: 28.0.50; eww/shr: Anchor link does not work Date: Thu, 21 May 2020 23:34:15 +0100 Message-ID: <87sgfs9au0.fsf@tcd.ie> References: <87sghckn7p.fsf@milkypond.org> <87o8rk597f.fsf@milkypond.org> <87blnj92dy.fsf@tcd.ie> <87imhr65p2.fsf@tcd.ie> <878sijpqr0.fsf@milkypond.org> <87y2qjxqbu.fsf@tcd.ie> <87d07p4npz.fsf@gnus.org> <87zhatxojk.fsf@tcd.ie> <87h7wrkz9x.fsf@tcd.ie> <87k118ru3x.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="42371"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 40532@debbugs.gnu.org, Arnaud Fontaine To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 22 00:35:11 2020 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 1jbtmR-000ArI-6S for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 May 2020 00:35:11 +0200 Original-Received: from localhost ([::1]:38934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbtmQ-00045m-57 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 21 May 2020 18:35:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbtmI-00045N-Vn for bug-gnu-emacs@gnu.org; Thu, 21 May 2020 18:35:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45952) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbtmI-0003yq-M9 for bug-gnu-emacs@gnu.org; Thu, 21 May 2020 18:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jbtmI-0000td-J6 for bug-gnu-emacs@gnu.org; Thu, 21 May 2020 18:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 May 2020 22:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40532 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 40532-submit@debbugs.gnu.org id=B40532.15901004713391 (code B ref 40532); Thu, 21 May 2020 22:35:02 +0000 Original-Received: (at 40532) by debbugs.gnu.org; 21 May 2020 22:34:31 +0000 Original-Received: from localhost ([127.0.0.1]:57495 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jbtln-0000sc-Cx for submit@debbugs.gnu.org; Thu, 21 May 2020 18:34:31 -0400 Original-Received: from mail-wr1-f50.google.com ([209.85.221.50]:33238) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jbtlm-0000sP-84 for 40532@debbugs.gnu.org; Thu, 21 May 2020 18:34:30 -0400 Original-Received: by mail-wr1-f50.google.com with SMTP id l11so8293918wru.0 for <40532@debbugs.gnu.org>; Thu, 21 May 2020 15:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=5F2wljkDnH+GadHBXMmivu0PgjhFbG8jJjt3+aRqGrY=; b=k+aRVYTsZXbHi7uU6a9cGrO2AjYff7P8VgmWaS6Z84887IAuEvgDv3TCrgnnpvmIAu +qyvI6jpPVPCp4Ws+lIvkBh6KjJO2nJVhBbQYvB2ls8dXtnm0+iC4jZ2FqUKYrRoPpHh r8N/7q/UNHQV1OOd2B/TbJ7lbtyI5CEjGlV3grgyioDNW17EWqJHyFg8l7H+EUYzQUYS GX338o/xya0zctBEItANpE5VjxZ/+bu5C4k3Hf1qUZVm/voYW+5FS9MG2ZGOFB24FB3R SdnP8MVu6ePG8+1QmFAYJm8ZWj4jH/Me7yqpL8phe1Ugt6pmoxrrMNIo1338xt2ubO1I g9fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=5F2wljkDnH+GadHBXMmivu0PgjhFbG8jJjt3+aRqGrY=; b=qbMijZRne4B4rFUyBzlt/e+lhVNw7hM29GYRa5Sl3BTJTu6nTTY3hyAsefnm50wiRC WNf3fRnJ8koQFRe0qqHwyT1TQWuFjhuTCUeZv+c+CTHnPtsm7kv4+9SoncYhXlkSj1FW lhGsH+UwjqqM5fgZYCpUqrKv+etg2DKAJpOssBl6Kl39Nbt8MKpuhBAV6rHFNmo5JiJD 9kngi0wa1fDsYb7wJLMOjfjDoqfsRNVIWRIQKqAIVXGtUpQxzWIQOvJ4yMRey2vuutJm K8GLHbNZeTlSRJc1H7a4Z7I7SY4+xXSxsdsPZ1KhOLzJ99WBcqw6shyV4m3eBXe2zMKi 0RSA== X-Gm-Message-State: AOAM532LQEbk13RrP+icCvzwRsJB+IC2yUTEmeycWQWgecb83xyMH/Ss m6qdABVTTxSKOkEjhejj+ZaQWg== X-Google-Smtp-Source: ABdhPJyYllyKHuaQPG4L++0PEadpdqp4z8l4Yg8TXZcVOKnyyZR9mlT1xPFawkVDPk5ogInGdR8aug== X-Received: by 2002:adf:f642:: with SMTP id x2mr605506wrp.315.1590100464166; Thu, 21 May 2020 15:34:24 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:1f68:7ff5:120d:64e]) by smtp.gmail.com with ESMTPSA id d126sm8391108wmd.32.2020.05.21.15.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 15:34:21 -0700 (PDT) In-Reply-To: <87k118ru3x.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 19 May 2020 14:23: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:180724 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen 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 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Propertize-all-shr-fragment-IDs-as-shr-target-id.patch >From 8cced1ac250078f2ea1cf1b82538c98621f7ca2f Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" 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 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 --=-=-= Content-Type: text/plain WDYT? Thanks, -- Basil --=-=-=--