* org-element: headline's :title is sometimes string, sometimes list
@ 2023-08-23 1:25 Hraban Luyat
2023-08-23 9:49 ` Ihor Radchenko
0 siblings, 1 reply; 3+ messages in thread
From: Hraban Luyat @ 2023-08-23 1:25 UTC (permalink / raw)
To: emacs-orgmode
Hi all.
I'll let the code speak:
(with-temp-buffer
(org-mode)
(insert "* Hello")
(cl-flet ((say-type (prefix hl)
(message "Headline title from %s is of type: %s"
prefix
(type-of (org-element-property :title hl)))))
(org-element-map (org-element-parse-buffer) 'headline
(lambda (hl) (say-type "map" hl)))
(goto-char (point-min))
(say-type "context" (org-element-context))
(say-type "at-point" (org-element-at-point))))
I expect: "string" everywhere.
I get:
Headline title from map is of type: cons
Headline title from context is of type: string
Headline title from at-point is of type: string
Question 1: Do you know what that `cons' structure is? Where is it
documented, how would I go about figuring this out myself? The
org-element API documentation is daunting.
Question 2: how do I reliably get the title as a string? Properties are
fine, I don't mind, but that weird list structure is awkward to handle.
Thank you
Hraban
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: org-element: headline's :title is sometimes string, sometimes list
2023-08-23 1:25 org-element: headline's :title is sometimes string, sometimes list Hraban Luyat
@ 2023-08-23 9:49 ` Ihor Radchenko
2023-08-23 15:01 ` Hraban Luyat
0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2023-08-23 9:49 UTC (permalink / raw)
To: Hraban Luyat; +Cc: emacs-orgmode
Hraban Luyat <hraban@0brg.net> writes:
> I expect: "string" everywhere.
>
> I get:
>
> Headline title from map is of type: cons
> Headline title from context is of type: string
> Headline title from at-point is of type: string
>
> Question 1: Do you know what that `cons' structure is? Where is it
> documented, how would I go about figuring this out myself? The
> org-element API documentation is daunting.
This is "anonymous element". `org-element-parse-buffer', by default,
parses down to object level:
* Heading *bold* text
contains bold markup, which is reflected in the parsed AST. The title
itself is called secondary value, which may contain Org markup.
You are not getting it using `org-element-at-point' API because it does
not parse objects and simply returns a heading parsed down to element
level - :title is not parsed in details.
> Question 2: how do I reliably get the title as a string? Properties are
> fine, I don't mind, but that weird list structure is awkward to handle.
Use `org-element-interpret-data' to convert Org AST back to plain text.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: org-element: headline's :title is sometimes string, sometimes list
2023-08-23 9:49 ` Ihor Radchenko
@ 2023-08-23 15:01 ` Hraban Luyat
0 siblings, 0 replies; 3+ messages in thread
From: Hraban Luyat @ 2023-08-23 15:01 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
Thank you Ihor.
On 8/23/23 5:49 AM, Ihor Radchenko wrote:
> Hraban Luyat <hraban@0brg.net> writes:
>
>> I expect: "string" everywhere.
>>
>> I get:
>>
>> Headline title from map is of type: cons
>> Headline title from context is of type: string
>> Headline title from at-point is of type: string
>>
>> Question 1: Do you know what that `cons' structure is? Where is it
>> documented, how would I go about figuring this out myself? The
>> org-element API documentation is daunting.
> This is "anonymous element". `org-element-parse-buffer', by default,
> parses down to object level:
>
> * Heading *bold* text
>
> contains bold markup, which is reflected in the parsed AST. The title
> itself is called secondary value, which may contain Org markup.
>
> You are not getting it using `org-element-at-point' API because it does
> not parse objects and simply returns a heading parsed down to element
> level - :title is not parsed in details.
>
>> Question 2: how do I reliably get the title as a string? Properties are
>> fine, I don't mind, but that weird list structure is awkward to handle.
> Use `org-element-interpret-data' to convert Org AST back to plain text.
>
> --
> Ihor Radchenko // yantar92,
> Org mode contributor,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-23 16:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-23 1:25 org-element: headline's :title is sometimes string, sometimes list Hraban Luyat
2023-08-23 9:49 ` Ihor Radchenko
2023-08-23 15:01 ` Hraban Luyat
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).