Skip to content

Instantly share code, notes, and snippets.

@imarko
Created October 25, 2020 01:25
Show Gist options
  • Save imarko/ec8f39550662fcd16908b7ec9d100e7e to your computer and use it in GitHub Desktop.
Save imarko/ec8f39550662fcd16908b7ec9d100e7e to your computer and use it in GitHub Desktop.
pandoc view mode
(define-derived-mode
pandoc-view-mode
org-mode
"pandoc-view-mode"
"View pandoc converted files in org-mode."
(erase-buffer)
(save-excursion
(call-process "pandoc" nil t nil "-torg" (buffer-file-name)))
(not-modified)
(read-only-mode t)
(view-mode t))
(add-to-list 'auto-mode-alist '("\\.docx\\'" . pandoc-view-mode))
(add-to-list 'auto-mode-alist '("\\.epub\\'" . pandoc-view-mode))
@vjohansen
Copy link

First stab at image support


(defvar epub-temp-filename "c:/temp/epub/file.epub")

(defun vjo-insert-images ()
  (interactive)
  (when (string-match "\\.epub" buffer-file-name)
    (make-directory (file-name-directory epub-temp-filename) t)
    (delete-file epub-temp-filename)
    (copy-file buffer-file-name epub-temp-filename)
    (let ((default-directory "c:/temp/epub"))
      (call-process "unzip" nil nil nil epub-temp-filename)) ;synchronously
    (save-excursion
      (let ((inhibit-read-only t))
        (goto-char (point-min))
        ;; TODO: maybe handle optional OEBPS/Images folder
        (replace-string "file:" (concat "file:" (file-name-directory epub-temp-filename)))
        ))
    (not-modified)
    (org-display-inline-images)
    ))

@imarko
Copy link
Author

imarko commented Oct 25, 2020

For more comprehensive epub support check out nov-mode or ereader mode. Both support images if I remember right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment