How to convert page source frim preview mode to storage format
Asked by CelesteCS:

Hi!  
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?  
Thanks!


Answers:
author: Shannon S
body: Hi Alexey,

Can you let us know perhaps what you are trying to do? [The Source Editor plugin](https://marketplace.atlassian.com/plugins/com.atlassian.confluence.plugins.editor.confluence-source-editor/server/overview), for example, will display the actual storage format and allow you to edit it.

Kind Regards,  
Shannon

comments: author: CelesteCS
body: Hi,  
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?  
Thanks!


author: Shannon S
body: Alexey,

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,  
Shannon


author: CelesteCS
body: 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);
pageContext.setOutputType(RenderContextOutputType.DISPLAY);
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:

```
<tr>
 <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-name="my-macro"
 data-macro-id="47a26b47-7e92-408b-b149-e30831f20416"
 data-macro-parameters="atlassian-macro-output-type=INLINE|parameter=value"
 data-macro-schema-version="1" data-macro-body-type="RICH_TEXT">
 <tbody>
 <tr>
 <td class="wysiwyg-macro-body"><p>2+2</p></td>
 </tr>
 </tbody>
 </table></td>
</tr>
```

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

Thanks!


author: Shannon S
body: Hi Alexey,

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

The [Source Editor add-on](https://marketplace.atlassian.com/plugins/com.atlassian.confluence.plugins.editor.confluence-source-editor/server/overview?_ga=2.48116078.811213194.1506325722-1114274742.1505467770) 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,  
Shannon


author: CelesteCS
body: 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.

Thanks!


author: Shannon S
body: Alexey,

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,  
Shannon


Tags: confluence-development