Created
August 31, 2020 03:32
-
-
Save ashton314/5fea9a2ead264c26b760be6d8a3ff2a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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