How to convert page source frim preview mode to storage format

CelesteCS September 21, 2017
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!

1 answer

0 votes
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 22, 2017

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

CelesteCS September 22, 2017

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!

Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 25, 2017

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

CelesteCS September 26, 2017

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!

Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 27, 2017

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

CelesteCS September 27, 2017

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!

Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 28, 2017

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events