From 159682d99cace7d5954bddeab4543afd58109f29 Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Tue, 23 Mar 2021 01:23:16 +0100 Subject: Verify shr-target-id property values before visit --- nov.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/nov.el b/nov.el index 0080176..69b303d 100644 --- a/nov.el +++ b/nov.el @@ -660,14 +660,19 @@ the HTML is rendered with `nov-render-html-function'." (when (not match) (error "Couldn't locate document")) (setq index match))) - (let ((shr-target-id target)) + (let ((shr-target-id target)) ; shr.el API for Emacs 27.1 and older (nov-goto-document (or index nov-documents-index)))) (when target - (let ((pos (next-single-property-change (point-min) 'shr-target-id))) - (when (not pos) - (error "Couldn't locate target")) - (goto-char pos) - (recenter (1- (max 1 scroll-margin)))))) + (let ((pos (point-min)) + done) + (while (and (not done) + (setq pos (next-single-property-change pos 'shr-target-id))) + (when (equal (get-text-property pos 'shr-target-id) target) + (goto-char pos) + (recenter (1- (max 1 scroll-margin))) + (setq done t))) + (when (not done) + (error "Couldn't locate target"))))) ;; adapted from `shr-browse-url' (defun nov-browse-url (&optional mouse-event) -- cgit v1.2.3