我正在尝试以这种方式解析 org-mode 文本:
* head
** sub-head
- word :: description
** sub-head
- word :: description
- some notes
* head2
** sub-head2
- some more notes
我试图以这样一种方式捕获数据(例如“word::description”和“some notes”),即每条数据都保留其父标题是什么以及父标题是什么,等等。我在 elisp 中设想以这种形式出现的数据:
(
("head"
("sub-head" ("word :: definition"))
("sub-head" ("word :: description" "some notes"))
)
("head2"
("sub-head2" ("some more notes"))
)
)
我猜有一个使用递归的优雅解决方案。如果有更好的方法,我愿意以不同的方式在 elisp 中构建数据。
最佳答案
函数 org-element-parse-buffer
应该有帮助。它将整个 org-mode 缓冲区解析为一个 lisp 列表。您将获得比您需要的更多的属性。
http://orgmode.org/worg/exporters/org-element-docstrings.html#sec-10
关于parsing - 递归解析组织模式层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18522271/