递归解析组织模式层次结构

cbs*_*1th 3 emacs recursion parsing elisp org-mode

我试图以这种方式解析组织模式文本:

* head
** sub-head
    - word :: description
** sub-head
    - word :: description
    - some notes
* head2
** sub-head2
    - some more notes
Run Code Online (Sandbox Code Playgroud)

我试图以这样的方式捕获数据(例如"word :: description"和"some notes"),使得每个数据保留其父标题是什么以及父母的父母是什么,等等.我设想数据在elisp中以这样的形式出现:

(
    ("head" 
        ("sub-head" ("word :: definition")) 
        ("sub-head" ("word :: description" "some notes"))
    )
    ("head2"
        ("sub-head2" ("some more notes"))
    )
)
Run Code Online (Sandbox Code Playgroud)

我猜有一个使用递归的优雅解决方案.如果有更好的方法,我愿意以不同的方式构建elisp中的数据.

Jua*_*cho 5

该功能org-element-parse-buffer应该有所帮助.它将整个org-mode缓冲区解析为lisp列表.您将获得比您需要的更多属性.

http://orgmode.org/worg/exporters/org-element-docstrings.html#sec-10