[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Org mode and "shunt" exporters?
From: |
Brett Viren |
Subject: |
Re: [O] Org mode and "shunt" exporters? |
Date: |
Fri, 13 Dec 2013 18:06:04 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Hi Eric,
Eric Schulte <address@hidden> writes:
> This should work in a recent Emacs.
>
> (require 'json)
> (defun org-as-json-to-file (&optional path)
> "Export the current Org-mode buffer as JSON to the supplied PATH."
> (interactive "Fwrite to file: ")
> (let ((tree (org-element-parse-buffer)))
> (org-element-map tree
> (append org-element-all-objects org-element-all-elements)
> (lambda (el) (org-element-put-property el :parent nil)))
> (with-temp-file path
> (insert (json-encode tree)))))
Thanks. With this, Nicolas's and all the other input I've got something
working now. There was still one small issue I found with this last
round. The :structure property also causes an error inside json.el
like:
json-encode-key: Bad JSON object key: 105
But, for now, nulling :structure in the same way as :parent let's me
chain org->JSON->Python! The first elisp code block in the test doc
below works.
Thanks for all the patient help from everyone. I've learned a lot.
-Brett.
#+TITLE: The Title.
Blah blah blah.
* A heading.
This uses http://edward.oconnor.cx/2006/03/json.el
- foo
- bar
- baz
#+BEGIN_SRC elisp
(require 'json)
(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"))
;; (if (eq (org-element-type x) 'plain-text)
;; (org-element-set-contents x (substring-no-properties
;; (org-element-contents x))))
))
(write-region
(json-encode tree)
;(prin1-to-string tree)
nil "foo.dat"))
#+END_SRC
#+RESULTS:
* From Eric Schultz
#+BEGIN_SRC elisp
(require 'json)
(defun org-as-json-to-file (&optional path)
"Export the current Org-mode buffer as JSON to the supplied PATH."
(interactive "Fwrite to file: ")
(let ((tree (org-element-parse-buffer)))
(org-element-map tree
(append org-element-all-objects org-element-all-elements)
(lambda (el) (org-element-put-property el :parent "none")))
(with-temp-file path
(insert (json-encode tree)))))
(org-as-json-to-file "eric.txt")
#+END_SRC
* Try some hand written data
#+BEGIN_SRC elisp
(require 'json)
(with-current-buffer (find-file-noselect "foo.dat")
(let ((tree (read (current-buffer))))
(prin1-to-string (json-encode tree))))
#+END_SRC
pgpd_Hgm81Xuh.pgp
Description: PGP signature
Re: [O] Org mode and "shunt" exporters?, John Kitchin, 2013/12/06
- Re: [O] Org mode and "shunt" exporters?, Brett Viren, 2013/12/12
- Re: [O] Org mode and "shunt" exporters?, John Kitchin, 2013/12/12
- Re: [O] Org mode and "shunt" exporters?, Eric Schulte, 2013/12/12
- Re: [O] Org mode and "shunt" exporters?, Aaron Ecay, 2013/12/12
- Re: [O] Org mode and "shunt" exporters?, Matt Price, 2013/12/12
- Re: [O] Org mode and "shunt" exporters?, John Kitchin, 2013/12/12
- Re: [O] Org mode and "shunt" exporters?, Brett Viren, 2013/12/13