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?
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.
In Confluence Server v7.7.X and v7.8.X my macros doesn't work properly and comments are exported without any render.
Of course all the settings for different versions are the same.
Is it a bug?
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. ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Up. Still need an answer.
Can anyone at least tell me, how can I properly access $xhtmlContent?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have rendered or unrendered checked for the output of the macro?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You mean the "Macro body processing" key? If so, It doesn't depend on it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, and you output should vary.
And use the inspect function to see how the output is being structured.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And I see there is this method that might help -
getBodyAsStringWithoutMarkup()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)?
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.