1

我的目标是使用提供的 REST API 在 confluence wiki 中创建一个包含表格的页面,该 wiki 用户可以在页面创建后使用 WYSIWYG 编辑器轻松编辑该表格。

我已经将文本拆开并将不同的类别放入一个数组数组中,然后从中生成一个 html 表(一个字符串),效果很好。

但是将此原始 html 表(在 $htmlTable 中)作为内容发布到 REST API

$data = array("type" => "page", "title" => someTitle, 
       "space" => array("key" => "$uploadSpace"), 
       "body" => array("storage" => array("value" => "$htmlTable", "representation" => "storage")));

返回 400 statusCode 错误。显然是因为输入没有正确转义,htmlspecialchars用于将字符串编码为 html,但是我将如何创建一个结构化输入,否则将其转换为 html 表?

我试图通过一个汇合宏来传递我的 html 表,该宏将 html 输入呈现到一个表中以供查看:

$data = array("type" => "page", "title" => someTitle,
       "space" => array("key" => "$uploadSpace"), 
       "body" => array("storage" => array("value" => "<ac:structured-macro ac:name=\"html\"><ac:plain-text-body><![CDATA[$htmlTable]]></ac:plain-text-body></ac:structured-macro>", "representation" => "storage")));

这会在页面上呈现我的 html 表格,但是这无法满足 WYSIWYG 要求中易于编辑的要求,因为 wiki 的用户之后会看到包含在宏中的 html 代码。

非常感谢您提前。

4

2 回答 2

0

你需要修改你的表格以使用Confluence Wiki Markup来标记表格。例如,html表:

$data = "<table>
         <tr><th>First Name</th><th>Last Name</th><th>GPA</th></tr>
         <tr><td>Bob</td><td>Jones</td><td>3.52</td></tr>
         <tr><td>Fred</td><td>Smith</td><td>2.89</td></tr>
         </table>";

应该写成:

$data = "||First Name||Last Name||GPA||
         |Bob|Jones|3.52|
         |Fred|Smith|2.89|";

然后,当您通过 REST 进行更新/插入时,将“表示”从“存储”更改为“维基”。(并删除 html 宏包装器)

$data = array("type" => "page", "title" => someTitle,
             "space" => array("key" => "$uploadSpace"), 
             "body" => array("**wiki**" => array("value" => "$htmlTable", "representation" => "**wiki**")));

这将为您提供一个原生的、所见即所得的 Confluence 表。

'storage' 表示表示 body 测试已经转换为 Confluence 内部用于存储内容的格式。您想使用 'wiki' 插入,并让 Confluence 为您处理任何转换。

于 2015-11-12T17:54:43.947 回答
0

经过长时间的挣扎,找到了解决办法。

在您的 HTML 内容上添加宏代码。

$bodyFormatted = '<ac:structured-macro ac:name="html"><ac:plain-text-body><![CDATA['.$bodyFormatted.']]></ac:plain-text-body></ac:structured-macro>';

$bodyFormatted 变量保存 HTML 内容。

$data['type'] = 'page';
$data['title'] = $articleData["title"].time();
$data['space']['key'] = $articleData["container"];
$data['body']['storage']['value'] = $bodyFormatted;
$data['body']['storage']['representation'] = 'storage';

编码为 json 并通过 REST。在那个重要的过程之前,我失败了。

“启用 HTML 宏”参考:https ://confluence.atlassian.com/conf55/confluence-user-s-guide/creating-content/using-the-editor/working-with-macros/html-macro

尽管有警告,但启用提到的模块 (html (html-xhtml))

处理您的 API 调用,现在检查内容。希望你完成了。工作完成后,禁用模块,以防止跨脚本攻击。

于 2016-12-29T15:09:06.497 回答