org-ml
org-ml copied to clipboard
A "Hello World"?
I find this project more promising and accessible than org-element.
Thanks for the efforts!
But is there somewhere a "hello world"?
Yeah I see a good amt of documentation in docs/api-refeence.md
I am looking for a simple end-to-end reference with setting up of hooks, export etc
ie some toy example that uses org-ml API and say transforms some org file into another?
If possible something that transforms:
*** Lorem Ipsum :LAW:
into
#+begin_law
Lorem Ipsum
#+end_law
would be wonderful.
But if even a simpler eg is given/pointed out I can hack from there on.
I've been meaning to build a 'cookbook' which would probably fill the need you are describing. I've been busy with other things but am hoping to return to that soon.
In the meantime, the code that does what you want is this:
(org-ml-update-this-headline*
(org-ml-build-special-block
(downcase (car (org-ml-get-property :tags it)))
(org-ml-build-paragraph (org-ml-get-property :raw-value it))))
This is actually an example I hadn't considered yet. I only envisioned org-ml-update-this-headline and the like to be used to modify headlines, but apparently it can transform headlines into something other than a headline, so thank you for the question ;)
Thanks much for the response. But I still dont know how to use it😄 Has to be put on some hook I guess??
I see that if I put point on a suitable headline it transforms it.
But on a headline without the suitable tag I get an error (wrong-type-argument char-or-string-p nil)
More fundamentally: I dont want to change the file literally; I want to change it "as if" during export (currently latex)
I was just perusing the org hooks and there are apparently hundreds!!!!! [Ok ½-hundred is I think not an exaggeration]
Not sure I understand your use case. Are you trying to recreate what would happen if you exported using the latex exporter?
If you don't want to actually change the file you can just emit a string like so:
(let* ((hl (org-ml-parse-this-headline))
(sb (org-ml-build-special-block
(downcase (car (org-ml-get-property :tags hl)))
(org-ml-build-paragraph (org-ml-get-property :raw-value hl)))))
(org-ml-to-string sb))
This (and the above example) are only going to work on headlines with at least one tag; if you want to make it more robust there needs to be logic to check the validity of the tag itself.
Not sure I understand your use case. Are you trying to recreate what would happen if you exported using the latex exporter?
I want to export to latex The file that org sees as input for latex-export should be identical to my file: Except that
- tag
:Lshould become#+begin_law - tag
:Ashould become#+begin_action - etc
I don't use the latex exporter very much so I can't say how exactly this would fit into what you want. It seems the exporter should have some built in functionality to map tags to different block names.
The only (easy) way I can see org-ml being useful here is to transform your file into a temporary buffer that you then run through the latex exporter. You would basically copy the file and then run something like org-ml-update-subtrees or org-ml-update-headlines which will apply a transformer function to all subtrees/headlines (whichever is more convenient). There's probably some clever way you could even advise the current export function to transparently do this if that's the desired outcome.