主要目的是使用 API 解析字符串中的 org-mode 数据。获取对应的节点内容等。
测试方法:使用 ob-babel 功能,支持共享数据和环境变量,可以传值等特点。
初始化数据源
1
2
3
4
| (setq org-string "* Hello world\n:PROPERTIES:\n:OWNER: Dav\n:ID: 123\n:END:\n\nThis is the body of first-level headline.\n\n** Subheadline\n\nTest text.")
(with-current-buffer (get-buffer-create "*org-string*")
(insert org-string)
)
|
APi 测试用例
获取所有属性名
1
2
3
4
5
6
| (with-current-buffer "*org-string*"
(org-mode)
(let ((x (org-buffer-property-keys)))
(with-output-to-temp-buffer "*xah temp out*"
(print x)))
)
|
获取当前 headline
1
2
3
4
5
6
7
8
|
(with-current-buffer "*org-string*"
(org-mode)
;; 提取当前标题的组成部分。
(let ((x (org-heading-components)))
(with-output-to-temp-buffer "*xah temp out*"
(print x)))
)
|
获取所有 headline
1
2
3
4
5
6
7
8
9
| (with-current-buffer "*org-string*"
(org-mode)
(let (($headings nil))
(org-map-entries
(lambda ()
(push (org-heading-components) $headings)))
(with-output-to-temp-buffer "*xah temp out*"
(print $headings)))
)
|
| 2 | 2 | nil | nil | Subheadline | nil |
|---|
| 1 | 1 | nil | nil | Hello world | nil |
org-element.el 库测试用例
org-data 的数据结构
(org-data nil <e1> <e2> <e3> … )