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

标签 parsing emacs recursion elisp org-mode

我正在尝试以这种方式解析 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/

相关文章:

emacs - 组织模式导出选项,例如 ODT、beamer

C - 数组中最小间隙的递归函数

java - 堆栈溢出错误: How would I write this method Iteratively?

c - 为什么这没有生成所有可能的子集?

c++ - 如何简单解析html引用

php - 使用 PHP 通过 SimpleXML 解析 XML 并遇到命名空间问题

c# - 使用 C# 解析 EDI 平面文件?

emacs - [control shift up] 不起作用

emacs - 在带有tramp的远程机器上运行命令?

C++头文件解析