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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Converting/rendering XHTML in user macros Edited

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
Bill Bailey Community Leader Oct 30, 2020

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

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

Yes, and you output should vary.

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

Bill Bailey Community Leader Oct 30, 2020

And I see there is this method that might help -

getBodyAsStringWithoutMarkup()

Thank you, I'l try it on monday. 

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)

Up. Still need an answer.

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

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 Community Leader Nov 03, 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. ;-)

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

Not yet. Left this task in the background.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

107 views 0 3
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you