Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Converting/rendering XHTML in user macros

Robert Khanafiev October 30, 2020

Hi everyone.

I'm new to Atlassian API and Velocity language, but I have to create my macro for exporting comments into PDF file. 

I can successfully access the comments with smth like

#set ($comments = $content.getComments())
#foreach( $comment in $comments )
#set ($commentBody = $comment.getContentEntityObject().getBodyAsString())
$commentBody
#end

 but seems like comments are returned to me in XHTML-type. 

Attached screenshots show the example of original comment and its exported representation. How can I correctly render it?

OriginalComment.pngWrongComment.png

 

3 answers

0 votes
Robert Khanafiev November 3, 2020

Found something interesting.

If I use 

$comment.getEntity().getBodyContent().getBody()

in Confluence Server v7.4.5 everything works fine and comments are exported to PDF document properly.

preview url image

In Confluence Server v7.7.X and v7.8.X my macros doesn't work properly and comments are exported without any render.

preview url image

Of course all the settings for different versions are the same.

Is it a bug? 

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 3, 2020

That is very interesting. I would suggest looking at the API docs to see what is changed, but unfortunately, the docs are very sparse.

Filing a case is probably your best option. There may already be a bug filed, or you get the joy of filing one. ;-)

Gary Sargent November 18, 2020

Did you get anywhere on this. I'm seeing the same behaviour change when trying to upgrade to V7.8.X from V6.15.9

Robert Khanafiev November 18, 2020

Not yet. Left this task in the background.

0 votes
Robert Khanafiev November 2, 2020

Up. Still need an answer.

Can anyone at least tell me, how can I properly access $xhtmlContent?

0 votes
Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2020

Do you have rendered or unrendered checked for the output of the macro?

Robert Khanafiev October 30, 2020

You mean the "Macro body processing" key? If so, It doesn't depend on it.

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2020

Yes, and you output should vary.

And use the inspect function to see how the output is being structured.

Bill Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2020

And I see there is this method that might help -

getBodyAsStringWithoutMarkup()
Robert Khanafiev October 30, 2020

Thank you, I'l try it on monday. 

Robert Khanafiev October 31, 2020

Have tried 

getBodyAsStringWithoutMarkup()

Yes, It works good, but of course it removes all the links (see attachment), so it is not exactly what I want. Is there any way to render the comment saving links (link to the user profile in my example)?

CommentNoMarkup.png

Below you can see what I have already tried. Let's assume, that for all the examples below "$comment" is taken from here:

#set ($comments = $content.getComments())
#foreach( $comment in $comments )
#### comment is available here
#end

1) Using renderConfluenceMacro. The output it the same as in my first message.

#set( $helper= $action.getHelper() )
#set( $commentBody1 = $comment.getContentEntityObject().getBodyContent().getBody() )
#set( $commentBody2 = $comment.getContentEntityObject().getBodyAsString() )
#set( $commentBody3 = "$comment.getContentEntityObject().getBodyAsString()" )


$helper.renderConfluenceMacro( commentBody1 )
$helper.renderConfluenceMacro( commentBody2 )
$helper.renderConfluenceMacro( commentBody3 )

2) Using xhtmlContent. Doesn't work at all.

#set ($xhtmlContent = $action.getContentBean())
#set( $commentBody1 = $comment.getContentEntityObject().getBodyContent().getBody() )
#set( $commentBody2 = $comment.getContentEntityObject().getBodyAsString() )
#set( $commentBody3 = "$comment.getContentEntityObject().getBodyAsString()" )

$xhtmlContent.convertStorageToView($commentBody1, null)
$xhtmlContent.convertStorageToView($commentBody2, null)
$xhtmlContent.convertStorageToView($commentBody3, null)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events