Skip to content

Instantly share code, notes, and snippets.

Last active January 20, 2020 21:01
What would you like to do?
;; Call this function with "M-x org-multi-file-md-export"
(defun org-multi-file-md-export ()
"Export current buffer to multiple Markdown files."
;; Loop over all entries in the file
(lambda ()
(let* ((level (nth 1 (org-heading-components)))
(title (or (nth 4 (org-heading-components)) ""))
;; Export filename is the EXPORT_FILE_NAME property, or the
;; lower-cased section title if it's not set.
(or (org-entry-get (point) "EXPORT_FILE_NAME")
(concat (replace-regexp-in-string " " "-" (downcase title)) ".md"))))
(when (= level 1) ;; export only first level entries
;; Mark the subtree so that the title also gets exported
;; Call the export function. This is one of the base org
;; functions, the 'md defines the backend to use for the
;; conversion. For exporting to other formats, simply use the
;; correct backend name, and also change the file extension
;; above.
(org-export-to-file 'md filename nil t nil))))
;; skip headlines tagged with "noexport" (this is an argument to
;; org-map-entries above)
nil nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment