Hi,

Nicolas Goaziou <n.goaz...@gmail.com> 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:

Attachment: pgpD3LPnqETG3.pgp
Description: PGP signature

Reply via email to