Creating Section and Columns using Jira MarkupBuilder with Structured Macro

Shereen January 31, 2020

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.

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2020

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)

Shereen February 3, 2020

Thank you so much! It is now working as expected. 

Suggest an answer

Log in or Sign up to answer