-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathorg-export-json.el
27 lines (26 loc) · 1.08 KB
/
org-export-json.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
;; Provides function to export current org buffer as JSON structure
;; to $file.org.json. Adapted from an org-mode mailing post by
;; Brett Viren: https://lists.gnu.org/archive/html/emacs-orgmode/2014-01/msg00338.html
(require 'json)
(defun org-export-json ()
(interactive)
(let* ((tree (org-element-parse-buffer 'object nil)))
(org-element-map tree (append org-element-all-elements
org-element-all-objects '(plain-text))
(lambda (x)
(if (org-element-property :parent x)
(org-element-put-property x :parent "none"))
(if (org-element-property :structure x)
(org-element-put-property x :structure "none"))
))
(write-region
(json-encode tree)
nil (concat (buffer-file-name) ".json"))))
(defun cli-org-export-json ()
(let ((org-file-path (car command-line-args-left))
(other-load-files (cdr command-line-args-left)))
(mapc 'load-file other-load-files)
(find-file org-file-path)
(org-mode)
(message "Exporting to JSON: %s" (car command-line-args-left))
(org-export-json)))