Macro heading links in TOC are wrong

Hi! Our app has a static content macro which displays arbitrary content, including headings. These are returned as storage format in the body of the response for our macro. We recently received support which showed that the headings inside the macro do not work well with Atlassian’s TOC element.

Normally a heading in a TOC will link to the element id of the heading on the page, e.g. #Lorem. However, when concerning a heading inside our macro, the link in the TOC and the id do not match. The TOC will still link to #Lorem, but the id of the heading in the macro will be PageName-Lorem, where ‘PageName’ is a version of the name of the page. This means the link does not work.

This id of the heading element in the macro is set by Confluence (in fact any id that we set in our response is removed), so we’re not sure at this point how to get the TOC and macro heading links to work correctly together.

It is of note that Atlassian’s Excerpt macro does not show this problem. Headings inside this macro get a normal id and the TOC link works as expected. Investigating the storage format and ADF sources of our macro and the Excerpt macro, we could not find any differences in the definition of the macro or its content that would explain the behavior.

Is it possible for headings in the body of our macro to have correct ids that correspond to those in the TOC? How can we do it? Or is this a bug or missing feature in Confluence? Thanks!