Skip to content

Instantly share code, notes, and snippets.

@ashton314
Created August 31, 2020 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashton314/5fea9a2ead264c26b760be6d8a3ff2a5 to your computer and use it in GitHub Desktop.
Save ashton314/5fea9a2ead264c26b760be6d8a3ff2a5 to your computer and use it in GitHub Desktop.
;; Pandoc conversion function
;; Requires f.el, as well as pandoc and pandoc-citeproc installed on the host system.
;; If on macOS, install with `brew install pandoc pandoc-citeproc'
(defcustom pandoc-converter-args "--filter pandoc-citeproc --pdf-engine=xelatex" "Additional arguments to pass to pandoc when running `convert-with-pandoc'")
(defun convert-with-pandoc ()
"Convert a file between formats with Pandoc.
This will place the outputted function in the same directory as
the source folder.
Opens the file in a new window if the output format is a plain-text format."
(interactive)
(let* ((in-file (read-file-name "File to convert: " nil nil t))
(out-format (completing-read "Output format: " '("md" "docx" "html" "org" "txt" "pdf")))
(out-file (f-swap-ext in-file out-format)))
(cd (f-dirname in-file))
(shell-command (concat "pandoc " pandoc-converter-args " \"" (f-filename in-file) "\" -o \"" (f-filename out-file) "\""))
(if (member out-format '("md" "txt" "html" "org"))
(find-file (f-filename out-file)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment