0

我想要实现的是上传包含代码示例的 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'
    }
)

任何帮助表示赞赏,

4

0 回答 0