通过API上传包含{code}宏的Confluence页面内容

时间:2017-03-03 16:01:59

标签: confluence confluence-rest-api

我想要实现的是上传包含代码示例的Confluence页面内容,并且我希望这些代码示例使用{code}宏插件,该插件在查看页面时提供语法突出显示。

我发现代码宏在Confluence上存储了2种格式,分别用于body.storagebody.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>

<div class="code panel pdl" style="border-width: 1px;">
   <div class="codeContent panelContent pdl">
     <pre class="syntaxhighlighter-pre">
     // code goes here
     </pre>
   </div>
</div>

我尝试使用API​​将两者上传到Confluence,但每次都会将代码块渲染为简单的<pre/>元素,并且不会渲染语法高亮。

任何帮助表示感谢。

注意:这是我通过API更新内容的方式:https://docs.atlassian.com/atlassian-confluence/REST/latest-server/#content-update 典型地:

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'
    }
)

任何帮助表示赞赏,

0 个答案:

没有答案
相关问题