我正在尝试通过 elisp 代码从 orgmode 中提取文本。我有
item
作为缓冲区的节点,我想提取标题下方第一段的文本。
文档看起来像这样:
* Section
** Hello
** World
What a beautiful day
*** Some other stuff
item
对应于标题为World
的节点,我想得到“多么美好的一天”。此外,如果这使它更安全(因为只有原始文本很重要),我可以将“多么美好的一天”封装在源代码块中。
我查看了https://orgmode.org/worg/dev/org-element-api.html并尝试使用
(car (org-element-contents 'item))
提取第一个孩子,但看起来我没有取得任何进展。
我不确定你到底有什么
item
,但你可以转到 :contents-begin
节点的 headline
并返回在那里找到的段落(如果有的话)。
(defun my-first-para (item)
"Message the first paragraph following headline ITEM, if present.
When called interactively, ITEM is the element at point."
(interactive (list (org-element-at-point-no-context)))
(when-let ((beg (org-element-property :contents-begin item)))
(goto-char beg)
(let ((el (org-element-at-point-no-context)))
(when (eq 'paragraph (org-element-type el))
(message
(buffer-substring-no-properties
(org-element-property :contents-begin el)
(org-element-property :contents-end el)))))))