How to convert page source frim preview mode to storage format

When the Confluence macro is rendered in Previw mode and reads parent page xhtml-code, it gets a code, which is not the same, which is on a saved page. All the macro instances are enclosed in wysiwyg-macros. How I can transform such code to normal page storage format?

1 answer

0 votes

Hi Alexey,

Can you let us know perhaps what you are trying to do? The Source Editor plugin, for example, will display the actual storage format and allow you to edit it.

Kind Regards,

I'm developing a macro, which uses it's parent page contents.
When this macro is rendered on a saved page, it reads its content normally. But when it is rendered in a preview mode and reads its parent page in the same manner, the page content is different: macros are replaced with Wysiwyg-macro and macro parameters are specified as parameters of this Wysiwyg-macro. Replacing this macro manually does not seem tobe a good solution, so I'm asking how to get normal page content, without Wysiwyg-macro?


When you install the Source Editor plugin above, once you've saved the page you can go in and edit again, and there will be a <> icon in the top right of the editor. You can click this and it will show all content as the source rather than WYSIWYG. Have you been able to test this, and is it what you require? 

Note, it won't show the source content when just viewing the page, but it sounds like you only need it to display that content when editing. Is this correct?

Kind Regards,

Hi Shannon,

Thank you for your answer.

I don't use Source Editor, I just read source page from my macro. Here is the code:

PageContext renderContext = conversionContext.getPageContext();
PageContext pageContext = ((PageContext) renderContext);
ContentEntityObject contentObject = pageContext.getEntity();
String page = contentObject.getBodyAsString();

 So, the page variable contains page source in storage format, but all the macros on the page are enclosed in WYSIWYG macro body:

<td class="confluenceTd">&nbsp;</td>
<td class="confluenceTd"><table class="wysiwyg-macro"
style="background-image: url('http://LEXUS:1990/confluence/plugins/servlet/confluence/placeholder/macro-heading?definition=e251bWVyaWNhbC1leHByZXNzaW9uOm91dGVyLXZhbHVlcy1zb3VyY2U9UGFnZSBjb250ZW50fGF0bGFzc2lhbi1tYWNyby1vdXRwdXQtdHlwZT1JTkxJTkV9&amp;locale=en_GB&amp;version=2'); background-repeat: no-repeat;"
data-macro-schema-version="1" data-macro-body-type="RICH_TEXT">
<td class="wysiwyg-macro-body"><p>2+2</p></td>

What I need is to get page source without this WYSIWYG macro.


Hi Alexey,

From my understanding, you wish to display the Confluence page as page source rather than WYSIWYG. Correct?

The Source Editor add-on that I recommended you install, will do just that, allow you to view Confluence pages in edit mode as the source, and not WYSIWYG.

If you've already tested that add-on, can you let me know why it might not work for your use case?

Kind Regards,

Hi Shannon,

We are developing a commercial plug-in, so installing any other plug-ins is not an option.

What I need is to get page source in storage format from my macro code, when it is placed on a page in preview mode.



Thank you for letting me know why you weren't able to use the other add-on.

I'm still a little unclear on what you need to do exactly. Are you saying this is the functionality you want your macro to have? You want it to display page source in storage format anytime a user has it on a page and previews the page?

This sounds like something that our development community would need to help you with, so I will add the Confluence Development tag on your question and someone will be able to assist.

Kind Regards,

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Feb 06, 2019 in Confluence

Try out the new editing experience

Hi team, I’m Avinoam, a product manager on Confluence Cloud, and today I’m really excited to let the Community know that all customers can now try out the new editing experience and see some of the ...

889 views 45 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you