What I'm trying to achieve is to upload a Confluence page content that contains code examples, and I'd like these code examples to use the {code} macro plugin that provides syntax highlighting when viewing the page.
I've found that the code macro stores 2 formats on Confluence, respectively for body.storage
and body.view
:
<ac:structured-macro ac:name="code" ac:schema-version="1" ac:macro- id="37fecf11-d435-452a-90c7-da19f3821b4c">
<ac:parameter ac:name="language">bash</ac:parameter>
<ac:parameter ac:name="linenumbers">true</ac:parameter>
<ac:plain-text-body><![CDATA[ // code goes here ]]></ac:plain-text-body>
</ac:structured-macro>
and
<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre">
// code goes here
</pre>
</div>
</div>
I've tried uploading both to Confluence using the API, but each time, the code block is rendered as a simple <pre/>
element, and syntax highlighting is not rendered.
Any help appreciated.
Note: This is how I update the content through the API: https://docs.atlassian.com/atlassian-confluence/REST/latest-server/#content-update Typically:
HTML = '<div class="code panel pdl" style="border-width: 1px;">
<div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre">
$ DIST=`cat /etc/*release`
$ echo $DIST
</pre>
</div>
</div>'
data = json.dumps(
{
'id': '%d' % PAGEID,
'type': 'page',
'title': TITLE,
'space': {
'key': SPACE
},
'version': {
'number': VERSION +1
},
'body': {
'storage': {
'representation': 'storage',
'value': HTML
}
}
}
)
rPut = requests.put(
url,
data = data,
auth = (USER, PWD),
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
)
Any help appreciated,