Git Product home page Git Product logo

nov-xwidget's Introduction

nov-xwidget - the best epub reader in Emacs

Introduction

nov-xwidget extends nov.el with the built-in xwidget webkit (You have to compile Emacs with xwidget support) and render the epub html/xhtml files with any customized CSS styles or JavaScript scripts.

Features

  • Render epub with any CSS or JavaScript scripts, including but not limited to fonts, layout etc.
  • Support dark or light mode
  • For some systems that can not use xwidget, set nov-xwidget-browser-function to other browser functions, e.g. browse-url.

Installation and Configuration

(use-package nov-xwidget
  :demand t
  :after nov
  :config
  (define-key nov-mode-map (kbd "o") 'nov-xwidget-view)
  (add-hook 'nov-mode-hook 'nov-xwidget-inject-all-files))

Three options for you to configure:

  • nov-xwidget-script
  • nov-xwidget-style-light
  • nov-xwidget-style-dark

Usage

Open an epub file in Emacs, then M-x nov-xwidget-view to change to xwidget webkit buffer.

FunctionFeature
xwidget-webkit-backBack
xwidget-webkit-forwardForward
nov-xwidget-goto-tocGoto table of contents
nov-xwidget-next-documentGoto next document
nov-xwidget-previous-documentGoto previous document
nov-xwidget-find-source-fileGoto the original source file
nov-xwidget-inject-all-filesApply styles and scripts to all documents in one epub

Contributions

I need your helps on adding more advanced styles or scripts. Add more features and make Emacs as the best epub reader!

nov-xwidget's People

Contributors

chenyanming avatar yaqubroli avatar citizen428 avatar syohex avatar tushartyagi avatar alan-w-255 avatar

Stargazers

Mark Kusper avatar  avatar Scott Steely avatar DooMWhite avatar  avatar Scott Hootman-Ng avatar  avatar  avatar  avatar  avatar Hui avatar Dimitris Mostrous avatar Pascal J avatar gty avatar  avatar ldz avatar  avatar  avatar  avatar  avatar Chaz Straney avatar  avatar  avatar Helder S Ribeiro avatar lokithus avatar  avatar  avatar Jeffrey Serio avatar Antares avatar 恺彧 avatar  avatar  avatar  avatar WuliTaoTao avatar nigo avatar Weaver Marquez avatar Sangjee Dondrub avatar Rahman avatar Zhenxu Xu avatar  avatar Vladimir Berezhnev avatar  avatar  avatar Kenzoh Sekitoh avatar FAP avatar Bill D. Strong avatar  avatar  avatar thewind avatar Yigit Emre Sahinoglu avatar Kingstom avatar Alexander Ulizko avatar Nopanun Laochunhanun avatar Yosef Weissmann avatar Jack McCown avatar Thomas Wu avatar vinurs avatar Yi Tang  avatar 觉 avatar Alcides Flores Pineda avatar NyaNya avatar  avatar stardiviner avatar Masanori Ogino avatar  avatar  avatar shosseinib avatar  avatar Ricardo Lanziano avatar Arialdo Martini avatar yibie avatar t. m. k. avatar Damon Chan avatar Alexander Barbosa avatar Akira Komamura avatar FCP avatar guidao avatar

Watchers

Mark Bestley avatar yibie avatar James Cloos avatar  avatar thinkiny avatar Yi Tang  avatar

nov-xwidget's Issues

[Bug] Wrong type argument: arrayp, nil

On nov-xwidget-view I got this: Wrong type argument: arrayp, nil

My nov-xwidget settings:

	(load "~/.emacs.d/local-packages/nov-xwidget")
	(require 'nov-xwidget)

	;; Best .epub reader
	(use-package nov-xwidget
		:demand t
		:after nov
		:config
		(define-key nov-mode-map (kbd "o") 'nov-xwidget-view)
		(add-hook 'nov-mode-hook 'nov-xwidget-inject-all-files))

My emacs was built with GTK3 and xwidget

image

OS: Arch Linux, KDE Plasma: v. 5.26.5

cursor and highlight line mode

Hi, I'm trying this package out for reading epub files in Emacs. It makes the book looks a lot better, and very close to the actual book layout.

while i read, i use the cursor as a guide to help me stay focused. i use hl-line mode for the same reason, to get below, i just call hl-line-mode, but it makes no effects in nov-xwidget, would you able to help?

image

[Bug] wrong-type-argument error

While opening epub books, I got this error.

Debugger entered--Lisp error: (wrong-type-argument consp nil)
  setcar(nil "Go语言程序设计: ")
  (if (listp v) (setcar (nthcdr 2 v) title) (aset v 2 title))
  (let* ((v (car (dom-by-tag dom 'title)))) (if (listp v) (setcar (nthcdr 2 v) title) (aset v 2 title)))
  (let ((dom dom)) (dom-append-child (dom-by-tag dom 'head) '(meta ((charset . "utf-8")))) (dom-append-child (dom-by-tag dom 'head) (list 'style nil (let* ((val (frame-parameter nil 'background-mode))) (cond ((eq val 'light) (let nil nov-xwdiget-style-light)) ((eq val 'dark) (let nil nov-xwdiget-style-dark)) (t (let nil nov-xwdiget-style-light)))))) (dom-append-child (dom-by-tag dom 'head) (list 'script nil nov-xwidget-script)) (let* ((v (car (dom-by-tag dom 'title)))) (if (listp v) (setcar (nthcdr 2 v) title) (aset v 2 title))) dom)
  (let* ((native-path (expand-file-name (if (eq major-mode 'calibredb-search-mode) (calibredb-get-file-path candidate t) candidate))) (output-native-file-name (if (or (string-equal (file-name-extension native-path) "html") (string-equal (file-name-extension native-path) "xhtml")) (format "_%s.html" (file-name-base native-path)) (file-name-nondirectory native-path))) (output-native-path (expand-file-name output-native-file-name (file-name-directory native-path))) (dom (let ((temp-buffer (generate-new-buffer " *temp*" t))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert-file-contents native-path) (libxml-parse-html-region ... ...)) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))) (title (format "%s: %s" (alist-get 'title nov-metadata) (dom-text (dom-by-tag dom 'title)))) (new-dom (let ((dom dom)) (dom-append-child (dom-by-tag dom 'head) '(meta (...))) (dom-append-child (dom-by-tag dom 'head) (list 'style nil (let* (...) (cond ... ... ...)))) (dom-append-child (dom-by-tag dom 'head) (list 'script nil nov-xwidget-script)) (let* ((v (car ...))) (if (listp v) (setcar (nthcdr 2 v) title) (aset v 2 title))) dom)) (file (let ((temp-file output-native-path) (temp-buffer (generate-new-buffer " *temp file*" t))) (unwind-protect (prog1 (save-current-buffer (set-buffer temp-buffer) (shr-dom-print new-dom) output-native-path) (save-current-buffer (set-buffer temp-buffer) (write-region nil nil temp-file nil 0))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))) (path (replace-regexp-in-string " " "%20" (concat "file:///" file)))) (if arg (let ((calibredb-preferred-format nil)) (nov-xwidget-webkit-browse-url-other-window path new-session 'switch-to-buffer)) (nov-xwidget-webkit-browse-url-other-window path new-session 'switch-to-buffer)))
  nov-xwidget-webkit-find-file("/var/folders/tg/2sc4fy1x3ksfznc8mw2h55040000gn/T/n..." nil t)
  (let* ((docs nov-documents) (index nov-documents-index) (toc nov-toc-id) (epub nov-epub-version) (metadata nov-metadata)) (nov-xwidget-webkit-find-file (cdr (aref docs index)) nil t) (save-current-buffer (set-buffer (xwidget-buffer (xwidget-webkit-current-session))) (set (make-local-variable 'nov-documents) docs) (set (make-local-variable 'nov-documents-index) index) (set (make-local-variable 'nov-toc-id) toc) (set (make-local-variable 'nov-epub-version) epub) (set (make-local-variable 'nov-metadata) metadata)))
  nov-xwidget-view()
  funcall-interactively(nov-xwidget-view)
  #<subr command-execute>(nov-xwidget-view nil nil nil)
  ad-Advice-command-execute(#<subr command-execute> nov-xwidget-view)
  apply(ad-Advice-command-execute #<subr command-execute> nov-xwidget-view)
  command-execute(nov-xwidget-view)

make the nov-xwdiget-style configurable

something like this

(defun get-nov-xwidget-style()
    (pcase nov-xwidget-style
      ('light nov-xwidget-style-light)
      ('dark nov-xwidget-style-dark)
      ('auto (pcase (frame-parameter nil 'background-mode)
               ('light nov-xwidget-style-light)
               ('dark nov-xwidget-style-dark)
               (_ nov-xwidget-style-light)))))

Does not work on Linux.

Since xwidget on Linux cannot open local html file, opening an epub file with nov-xwidget will result in a blank page only. It is a known bug of WebKitGTK, other WebKitGTK-based browser cannot open local html file either, e.g. epiphany. See Emacs (bug #55804).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.