-
-
Save jakeisnt/7626c5fc5cf07fa1c228df7c59e94853 to your computer and use it in GitHub Desktop.
Elisp function that calls Pandoc's org to markdown exporter. Useful for org+clerk literate programming
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
;; You can use this function to export your current .org file as a .md file | |
;; The function requires Pandoc to be installed, so make sure you've got it! | |
;; Why use this instead of org's built in markdown exporter? | |
;; If you're a fan of both org mode and NextJournal's Clerk, you can use this to | |
;; effectively have Clerk render your .org files as you write them. | |
;; The built-in markdown exporter does not correctly annotate code blocks | |
;; with ```clojure \n ... \n```, which prevents Clerk from seeing and evaluating | |
;; your clojure code. Pandoc's exporter from org->md is simple and doesn't support | |
;; every org feature, but does annotate code blocks properly. | |
;; This works well enough for basic cases, and hopefully you can build a nice | |
;; workflow with it. | |
;; the function will save the markdown file as [org-file-name-with-extension].md | |
;; So, if you're editing "~/literate-clojure.org" the markdown file will be | |
;; "~/literate-clojure.org.md". | |
(defun export-md-on-save-org-mode-file () | |
(let ((filename | |
(buffer-file-name))) | |
(when (and (string-match-p | |
(regexp-quote ".org") (message "%s" (current-buffer))) | |
(not (string-match-p | |
(regexp-quote "[") (message "%s" (current-buffer))))) | |
(shell-command | |
(concat "pandoc -f org -t markdown -o " filename ".md " filename))))) | |
;; Run the function on save. | |
;; You might alternatively set a kbd shortcut to only run exports manually | |
(add-hook 'after-save-hook 'export-md-on-save-org-mode-file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment