[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d41a5e4b1ba 3/6: Outline support for shr rendered documents
From: |
Eli Zaretskii |
Subject: |
master d41a5e4b1ba 3/6: Outline support for shr rendered documents |
Date: |
Sat, 25 Nov 2023 05:58:35 -0500 (EST) |
branch: master
commit d41a5e4b1bafbb974d2c886d3198d9bda7821591
Author: Rahguzar <rahguzar@zohomail.eu>
Commit: Eli Zaretskii <eliz@gnu.org>
Outline support for shr rendered documents
* lisp/net/shr.el
(shr-heading): Propertize heading with level.
(shr-outline-search): An 'outline-search-function' that finds
headings using text property search.
(shr-outline-level): Outline level for 'shr-outline-search'.
(Bug#66676)
---
lisp/net/shr.el | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/lisp/net/shr.el b/lisp/net/shr.el
index e54b1a65784..71c16ebd126 100644
--- a/lisp/net/shr.el
+++ b/lisp/net/shr.el
@@ -1272,7 +1272,11 @@ START, and END. Note that START and END should be
markers."
(defun shr-heading (dom &rest types)
(shr-ensure-paragraph)
- (apply #'shr-fontize-dom dom types)
+ (let ((start (point))
+ (level (string-to-number
+ (string-remove-prefix "shr-h" (symbol-name (car types))))))
+ (apply #'shr-fontize-dom dom types)
+ (put-text-property start (pos-eol) 'outline-level level))
(shr-ensure-paragraph))
(defun shr-urlify (start url &optional title)
@@ -2069,6 +2073,41 @@ BASE is the URL of the HTML being rendered."
(shr-generic dom)
(insert ?\N{POP DIRECTIONAL ISOLATE}))
+;;; Outline Support
+(defun shr-outline-search (&optional bound move backward looking-at)
+ "A function that can be used as `outline-search-function' for rendered html.
+See `outline-search-function' for BOUND, MOVE, BACKWARD and LOOKING-AT."
+ (if looking-at
+ (get-text-property (point) 'outline-level)
+ (let ((heading-found nil)
+ (bound (or bound
+ (if backward (point-min) (point-max)))))
+ (save-excursion
+ (when (and (not (bolp))
+ (get-text-property (point) 'outline-level))
+ (forward-line (if backward -1 1)))
+ (if backward
+ (unless (get-text-property (point) 'outline-level)
+ (goto-char (or (previous-single-property-change
+ (point) 'outline-level nil bound)
+ bound)))
+ (goto-char (or (text-property-not-all (point) bound 'outline-level
nil)
+ bound)))
+ (goto-char (pos-bol))
+ (when (get-text-property (point) 'outline-level)
+ (setq heading-found (point))))
+ (if heading-found
+ (progn
+ (set-match-data (list heading-found heading-found))
+ (goto-char heading-found))
+ (when move
+ (goto-char bound)
+ nil)))))
+
+(defun shr-outline-level ()
+ "Function to be used as `outline-level' with `shr-outline-search'."
+ (get-text-property (point) 'outline-level))
+
;;; Table rendering algorithm.
;; Table rendering is the only complicated thing here. We do this by
- master updated (e736a1b5a2a -> 8157d49060b), Eli Zaretskii, 2023/11/25
- master d0d9d7f5fa3 4/6: Optionally turn on visual-line-mode + outline support, Eli Zaretskii, 2023/11/25
- master d41a5e4b1ba 3/6: Outline support for shr rendered documents,
Eli Zaretskii <=
- master 0de7efe897b 5/6: Don't insert subscript on a newline, Eli Zaretskii, 2023/11/25
- master 8157d49060b 6/6: Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs, Eli Zaretskii, 2023/11/25
- master 88bd83d1783 1/6: Make some aspects of shr rendering customizable, Eli Zaretskii, 2023/11/25
- master 42545444055 2/6: Allow displaying images inline, Eli Zaretskii, 2023/11/25