[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 13:26:57 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Hi,
Nicolas Goaziou <address@hidden> writes:
> You can walk the tree, e.g. with `org-element-map', and remove
> all :parent references if you don't need them.
I figured out how to follow this advice. I can even make valid JSON
From the filtered parse tree by handing it to Edward O'Conner's
json.el (link in example below).
However this method only works for a very simple org document. I'm
successfully filtering out the :parent properties of (most of) the
elements but as soon as my document produces a plain text element like:
#("Text" 0 4 (:parent #1))
then two problems occcur:
First, I'm simply failing to see how to set this :parent property to nil
like I do with the others.
Second, json.el throws a "Bad JSON Object" error. I tried assuming that
the problem was it doesn't know what to do with this substring form.
Naively, I tried to follow some other recent advice in another thread
about using substring-no-properties to strip out the meta data from the
plain text elements. But this apparently is a net no-op as I suspect
that the org-element-set-contents then puts them right back.
I feel like I'm pretty close. Any more advice?
Thanks,
-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 org-element-all-elements
(lambda (x)
(if (org-element-property :parent x)
(org-element-put-property x :parent nil))
;; (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.txt"))
#+END_SRC
#+RESULTS:
pgphqUaoNLDe3.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