How are heading IDs generated?

Hello,

I am trying to find the logic on how IDs are generated from IDs.

For example having the following heading is converted to #HExampleHeading

= Example Heading =

My goal is to go from URL back to headings in the raw source of the page rather than the rendered page.

I have been able to reproduce the logic for most simple situations but there are still edge cases for which my logic fails, therefore I wanted to look at reproducing directly the logic used for rendering the headings.

Thanks!

Hi!

For anything related to how we render syntax in XWiki, you can look into the project xwiki-rendering.

For your specific question, here are a couple links to places from where you should be able to find what you’re looking for :wink:

Hope this helps!

Lucas C.

1 Like

Great, thank you! I did some digging myself in the rendering Github project but couldn’t find the exact place where the logic was done!

I’ll get started working on that and will report back if we have any further issues with it.

Thanks a lot for you help!

{{groovy}}
import org.xwiki.rendering.util.IdGenerator;
def id = new IdGenerator().generateUniqueId("H", "Example Heading");
{{/groovy}}
2 Likes

I looked a bit more into it:

Allowed characters are 1->9, a->z , A->Z , “:” “_” “.” and “-”.

1 Like