Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse org-mode by org-element elegantly

org-element is a new module for org-mode, I think it is good for parse org file, and don't want to parse it by old way with match-string. but after play with it for some hours, I have to admit I don't have enough experience with org-mode, so could masters give me some clues, thanks very much!

My requirement is simple, I want to get all headlines and content.

* headline

:PROPERTIES

** subheadline

content1

** subheadline

content2
like image 534
netawater Avatar asked Jun 20 '13 08:06

netawater


1 Answers

based on @YoungFrog's prompt:

  • get all headlines:

    (let ((parsetree (org-element-parse-buffer 'headline))) 
      (org-element-map parsetree 'headline 
                       (lambda (hl) (org-element-property :title hl)))) 
    
  • get all contents:

    (let ((parsetree (org-element-parse-buffer 'paragraph)))
      (org-element-map parsetree 'paragraph 
                       (lambda (hl) (org-element-interpret-data hl))))
    
like image 55
netawater Avatar answered Oct 18 '22 03:10

netawater