aboutsummaryrefslogtreecommitdiff
path: root/nov.el
diff options
context:
space:
mode:
Diffstat (limited to 'nov.el')
-rw-r--r--nov.el43
1 files changed, 32 insertions, 11 deletions
diff --git a/nov.el b/nov.el
index 473de25..c678066 100644
--- a/nov.el
+++ b/nov.el
@@ -74,6 +74,21 @@ effect in Emacs 25.1 or greater."
(const :tag "Use the width of the window" nil))
:group 'nov)
+(defcustom nov-render-html-function 'nov-render-html
+ "Function used to render HTML.
+It's called without arguments with a buffer containing HTML and
+should change it to contain the rendered version of it.")
+
+(defcustom nov-pre-html-render-hook nil
+ "Hook run before `nov-render-html'."
+ :type 'hook
+ :group 'nov)
+
+(defcustom nov-post-html-render-hook nil
+ "Hook run after `nov-render-html'."
+ :type 'hook
+ :group 'nov)
+
(defvar-local nov-temp-dir nil
"Temporary directory containing the buffer's EPUB files.")
@@ -399,18 +414,32 @@ chapter title."
(setq title '(:propertize "No title" face italic)))
(setq header-line-format (list title ": " chapter-title))))
-(defvar nov-rendering-functions
+(defvar nov-shr-rendering-functions
'(;; default function uses url-retrieve and fails on local images
(img . nov-render-img)
;; titles are rendered *inside* the document by default
(title . nov-render-title))
"Alist of rendering functions used with `shr-render-region'.")
+(defun nov-render-html ()
+ "Render HTML in current buffer with shr."
+ (run-hooks 'nov-pre-html-render-hook)
+ (let (;; HACK: make buttons use our own commands
+ (shr-map nov-mode-map)
+ (shr-external-rendering-functions nov-shr-rendering-functions)
+ (shr-use-fonts nov-variable-pitch)
+ (shr-width nov-text-width))
+ ;; HACK: `shr-external-rendering-functions' doesn't cover
+ ;; every usage of `shr-tag-img'
+ (cl-letf (((symbol-function 'shr-tag-img) 'nov-render-img))
+ (shr-render-region (point-min) (point-max))))
+ (run-hooks 'nov-post-html-render-hook))
+
(defun nov-render-document ()
"Render the document referenced by `nov-documents-index'.
If the document path refers to an image (as determined by
`image-type-file-name-regexps'), an image is inserted, otherwise
-the HTML is rendered with `shr-render-region'."
+the HTML is rendered with `nov-render-html-function'."
(interactive)
(let* ((document (aref nov-documents nov-documents-index))
(id (car document))
@@ -433,15 +462,7 @@ the HTML is rendered with `shr-render-region'."
(insert (nov-slurp path))))
(when (not imagep)
- (let (;; HACK: make buttons use our own commands
- (shr-map nov-mode-map)
- (shr-external-rendering-functions nov-rendering-functions)
- (shr-use-fonts nov-variable-pitch)
- (shr-width nov-text-width))
- ;; HACK: `shr-external-rendering-functions' doesn't cover
- ;; every usage of `shr-tag-img'
- (cl-letf (((symbol-function 'shr-tag-img) 'nov-render-img))
- (shr-render-region (point-min) (point-max)))))
+ (funcall nov-render-html-function))
(goto-char (point-min))))
(defun nov-find-document (predicate)