From 03776c62c995682455267851617461c1ecf3217b Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Sun, 3 May 2020 23:37:52 +0200 Subject: Rewrite Imenu code using `nov-ncx-to-html` --- nov.el | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/nov.el b/nov.el index 9347897..e7279e6 100644 --- a/nov.el +++ b/nov.el @@ -865,24 +865,15 @@ See also `nov-bookmark-make-record'." "Visit imenu item using FILENAME and TARGET." (nov-visit-relative-file filename target)) -(defun nov--imenu-create-epub2-index (toc-path) - (let ((toc (with-temp-buffer - (insert-file-contents toc-path) - (libxml-parse-xml-region (point-min) (point-max))))) - (mapcar - (lambda (node) - (-let* ((label-node (esxml-query "navLabel>text" node)) - (content-node (esxml-query "content" node)) - (href (nov-urldecode (esxml-node-attribute 'src content-node))) - (label (car (esxml-node-children label-node))) - ((filename target) (nov-url-filename-and-target href))) - (list label filename 'nov-imenu-goto-function target))) - (esxml-query-all "navPoint" toc)))) - -(defun nov--imenu-create-epub3-index (toc-path) - (let ((toc (with-temp-buffer - (insert-file-contents toc-path) - (libxml-parse-html-region (point-min) (point-max))))) +(defun nov-imenu-create-index () + "Generate Imenu index." + (let* ((toc-path (cdr (aref nov-documents 0))) + (ncxp (version< nov-epub-version "3.0")) + (toc (with-temp-buffer + (if ncxp + (insert (nov-ncx-to-html toc-path)) + (insert-file-contents toc-path)) + (libxml-parse-html-region (point-min) (point-max))))) (mapcar (lambda (node) (-let* ((href (esxml-node-attribute 'href node)) @@ -891,13 +882,6 @@ See also `nov-bookmark-make-record'." (list label filename 'nov-imenu-goto-function target))) (esxml-query-all "a" toc)))) -(defun nov-imenu-create-index () - "Generate Imenu index." - (let ((toc-path (cdr (aref nov-documents 0)))) - (if (version< nov-epub-version "3.0") - (nov--imenu-create-epub2-index toc-path) - (nov--imenu-create-epub3-index toc-path)))) - (defun nov-imenu-setup () (setq imenu-create-index-function 'nov-imenu-create-index)) (add-hook 'nov-mode-hook 'nov-imenu-setup) -- cgit v1.2.3