On 9/15/20 2:37 PM, to...@tuxteam.de wrote:
On Tue, Sep 15, 2020 at 01:15:56PM +0200, Przemysław Kamiński wrote:
There's the org-json (or ox-json) package but for some reason I
wasn't able to run it successfully. I guess export to S-exps would
be best here. But yes I'll check that out.
If that's your route, perhaps the "Org element API"  might be
helpful. Especially `org-element-parse-buffer' gives you a Lisp
data structure which is supposed to be a parse of your Org buffer.
From there to S-expression can be trivial (e.g. `print' or `pp'),
depending on what you want to do.
Walking the structure should be nice in Lisp, too.
The topic of (non-Emacs) parsing of Org comes up regularly, and
there is a good (but AFAIK not-quite-complete) Org syntax spec
in Worg , but there are a couple of difficulties to be mastered
before such a thing can become really enjoyable and useful.
The loose specification of Org's format (arguably its second
or third strongest asset, the first two being its incredible
community and Emacs itself) is something which makes this
problem "interesting". People have invented lots of usages
which might be broken should Org change to a strict formal
spec. You don't want to break those people.
But yes, perhaps some day someone nails it. Perhaps it's you :)
So I looked at (pp (org-element-parse-buffer)) however it does print out
recursive stuff which other schemes have trouble parsing.
My code looks more or less like this:
(defun org-parse (f)
(let* ((parsed (org-element-parse-buffer))
(all (append org-element-all-elements org-element-all-objects))
(mapped (org-element-map parsed all
strip-parent is basically (plist-put props :parent nil) for elements
properties. However it turns out there are more recursive objects, like
#("Headline 1" 0 10
So I'm wondering do I have to do it by hand for all cases or is there
some way to output only a simple AST without those nested objects?