Mismatched HTML from AP.getMacroBody()

Hi devs!

I’ve been trying to use AP.getMacroBody() to retrieve what’s written inside a macro, but the retrieved HTML are different than what they look like during editing, e.g. <ul> retrieved with getMacroBody() is missing the ak-ul class which they have during edit and when rendered normally.

That makes me wonder if this is a bug or an expected behaviour? Any clue on this?

Thanks in advance.


Hi @yongchong.long,

I personally haven’t used AP.getMacroBody() before, so I could be wrong about this, but I assume what you’re getting back from it is actually storage format. This XHTML-based format is used by Confluence to store the content of the page.

If you’re looking to get actual HTML for displaying the macro body in the browser, you’ll likely want to send the storage format to the Convert Content Body REST Endpoint and tell it to give you back the content in either the view, export_view, or styled_view format.

Hope this helps!



Hi @SvenSchatter,

Thanks for the reply, what I observed is that for non-standard HTML elements, they are stored as storage format, e.g. <ac:task-list>, but for the rest like a simple unordered list, it’s stored as standard HTML (e.g. <ul>) which I guess is compatible with the XHTML-based storage format.

The problem I have is when a standard element, for example, an unordered list (<ul>) is located outside of macro body, they actually have extra classes or attributes applied to them when viewing them on the page:

Where as when an identical element resides inside a macro body and retrieved as macro body using AP.getMacroBody(), it is simply an <ul> without any classes or attributes, even when I used the REST endpoint to convert them to view, export_view, or styled_view, they remain without any of the classes or attributes that they would have if they are outside of a macro body (notice the missing ak-ul class in <ul>, and the data attributes as well):

Thus the question, is there anyway to make them look the same (not just <ul> but other elements as well), or at least have the same classes and attributes?

If you just want your HTML to display the same as in Confluence you’ll want to include the reduced-ui-kit and css-reset from Atlaskit in your document (or you could use AUI).

If the conversion REST endpoints don’t add any classes to your HTML I’m afraid there won’t be any other way to get them.


1 Like