Retrieve heading text in rendering API

Hello all,

I want to change the automatically generated IDs for headings (H…) using the rendering API.
How can I retrieve the heading content, aka the text which was used to generate the ID from, from the HeaderBlock? Do I have to go through all children blocks and check if it is a WordBlock or SpaceBlock and concatenate them together or is there any simple way?

For more context: I have given some HTML like <h1>Foo Bar</h1> and after converting it to XDOM default XWiki behaviour is to set the ID of the corresponding HeaderBlock to “HFooBar”. I want to change the ID to “Foo_Bar” or add an IdBlock with such ID before the HeaderBlock. In the transformation, I need the content “Foo Bar” of my HeaderBlock. From here on I am a little bit lost. Do I need to write some custom Listener Class now?

I have found there is a Syntax.PLAIN_1_0 which I can use with a BlockRenderer to get the plain text of my HeaderBlock. Not sure if it is the best or only way but it seems like it works for now.