I am new in Jira and I am creating a post-function that will create a Confluence Page.
I want to write the storage format using an XML builder and I have the following code.
// write storage format using an XML builder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.'ac:structured-macro'('ac:name': "section") {
'ac:parameter'('ac:name': "border","true")
'ac:parameter'('ac:name': "width","100")
xml.p("This is a Section")
xml.'ac:structured-macro'('ac:name': "column") {
'ac:parameter'('ac:name': "border","true")
xml.p("This is a Column")
}
}
// print the storage that will be the content of the page
log.debug(writer.toString())
My goal is to create a section with a column using a structured macro but it is not working as expected as it only creates the Section part.
I think you are missing the body containers.
Try it like this:
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.'ac:structured-macro'('ac:name': "section") {
'ac:parameter'('ac:name': "border","true")
'ac:rich-text-body'{
xml.p("This is a Section")
xml.'ac:structured-macro'('ac:name': "column") {
'ac:parameter'('ac:name': "width","100")
'ac:rich-text-body'{
xml.p("This is a Column")
}
}
}
}
log.info writer.toString()
If you don't already, I'd recommend getting https://marketplace.atlassian.com/plugins/com.atlassian.confluence.plugins.editor.confluence-source-editor?_ga=2.251717833.1701738042.1579542961-924046337.1569864105
This way to can output your xml, and paste it directly in a page to test it.
Or edit a page and see the resulting xml immediately (and edit it if necessary)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.